创建一个简单的Web应用(基于mysql数据库)
1。下载并安装Groovy和Grails
Groovy:http://groovy.codehaus.org/Download
Grails:http://grails.org/Installation
2。创建数据库表:
DROP TABLE IF EXISTS `ebxmlrr`.`comics`;
CREATE TABLE `ebxmlrr`.`comics` (
`id` bigint(20) NOT NULL auto_increment,
`version` bigint(20) NOT NULL,
`issue` bigint(20) NOT NULL,
`title` varchar(255) NOT NULL,
`publisher` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
3。创建Web 应用
>grails create-app
....
.....
create-app:
[input] Enter application name:
comics_catalog
.....
命令行提示要求输入应用的名字,然后输入:comics_catalog
4。添加Domain Classes
> cd comics_catalog
> grails create-domain-class
....
create-domain-class:
[input] Enter domain class name:
comics
....
当命令行要求输入类名字时,输入comics,这个名字必须和数据库中的表的名字一致
框架将产生./comics_catalog/grails-app/domain/Comics.groovy 并修改为如下
class Comics {
@Property Long id
@Property Long version
// new properties for the Comics class
@Property String title
@Property Long issue
@Property String publisher
String toString() { "${this.class.name} : $id" }
}
5。然后从domain class产生其他的部分
> grails generate-all
....
input-domain-class:
[input] Enter domain class name:
comics
....
命令行要求输入domain class name 时输入刚才的class name:comics
然后框架将产生views和Controllers。
./comics_catalog/grails-app/controllers
./comics_catalog/grails-app/views
6。配置数据库连接
在./comics_catalog/grails-app/conf/DevelopmentDataSource .groovy
修改为如下所示:
class DevelopmentDataSource {
boolean pooling = true
String dbCreate = "create-drop" // one of 'create', 'create-drop','update'
String url = "jdbc:mysql://localhost/*****"
String driverClassName = "com.mysql.jdbc.Driver"
String username = "userid"
String password = "password"
}
然后将mysql的数据库驱动文件mysql-connector-java-5.0.4-bin.jar考到
./comics_catalog/lib/ 下
7。运行web程序
> grails run-app
默认端口为8080
如想修改端口则>grails -Dserver.port=9090 run-app
8.在浏览器中输入
http://localhost:8080/comics_catalog/comics/你将看到刚才所作的成果了啊
9.发布
>grails war
分享到:
相关推荐
[Apress] Groovy, Grails, Griffon 入门教程 (英文版) [Apress] Beginning Groovy, Grails and Griffon (E-Book) ☆ 出版信息:☆ [作者信息] Vishal Layka, Christopher M. Judd, Joseph Faisal Nusairat, Jim ...
Groovy和Grails配置方法 教你从0入手,一步一步深入安装和测试,包含环境和语言的下载地址
groovy-grails-tool-suite-3.6.4.RELEASE-e4.4.2-win32-x86_64.part1 共两个压缩包,解压后将扩展名.zip.bak改为.zip再次解压。
begining groovy and grails
Groovy / Grails F2 The Best Web Server
Groovy / Grails F4 The Best Web Server
Groovy / Grails F3 The Best Web Server
Groovy and Grails Recipes.pdf ebook
groovy-grails-tool-suite-3.6.4.RELEASE-e4.4.2-win32-x86_64.part2 共两个包,解压后需要将扩展名.zip.bak改名为.zip重新解压。 http://dist.springsource.com/release/STS/3.8.1.RELEASE/dist/ e4.6/spring-tool-...
Groovy&Grails - 指南.pptGroovy&Grails - 指南.pptGroovy&Grails - 指南.pptGroovy&Grails - 指南.pptGroovy&Grails - 指南.ppt
Agile Development with Groovy and Grails.pdf
Apress - Beginning Groovy and Grails, From Novice to Professional.pdf
Groovy and Grails Recipes 作者:Bashar Abdul-Jawad 共407页 PART 1 Groovy by Example CHAPTER 1 Getting Started with Groovy CHAPTER 2 From Java to Groovy CHAPTER 3 Groovy Data Types and Control ...
NULL 博文链接:https://ivaneye.iteye.com/blog/305661
[Apress] Groovy & Grails 新手进阶教程 (英文版) [Apress] Beginning Groovy and Grails From Novice to Professional (E-Book) ☆ 出版信息:☆ [作者信息] Christopher M. Judd, Joseph Faisal Nusairat, ...
Groovy Grails , The best web server.
Beginning Groovy and Grails From Novice to Professional Christopher M. Judd, Joseph Faisal Nusairat, James Shingler
介绍groovy语法和grails基本知识的ppt
搜索到的介绍groovy的ppt
eclipse插件grails(groovy)配置方法