grails项目关于域更新
当然,这不是真正的代码,就像这种格式一样,最终的结果是抛出异常并更新用户。 你知道为什么吗?看看这个:grails项目关于域更新,grails,dom,Grails,Dom,当然,这不是真正的代码,就像这种格式一样,最终的结果是抛出异常并更新用户。 你知道为什么吗?看看这个: class UserController { def userService; def execute() { try{ User user=User.get(params.id.toLong()); if(user){ user.name="kevin"; u
class UserController {
def userService;
def execute() {
try{
User user=User.get(params.id.toLong());
if(user){
user.name="kevin";
userService.updateUser(user);
}
}catch(Exception e){
def map = ['exceptionmsg' : e.getMessage()];
render map as JSON;
}
}
}
-------------------
class UserService {
static transactional = true
def updateUser(User user)throws Exception{
user.desc="I'm a boy"
throw new Exception("this test");
if(!user.save()){
throw new RuntimeException(user.error.toString());
}
}
}
在第6行中,您抛出一个异常。删除此行。由于所有代码都未格式化,因此需要设置一点格式。可能是因为
引发异常
将异常设置为选中异常,而事务仅针对未选中异常回滚。是否尝试删除引发异常的?
class UserService {
static transactional = true
def updateUser(User user)throws Exception{
user.desc="I'm a boy"
//throw new Exception("this test");
if(!user.save()){
throw new RuntimeException(user.error.toString());
}
}
}