Grails Quick Start
2020-02-17 05:04
267 查看
Grails Quick Start
安装 grails
安装方式很多
- 官网安装 https://grails.org/
- 本机是 mac os 选择用 homebrew 安装的
brew install grails
创建项目
使用 grails 命令 创建项目:
grails create-app my-project
项目目录 :
%PROJECT_HOME% + grails-app + conf ---> location of configuration artifacts + hibernate ---> optional hibernate config + spring ---> optional spring config + controllers ---> location of controller artifacts + domain ---> location of domain classes + i18n ---> location of message bundles for i18n + services ---> location of services + taglib ---> location of tag libraries + util ---> location of special utility classes + views ---> location of views + layouts ---> location of layouts + lib + scripts ---> scripts + src + groovy ---> optional; location for Groovy source files (of types other than those in grails-app/*) + java ---> optional; location for Java source files + test ---> generated test classes + web-app + WEB-INF
创建领域类
cd my-project grails create-domain-class org.example.Book
编辑类 添加一些属性
package org.example class Book { String title String author static constraints = { title(blank: false) author(blank: false) } }
constraints函数中可以添加一些约束
创建控制器
grails create-controller org.example.Book // Note the capital B
简单的 controller
def index={ //在控制器中定义的任何一个闭包都会暴露成一个 url render "Hello World" }
你会看到 “Hello World”。
来个更高级的: 如果定义了scaffold grails 会给自动创建 CUDR 的逻辑是不是很神奇?
package org.example class BookController { def scaffold = Book // Note the capital "B" }
运行
grails run-app
访问 http://localhost:8080 你看到了什么 BookController 点进去就是它的 CRUD 了
访问 http://localhost:8080/test Hello world
连接数据库
dataSource: pooled: true jmxExport: true driverClassName: org.postgresql.Driver username: changeme password: changeme environments: development: dataSource: dbCreate: create-drop url: jdbc:postgresql://10.32.150.91:5432/psyco
转载于:https://my.oschina.net/nslunhui/blog/804986
- 点赞
- 收藏
- 分享
- 文章举报
相关文章推荐
- iOS开发 粗解UIDynamicAnimator
- Fluent NHibernate的配置
- C# 浅谈ThreadPool -- 上篇(Enqueue)
- @RequestMa'pping注解 value的值
- element-ui 表格表头禁用全选功能
- XMLHttpRequest Level 2 使用指南
- XMLHttpRequests规范文档
- HBuilder的常用快捷键
- intelliJ idea自动生成UID
- 连接数据库提示: 'Client does not support authentication protocol requested by server
- JSON 用Iterator 遍历key 和value
- 【Uinty】物理基础
- elementUI table表头错位问题
- Document is missing mandatory uniqueKey field: id解决方案
- 灵活实用require.js,让JS加载速度更流畅
- UGUI 5.0 一些笔记
- uicollectionview 不调用cellForItemAtIndexPath
- UIViewController
- 学习基于LABVIEW的Arduino开发设计 ——8*8LED点阵转圈圈
- That would lead to questions