http://www.grails.org/
1.官网下载安装grails,配置path环境变量到bin目录下
在命令行输入grails查看变化,如果运行成功就代表安装成功了
安装idea开发工具
2.build.gradle配置文件设置
compile 'org.grails.plugins:spring-security-core:3.1.1' runtime 'mysql:mysql-connector-java:5.1.39'
一个用来配置闭包用户登录权限设置
一个用来配置mysql jdbc驱动
3.mysql配置
dataSource: pooled: true jmxExport: true driverClassName: com.mysql.jdbc.Driver username: yangchuan password: 2719283s+ environments: development: dataSource: dbCreate: update url: jdbc:mysql://localhost:3306/tianxing?useUnicode=true&characterEncoding=UTF-8&useSSL=false test: dataSource: dbCreate: create-drop url: jdbc:mysql://101.251.244.37:3306/tianxing?useUnicode=true&characterEncoding=UTF-8&useSSL=false production: dataSource: dbCreate: update url: jdbc:mysql://10.0.8.100:3306/tianxing?useUnicode=true&characterEncoding=UTF-8&useSSL=false properties: jmxEnabled: true initialSize: 5 maxActive: 50 minIdle: 5 maxIdle: 25 maxWait: 10000 maxAge: 600000 timeBetweenEvictionRunsMillis: 5000 minEvictableIdleTimeMillis: 60000 validationQuery: SELECT 1 validationQueryTimeout: 3 validationInterval: 15000 testOnBorrow: true testWhileIdle: true testOnReturn: false jdbcInterceptors: ConnectionState defaultTransactionIsolation: 2 # TRANSACTION_READ_COMMITTED
要注意格式对称以及首行缩进问题,如果配置标准不一致就会运行失败.
4.用户登陆设置
使用命令grails s2-quickstart com.test User Role 创建用户账户domian
使用命令grails generate-all com.test.User 来创建需要的view和controller
在init目录下的BootStrap中配置用户名与密码:
package dfhfax import com.dfhfax.Role import com.dfhfax.User import com.dfhfax.UserRole class BootStrap { def init = { servletContext -> if(Role.count()<1){ println 'init role data' def r = new Role() r.authority='ROLE_ADMINISTRATOR' r.save() } if (User.count() < 1) { println 'init user data' def c = new User() c.username = 'yangchuan' c.password = '2719283s+' c.save() } if (UserRole.count() < 1) { println 'init user role data' UserRole.create(User.findByUsername('yangchuan'), Role.findByAuthority('ROLE_ADMINISTRATOR')) } } def destroy = { } }
在需要访问页面对应的controller上添加访问权限的标识
@Secured(['ROLE_ADMINISTRATOR'])