注册(密码前后一致问题解决)

来源:互联网 发布:歼20就是个笑话 知乎 编辑:程序博客网 时间:2024/06/03 18:25
def save(User userInstance) {
        if (userInstance == null) {
            notFound()
            return
        }
else if(params.password!=params.passwordAgain){
 flash.message="密码前后不一致,请重新输入!" 
 redirect(action:"create")
//此处既保证了grails自带的验证可以得到验证又可以保证自己设定的条件得到满足

}else{


if (userInstance.hasErrors()) {
            respond userInstance.errors, view:'create'
            return
        }
           //def u=new User(params)
          
           
       userInstance.save flush:true


        request.withFormat {
            form {
                flash.message = message(code: 'default.created.message', args: [message(code: 'userInstance.label', default: 'User'), userInstance.id])
                redirect userInstance
            }
            '*' { respond userInstance, [status: CREATED] }
        }
      
       
       }


        
       
    }
原创粉丝点击