在intelli-j设置ClassProject-structure Libraries加入grails 库
B和A是1:1 如果B有 static belongsTo=A //允许A直接获取B
A和B是1:m A是Many side B是one side,B中不包含many side的引用就会创建第三章中间表,否则不创建
Controller
render(view:"", model:[])
render text:"",contentType:""
render(template:"", model[])
redirect(action:"",controller:"")
redirect参数:
action, controller, params, id, uri, url
返回一个model到默认view
def action={[key:""]}
在action内数据绑定
1 吧params传入构造函数, def album = new Album(params)
2 def album = new Album() album.gen=params.gen album.name=params.name
3 def album = Album.get(params.id) album.properties = params
创建一个command,command放在controller目录下
class Command{
String name
List songs[]
static constraints={
name blank:false
}
Bean createBean(){
def bean = new Bean();
bean.name=name;
bean.songs=songs;
return bean;
}
}
class Controller{
def save={
Command cmd->
}
}
<g:form url="[controller:'album',action='save']">
<input type="text" name="name"/>
<input type="text" name="songs[0]"/>
</g:form>
<g:renderError bean="{cmd}"/>