我在使用grails创建Web论坛时遇到了一些问题。在我的控制器中,我需要为网站工作创建一个标准主题,我使用的是教程代码。所以我的问题是:如何创建一个标准的主题为了这个代码工作?创建标准主题
,我需要创建的部分是在第11行
控制器:
class ForumController {
def springSecurityService
def home() {
[sections:Section.listOrderByTitle()]
}
def topic(long topicId) {
Topic topic = Topic.get(topicId)
if (topic == null){
}
params.max = 10
params.sort = 'createDate'
params.order = 'desc'
[threads:DiscussionThread.findAllByTopic(topic, params),
numberOfThreads:DiscussionThread.countByTopic(topic), topic:topic]
}
def thread(long threadId) {
DiscussionThread thread = DiscussionThread.get(threadId)
params.max = 10
params.sort = 'createDate'
params.order = 'asc'
[comments:Comment.findAllByThread(thread, params),
numberOfComments:Comment.countByThread(thread), thread:thread]
}
@Secured(['ROLE_USER'])
def postReply(long threadId, String body) {
def offset = params.offset
if (body != null && body.trim().length() > 0) {
DiscussionThread thread = DiscussionThread.get(threadId)
def commentBy = springSecurityService.currentUser
new Comment(thread:thread, commentBy:commentBy, body:body).save()
// go to last page so user can view his comment
def numberOfComments = Comment.countByThread(thread)
def lastPageCount = numberOfComments % 10 == 0 ? 10 : numberOfComments % 10
offset = numberOfComments - lastPageCount
}
redirect(action:'thread', params:[threadId:threadId, offset:offset])
}
}
这是有点不清楚,你问什么。您正在创建一个网络论坛,并且不确定如何设置默认的“主题”?在这种情况下,主题究竟意味着什么?主题是简单的帖子的名称 - 还是它的一个职位类别? –
是的,英语并不是我的第一语言,对此我很抱歉,但我正在尝试创建一个“Topic”域类的初始实例。 '主题'是一类帖子 –