play framework学习(数据库建表)

来源:互联网 发布:手机频谱分析软件 编辑:程序博客网 时间:2024/06/05 13:50

在建数据库的表时,要注意:

如User里@OneToMany(mappedBy="user",cascade=CascadeType.ALL) 

public List<Post> posts;

Post里

@ManyToOne 

public User user;

在action中不要传递对象,因为url中会将传递的参数的信息写上去。

建表时最好不要自己额外设置关键字,要用sql中分配的id,这样可以节省大量的空间。

校验:

在html中

#{ifErrors}

<div class="error">

<h2 class="header">

please correct these errors

</h2> 

</div>

#{/ifErrors}

<input type="password" name="userpwd" class="userpwd" value=${_userpwd}>

<span class="error"> #{error 'userpwd'/}</span>

在action中

validation.required(userpwd);

validation.minSize(userpwd,6);

if(validation.hasErrors()){

render("@register");

}

这样在不满足条件时,就会有相应的提示。

 

0 0
原创粉丝点击