1、建立表之间的一对多关系:
public class Role {
String rolename;
String description;
int role_gid;
static hasMany=[user:User]; ①
String toString(){"${this.rolename}"}; ②
}
class User {
String username;
String password;
...
Role role;
static belongsTo=Role; ③
}
① 角色表Role 和 用户表User建立一对多的关系,hasMany 属性名----类名对
② toString 为领域类重写有意义的记录标识符
③ belongsTo 标明一个用户必须属于一个角色,建立级联关系
2、ACTION拦截器
拦截进入功能页面的访问,常用于用户登录验证 def beforeInterceptor = [action:this.&checkUser, except: ['userlogin','doLogin']] def beforeInterceptor = [action:this.&checkUser, only: ['list', 'show']] // checkUser:验证方法名字; 'userlogin','doLogin'...:action名字 3、模版页面 命名:_adminmenubar.gsp 位置:grails-app/views 引用:<g:render template="/adminmenubar" /> 4、页面布局 ① 外观样式表 web-app/css ② 图片 web-app/images ③ 公共页面布局模版 grails-app/views/layouts <head> ....... <meta name="layout" content="public" /> //public: 布局模版名字 </head> Public.Gsp <html> <head> <title><g:layoutTitle default="Racetrack" /></title> <link rel="stylesheet" href="${createLinkTo(dir:'css',file:'public.css')}"> </link> <g:layoutHead /> </head> <body> <table class="contentArea"> <tr> <td> <div class="logo"></div> <g:layoutBody /> </td> </tr> </table> </body> </html> <g:layoutTitle>、<g:layoutHead >、<g:layoutBody >:实际页面内容的占位符 比如在运行时,Grails会渲染页面里的<body>标签的内容来代替<g:layoutBody >标签