我在Grails控制器中遇到问题。控制器的逻辑是执行某些数据的检查(通过服务调用),然后如果该服务返回true,则保存数据。但是,当检查发生并失败时,数据仍然存在......
这是基本的控制器动作代码(criteria.isMet和criteria.msg是服务方法通过地图返回的值):
def save() {
{
def object = new Domain(params)
object.name = "OBJECT"
def criteria = service.isCriteriaMet(object)
if(criteria.isMet){
object.save(flush: true)
render(view: "show", model: [objectInstance: object])
}else{
render(view: "create", model: [objectInstance: object])
object?.errors?.rejectValue("id", "default.message", [message(code: messageLabel)] as Object[], criteria.msg)
}
}