grails不会保存但没有错误
您好,我有一个非常简单的域,如下所示
// page 52 Bankruptcy Questions
class FamilyLawFinancial{
Date dateOfTheOrder ;
boolean isPartyToFamilyLawProperty = false;
boolean isCurrentlyInvolvedInFamilyLawProperty = false;
boolean isBecomeInvolvedInProceedings = false;
static belongsTo=[person:Person];
static constraints = {
dateOfTheOrder(nullable:true);
isPartyToFamilyLawProperty(nullable:false);
isCurrentlyInvolvedInFamilyLawProperty(nullable:false);
isBecomeInvolvedInProceedings(nullable:false);
}
String toString(){
"${id}"
}
}
,这是保存数据的控制器:
def save = {
def person = Person.get(session.curperson.id);
def obj = FamilyLawFinancial.findByPerson(person);
if(obj == null){
obj = new FamilyLawFinancial();
obj.person = person ;
}
params.dateOfTheOrder = myutil.formatDate(params.dateOfTheOrder);
obj.properties = params;
println(obj.hasErrors());
println(obj.dateOfTheOrder);
if(obj.hasErrors() && !obj.save(flush:true)){
println("errors: ${obj.errors}");
flash.message = "error found";
println("save familyLawFinancial errors: ${errors}");
}else{
flash.message = "saved ";
}
redirect(controller:'frontPage', action:'index'); return ;
}
obj.hasErrors() 产生 false (这意味着没有错误),但它不会保存到数据库中。知道如何调试这个吗?
ps: myutil.formatDate() -->用于将日期字符串(例如 19/11/2010)转换为 Date()
Hi I have a domain that so simple like the following
// page 52 Bankruptcy Questions
class FamilyLawFinancial{
Date dateOfTheOrder ;
boolean isPartyToFamilyLawProperty = false;
boolean isCurrentlyInvolvedInFamilyLawProperty = false;
boolean isBecomeInvolvedInProceedings = false;
static belongsTo=[person:Person];
static constraints = {
dateOfTheOrder(nullable:true);
isPartyToFamilyLawProperty(nullable:false);
isCurrentlyInvolvedInFamilyLawProperty(nullable:false);
isBecomeInvolvedInProceedings(nullable:false);
}
String toString(){
"${id}"
}
}
and here is the controller that save the data:
def save = {
def person = Person.get(session.curperson.id);
def obj = FamilyLawFinancial.findByPerson(person);
if(obj == null){
obj = new FamilyLawFinancial();
obj.person = person ;
}
params.dateOfTheOrder = myutil.formatDate(params.dateOfTheOrder);
obj.properties = params;
println(obj.hasErrors());
println(obj.dateOfTheOrder);
if(obj.hasErrors() && !obj.save(flush:true)){
println("errors: ${obj.errors}");
flash.message = "error found";
println("save familyLawFinancial errors: ${errors}");
}else{
flash.message = "saved ";
}
redirect(controller:'frontPage', action:'index'); return ;
}
The obj.hasErrors() produce false (it means no error) but it wont save into the database. Any idea how to debug this ?
ps: myutil.formatDate() --> for converting the Date String such as 19/11/2010 to Date()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果
&&
之前的条件计算结果为false
,则不会计算&&
之后的条件。作为
false && true
的计算结果为false
,从语言的角度来看,计算第二个条件的效率很低。毕竟,在这种情况下, obj.save(..) 永远不会被调用。
The condition after
&&
will not be evaluated if the condition before evaluates tofalse
.As
false && true
evaluates tofalse
, evaluating the second condition would be inefficient from the language's point of view.After all, in this case,
obj.save(..)
never gets called.