我在使用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」域類的初始實例。 '主題'是一類帖子 –