grails 开发笔记

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'])


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

yangchuan_csdn91

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值