-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
173 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,48 @@ | ||
<div class="com_container"> | ||
<div class="com_header"> | ||
<span> | ||
评论 共${count}条评论 | ||
评论 共${comment_list.totalRow}条评论 | ||
</span> | ||
<a href="#add_comment"> | ||
发表评论 | ||
</a> | ||
</div> | ||
<#list comment_list.list as comment> | ||
<div class="com_item clearfix"> | ||
<a href="http://my.siyanjing.com/${comment.comment_uname}" class="avatar"> | ||
<img src="<#if comment.avatar ??>${comment.avatar}<#else>/images/photo.jpg</#if>" width="34" height="34"/> | ||
</a> | ||
<div class="com_cnt"> | ||
<p class="meta"> | ||
${comment_index+1}楼:${comment.comment_unickname} 发布于${comment.comment_date} | ||
<a href="javascript:reply('${comment.comment_uname}','${comment.comment_unickname}')"> | ||
回复 | ||
</a> | ||
</p> | ||
<p class="cnt"> | ||
${comment.comment} | ||
</p> | ||
<div id="comment_content"> | ||
<#list comment_list.list as comment> | ||
<div class="com_item clearfix"> | ||
<a href="http://my.siyanjing.com/${comment.comment_uname}" class="avatar"> | ||
<img src="<#if comment.avatar ??>${comment.avatar}<#else>/images/photo.jpg</#if>" width="34" height="34"/> | ||
</a> | ||
<div class="com_cnt"> | ||
<p class="meta"> | ||
${(comment_list.pageNumber-1)*comment_list.pageSize+comment_index+1}楼:${comment.comment_unickname} 发布于${comment.comment_date} | ||
<a href="javascript:reply('${comment.comment_uname}','${comment.comment_unickname}')"> | ||
回复 | ||
</a> | ||
</p> | ||
<p class="cnt"> | ||
${comment.comment} | ||
</p> | ||
</div> | ||
</div> | ||
</#list> | ||
<div id="comment_page"> | ||
<#include "/layout/_paginate.html" /> | ||
<@paginate currentPage=comment_list.pageNumber totalPage=comment_list.totalPage actionUrl="javascript:void();#" /> | ||
</div> | ||
</div> | ||
</#list> | ||
<div id="comment_add"> | ||
<div id="comment_add" class="clearfix"> | ||
<#if auth_user??> | ||
<div contenteditable="true" class="editor" name="${target}"></div> | ||
<div class="btn-g blue submit"> | ||
发表评论 | ||
</div> | ||
<div contenteditable="true" class="editor" name="${target}"> | ||
</div> | ||
<div class="btn-g blue submit"> | ||
发表评论 | ||
</div> | ||
<div id="submit_info"> | ||
</div> | ||
<#else> | ||
<a href="/login?redirect=">登录</a>后评论 | ||
</#if> | ||
<a href="/login?redirect="> | ||
登录 | ||
</a>后评论</#if> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,74 @@ | ||
package me.thinkjet.controller; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import me.thinkjet.auth.AuthManager; | ||
import me.thinkjet.auth.AuthUser; | ||
import me.thinkjet.model.Comment; | ||
|
||
import com.jfinal.aop.Before; | ||
import com.jfinal.core.Controller; | ||
import com.jfinal.ext.route.ControllerBind; | ||
import com.jfinal.plugin.ehcache.CacheInterceptor; | ||
import com.jfinal.plugin.ehcache.CacheName; | ||
import com.jfinal.plugin.activerecord.Page; | ||
import com.jfinal.plugin.ehcache.CacheKit; | ||
|
||
/** | ||
* CommonController | ||
*/ | ||
@ControllerBind(controllerKey = "/comment", viewPath = "/") | ||
public class CommentController extends Controller { | ||
@Before(CacheInterceptor.class) | ||
@CacheName("comment") | ||
public void index() { | ||
String target = this.getPara(0); | ||
int page = this.getParaToInt(1, 1); | ||
this.setAttr("target", target); | ||
this.setAttr("page", page); | ||
this.setAttr("comment_list", Comment.dao.paginateByCache("comment", | ||
target + "_" + page, page, 6, "select c.*,u.avatar as avatar", | ||
target + "_" + page, page, 20, "select c.*,u.avatar as avatar", | ||
"from comment c left join users u " | ||
+ "on c.comment_uname=u.username " | ||
+"where c.target=? " | ||
+ "order by c.id asc", target)); | ||
this.setAttr( | ||
"count", | ||
Comment.dao.findByCache("comment", "count_" + target, | ||
"select count(id) from comment where target=?", target) | ||
.get(0).getAttrValues()[0]); | ||
System.out.println(Comment.dao.paginateByCache("comment", | ||
target + "_" + page, page, 6, "select c.*,u.avatar", | ||
"as avatar from comment c left join users u " | ||
+ "on c.target=? and c.comment_uname=u.username " | ||
+ "order by c.id asc", target)); | ||
+ "where c.target=? " + "order by c.id asc", target)); | ||
this.render("comment.html"); | ||
} | ||
public void add(){ | ||
Comment comment = getModel(Comment.class); | ||
comment.save(); | ||
|
||
public void update() { | ||
String target = this.getPara(0); | ||
int page = this.getParaToInt(1, 1); | ||
this.setAttr("target", target); | ||
this.setAttr("page", page); | ||
Page<Comment> comments = Comment.dao.paginate(page, 20, | ||
"select c.*,u.avatar as avatar", | ||
"from comment c left join users u " | ||
+ "on c.comment_uname=u.username " | ||
+ "where c.target=? " + "order by c.id asc", target); | ||
CacheKit.put("comment", target + "_" + page, comments); | ||
this.setAttr("comment_list", comments); | ||
this.render("comment.html"); | ||
} | ||
|
||
public void add() { | ||
Map<String, Object> attrs = new HashMap<String, Object>(); | ||
if (this.getPara("target") == null || this.getPara("comment") == null | ||
|| AuthManager.getSession(this) == null) { | ||
this.renderHtml("评论失败"); | ||
return; | ||
} | ||
attrs.put("target", this.getPara("target")); | ||
attrs.put("comment", this.getPara("comment")); | ||
AuthUser user = AuthManager.getSession(this); | ||
attrs.put("comment_uname", user.getUser().getStr("username")); | ||
attrs.put("comment_unickname", user.getUser().getStr("name") == null | ||
|| user.getUser().getStr("name").equals("") ? user.getUser() | ||
.getStr("username") : user.getUser().getStr("name")); | ||
if (this.getPara("motion") != null) { | ||
String motion = this.getPara("motion"); | ||
String[] motions = motion.substring(2, motion.length() - 1).split( | ||
","); | ||
String uname = motions[0].split(":")[1]; | ||
String unickname = motions[1].split(":")[1]; | ||
attrs.put("at_uname", uname); | ||
attrs.put("at_unickname", unickname); | ||
} | ||
new Comment().setAttrs(attrs).save(); | ||
this.renderHtml("评论成功!"); | ||
} | ||
|
||
} |