如何使用intellij idea 创建的grails去写一个登录页面然后实现增删改查
展开全部
1.安装grails
下载grails,然后配置:
GRAILS_HOME=”D:/JavaDev/grails”
path追加:%GRAILS_HOME%/bin
2.创建grails项目
3.配置数据源
打开conf/DataSource.groovy
dataSource {
dbCreate = "update"
url = "jdbc:mysql://192.168.58.11:3306/grailsdb?useUnicode=true&characterEncoding=UTF-8"
driverClassName = "com.mysql.jdbc.Driver"
username = "root"
password = "root"
}
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = false
cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory' // Hibernate 3
// cache.region.factory_class = 'org.hibernate.cache.ehcache.EhCacheRegionFactory' // Hibernate 4
}
// environment specific settings
environments {
development {
dataSource {
dbCreate = "update" // one of 'create', 'create-drop', 'update', 'validate', ''
url = "jdbc:mysql://192.168.58.11:3306/grailsdb?useUnicode=true&characterEncoding=UTF-8"
}
}
test {
dataSource {
dbCreate = "update"
url = "jdbc:mysql://192.168.58.11:3306/grailsdb?useUnicode=true&characterEncoding=UTF-8"
}
}
production {
dataSource {
dbCreate = "update"
url = "jdbc:mysql://192.168.58.11:3306/grailsdb?useUnicode=true&characterEncoding=UTF-8"
properties {
maxActive = -1
minEvictableIdleTimeMillis=1800000
timeBetweenEvictionRunsMillis=1800000
numTestsPerEvictionRun=3
testOnBorrow=true
testWhileIdle=true
testOnReturn=false
validationQuery="SELECT 1"
jdbcInterceptors="ConnectionState"
}
}
}
}12345678910111213141516171819202122232425262728293031323334353637383940414243444546
4.引入数据库驱动包
lib下添加mysql-connector-java-5.1.32.jar
用命令refresh-dependencies添加到依赖
5.新建Domain类。
两种方式:(1)通过命令:create-domain-class Book(2)右键-〉New-〉Domain Class
Book代码如下:
package hellograils
class Book {
String title
String content
static constraints = {
}
}12345678
6.创建controller和views:两种方式
(1)打Book类,点击图标上面的Controller 和Views 就可以产生代码了
(2)命令grails generate-all hellograils.Book
grails会自动创建Controller(会自动生成增、删、改、查的相关方法)和View(会自动生成增、删、改、查的相关页面)
下载grails,然后配置:
GRAILS_HOME=”D:/JavaDev/grails”
path追加:%GRAILS_HOME%/bin
2.创建grails项目
3.配置数据源
打开conf/DataSource.groovy
dataSource {
dbCreate = "update"
url = "jdbc:mysql://192.168.58.11:3306/grailsdb?useUnicode=true&characterEncoding=UTF-8"
driverClassName = "com.mysql.jdbc.Driver"
username = "root"
password = "root"
}
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = false
cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory' // Hibernate 3
// cache.region.factory_class = 'org.hibernate.cache.ehcache.EhCacheRegionFactory' // Hibernate 4
}
// environment specific settings
environments {
development {
dataSource {
dbCreate = "update" // one of 'create', 'create-drop', 'update', 'validate', ''
url = "jdbc:mysql://192.168.58.11:3306/grailsdb?useUnicode=true&characterEncoding=UTF-8"
}
}
test {
dataSource {
dbCreate = "update"
url = "jdbc:mysql://192.168.58.11:3306/grailsdb?useUnicode=true&characterEncoding=UTF-8"
}
}
production {
dataSource {
dbCreate = "update"
url = "jdbc:mysql://192.168.58.11:3306/grailsdb?useUnicode=true&characterEncoding=UTF-8"
properties {
maxActive = -1
minEvictableIdleTimeMillis=1800000
timeBetweenEvictionRunsMillis=1800000
numTestsPerEvictionRun=3
testOnBorrow=true
testWhileIdle=true
testOnReturn=false
validationQuery="SELECT 1"
jdbcInterceptors="ConnectionState"
}
}
}
}12345678910111213141516171819202122232425262728293031323334353637383940414243444546
4.引入数据库驱动包
lib下添加mysql-connector-java-5.1.32.jar
用命令refresh-dependencies添加到依赖
5.新建Domain类。
两种方式:(1)通过命令:create-domain-class Book(2)右键-〉New-〉Domain Class
Book代码如下:
package hellograils
class Book {
String title
String content
static constraints = {
}
}12345678
6.创建controller和views:两种方式
(1)打Book类,点击图标上面的Controller 和Views 就可以产生代码了
(2)命令grails generate-all hellograils.Book
grails会自动创建Controller(会自动生成增、删、改、查的相关方法)和View(会自动生成增、删、改、查的相关页面)
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询