Grails:保存不起作用
我已经在 grails 中创建了新域,并从控制器中创建了我尝试保存的内容,但数据库中没有保存任何内容。代码如下
控制器
def register={
String name = params.name
String email = params.email
String pass = params.password
boolean signedIn = params.signedIn
System.out.println(name + " " + email +" "+ pass+" " + signedIn)
def rUser = new Registered(params)
rUser.signedIn = signedIn
System.out.println(rUser)
rUser.save(flush:true)
}
域名
class Registered {
String name;
String email;
String password;
boolean signedIn =false;
static constraints = {
}
}
,我正在尝试通过此网址保存
http://localhost:8080/egypths/apps/register?name=hegab&[email protected]&password=tom&signedIn=false
那么我做错了什么...记住堆栈跟踪中没有错误
i have created new domain in grails and from a controller i've tried to save but nothing get saved in the database.. the code is as follow
controller
def register={
String name = params.name
String email = params.email
String pass = params.password
boolean signedIn = params.signedIn
System.out.println(name + " " + email +" "+ pass+" " + signedIn)
def rUser = new Registered(params)
rUser.signedIn = signedIn
System.out.println(rUser)
rUser.save(flush:true)
}
domain
class Registered {
String name;
String email;
String password;
boolean signedIn =false;
static constraints = {
}
}
and i'm trying to save by this url
http://localhost:8080/egypths/apps/register?name=hegab&[email protected]&password=tom&signedIn=false
so what am i doing wrong ... putting in mind that there's no error in the stack trace
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我首先将其包装在一个集成测试中,如下所示:
然后我将首先使控制器操作尽可能简单:
这样您可以快速重复测试并找出问题所在。如果未通过验证,将
failOnError:true
添加到 save 调用将导致引发异常。如果这个简单的示例有效,请开始寻找更优雅的解决方案来确定问题所在。I would start by wrapping this in an integration test that would look like this:
Then I would start by making your controller action as simple as possible:
This way you can quickly repeat your test and figure out where your problem is. Adding the
failOnError:true
to the save call will cause an exception to be thrown if it doesn't pass validation. If this simple example works start working back towards a more elegant solution to identify where you're issue resides.