nig*_*2k1 3 java grails java-ee grails-domain-class
嗨,我有一个像下面这么简单的域名
// 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}"
}
}
Run Code Online (Sandbox Code Playgroud)
这是保存数据的控制器:
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 ;
}
Run Code Online (Sandbox Code Playgroud)
该obj.hasErrors()产生假(这意味着没有错误),但它不会保存到数据库中.知道如何调试这个吗?
PS:myutil.formatDate() - >为日期字符串等转换为19/11/2010到日期()
if(obj.hasErrors() && !obj.save(flush:true)){
Run Code Online (Sandbox Code Playgroud)
&&如果之前的条件评估为,则不会评估条件false.
作为false && true评估false,从语言的角度来看,评估第二个条件是低效的.
毕竟,在这种情况下,obj.save(..)永远不会被调用.