ApplicationController添加方法postComment()
publicstaticvoidpostComment(LongpostId,Stringauthor,Stringcontent){Postpost=Post.findById(postId);post.addComment(author,content);show(postId);}
修改show.html
Yourname:
Yourmessage:
5.添加验证,验证Author和Content非空
importplay.data.validation.*;publicstaticvoidpostComment(LongpostId,@RequiredStringauthor,@RequiredStringcontent){Postpost=Post.findById(postId);if(validation.hasErrors()){render("Application/show.html",post);}post.addComment(author,content);show(postId);}
编辑form,显示错误
#{form@Application.postComment(post.id)}#{ifErrors}
Allfieldsarerequired!
Yourmessage:${params.content}
6.优化客户提示
加载jquery的类库
修改Show.html
#{ifFlash.success}
${flash.success}
添加Comment成功的提示
post.addComment(author,content);flash.success("Thanksforposting%s",author);