向老码农的自留地的求助
爱情魔方★嫒吧
全部回复
仅看楼主
level 7
爱情魔方★嫒
楼主
特别感谢你能够热心回答我的问题!特别感谢!
2013年07月23日 03点07分
1
level 7
爱情魔方★嫒
楼主
首先我做的是一个极其简单的论坛 功能就是能够对版块、帖子、评论、用户进行增删改 没了!
这是我的版块的domain
class Board {
String boardName
String description
Integer postCount
2013年07月23日 03点07分
2
level 7
爱情魔方★嫒
楼主
static hasMany = 【boarders:User,articles:Article】
static constraints = {
description(maxLength:100, blank:false)
boardName(size:5..10, unique:true, blank:false)
}
}
版块可以有多个版主boarders,是User型的
2013年07月23日 03点07分
3
level 7
爱情魔方★嫒
楼主
class User {
String nickName
String password
String email
String sex
Date birthday//
String address//
String signDetail//
String picture//
String qq//
Date registerTime = new Date()
Date lastLoginTime = new Date()
String boarder //是否是版主
static hasMany = 【articles:Article,comments:Comment】
static constraints = {
nickName(size:5..10, unique:true)
password(size:6..15)email(email:true, unique:true)
//sex(inList:[0, 1])
birthday(nullable: true)
address(nullable: true)
signDetail(nullable: true)
picture(nullable: true)
qq(nullable: true)
}
}
2013年07月23日 03点07分
4
level 7
爱情魔方★嫒
楼主
然后我想管理员输入版主
在BoardController里 board.addToBoarders(new User(nickName:params.nickName)).save()
这样写不对 那要怎么写啊
2013年07月23日 03点07分
5
level 7
爱情魔方★嫒
楼主
board.boarders.nickName = params.nickName 这样写也不对
2013年07月23日 03点07分
6
老码农的自留地
你的User类定义里边的constraints里有这个: password(size:6..15)email(email:true, unique:true) 这两个属性在new User的时候都要有,另外最好分开两行写。 还有就是String属性是blank:true,而不是nullable:true。
2013年07月23日 03点07分
level 7
爱情魔方★嫒
楼主
我在BoardController里的
def create() {
def board = new Board(
boardName:params.boardName,
description:params.description,
postCount:0,
boarders: User.get(1),
//boarders:params.boarders,
)
board.save(failOnError: true)
redirect action:'index'
}
这样写的话输出如下
2013年07月23日 06点07分
7
level 7
爱情魔方★嫒
楼主
//boarders: User.get(1),
boarders:params.boarders,
这样写的话我新建时
保存之后就变成
2013年07月23日 06点07分
8
老码农的自留地
boarders:params.boarders当然不对,boarders是User实例,params.boarders是个id 字符串,另外你要把console输出的错误信息都贴过来,比较容易找到问题根源。
2013年07月23日 06点07分
老码农的自留地
新建gsp里边把用户输入框改成<g:select name="user.id" from="${User.list()}" value="${user?.nickName}" optionKey="id" optionValue="nickName"/> , controller里改成 boarders: User.get(params.user.id)
2013年07月23日 06点07分
level 7
爱情魔方★嫒
楼主
dataSource {
pooled = true
driverClassName = "com.mysql.jdbc.Driver"
username = "root"
password = ""
}
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = false
cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'}
// environment specific settings
environments {
development {
dataSource {
dbCreate = "update"
// one of 'create', 'create-drop', 'update', 'validate', ''
url = "jdbc:mysql://localhost/bbs?characterEncoding=gbk"
}
}
test { dataSource { dbCreate = "update" url = "jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000" } } production { dataSource { dbCreate = "update" url = "jdbc:h2:prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000" pooled = true properties { maxActive = -1 minEvictableIdleTimeMillis=1800000 timeBetweenEvictionRunsMillis=1800000 numTestsPerEvictionRun=3 testOnBorrow=true testWhileIdle=true testOnReturn=true validationQuery="SELECT 1" } } }}
2013年07月23日 06点07分
9
1