帖子功能加入[发布/更新/评论/置顶/加精/删除]
This commit is contained in:
58
src/main/java/com/lxyer/controller/CommentController.java
Normal file
58
src/main/java/com/lxyer/controller/CommentController.java
Normal file
@@ -0,0 +1,58 @@
|
||||
package com.lxyer.controller;
|
||||
|
||||
import com.jfinal.aop.Before;
|
||||
import com.jfinal.kit.Kv;
|
||||
import com.jfinal.plugin.activerecord.Page;
|
||||
import com.lxyer.config.JBean;
|
||||
import com.lxyer.config.interceptor.LoginInterceptor;
|
||||
import com.lxyer.model.Comment;
|
||||
import com.lxyer.service.CommentService;
|
||||
|
||||
/**
|
||||
* Created by JUECHENG at 2018/1/8 23:07.
|
||||
*/
|
||||
public class CommentController extends IController {
|
||||
|
||||
CommentService service = CommentService.me;
|
||||
/**
|
||||
* 评论列表
|
||||
*/
|
||||
public void list(){
|
||||
Kv kv = getParams("contentId");
|
||||
Page<Comment> page = Comment.dao.findPage(getPn(), getPs(), kv);
|
||||
|
||||
renderJBean(page);
|
||||
}
|
||||
|
||||
/**
|
||||
* 评论详情
|
||||
*/
|
||||
public void info(){
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 评论保存
|
||||
*/
|
||||
@Before(LoginInterceptor.class)
|
||||
public void save(){
|
||||
Comment comment = getModel(Comment.class);
|
||||
|
||||
service.save(comment, getUserId());
|
||||
renderJBean(JBean.success);
|
||||
}
|
||||
|
||||
/**
|
||||
* todo:更新状态
|
||||
*/
|
||||
public void update_status(){
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* todo:评论点赞
|
||||
*/
|
||||
public void support(){
|
||||
|
||||
}
|
||||
}
|
@@ -2,7 +2,6 @@ package com.lxyer.controller;
|
||||
|
||||
import com.jfinal.kit.Kv;
|
||||
import com.jfinal.plugin.activerecord.Page;
|
||||
import com.jfinal.plugin.activerecord.Record;
|
||||
import com.lxyer.model.Content;
|
||||
import com.lxyer.model.User;
|
||||
|
||||
|
@@ -6,6 +6,7 @@ import com.jfinal.plugin.activerecord.*;
|
||||
import com.jfinal.plugin.redis.Cache;
|
||||
import com.jfinal.plugin.redis.Redis;
|
||||
import com.lxyer.config.E;
|
||||
import com.lxyer.config.JBean;
|
||||
import com.lxyer.model.User;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -51,6 +52,10 @@ public class IController extends Controller {
|
||||
return kv;
|
||||
}
|
||||
|
||||
public void renderJBean(Object obj){
|
||||
renderJson(new JBean(1, null, obj));
|
||||
}
|
||||
|
||||
public int getPn(){
|
||||
return getParaToInt("pn", 1);
|
||||
}
|
||||
@@ -121,4 +126,11 @@ public class IController extends Controller {
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* todo:文件上传
|
||||
*/
|
||||
public void upFile(){
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,9 +1,12 @@
|
||||
package com.lxyer.controller;
|
||||
|
||||
import com.jfinal.aop.Before;
|
||||
import com.jfinal.aop.Clear;
|
||||
import com.jfinal.kit.Kv;
|
||||
import com.lxyer.config.JsonBean;
|
||||
import com.jfinal.plugin.activerecord.Page;
|
||||
import com.lxyer.config.JBean;
|
||||
import com.lxyer.config.interceptor.LoginInterceptor;
|
||||
import com.lxyer.model.Comment;
|
||||
import com.lxyer.model.Content;
|
||||
import com.lxyer.service.ContentService;
|
||||
|
||||
@@ -12,35 +15,39 @@ import java.util.List;
|
||||
/**
|
||||
* Created by JUECHENG at 2018/1/7 16:48.
|
||||
*/
|
||||
@Before(LoginInterceptor.class)
|
||||
public class JieController extends IController{
|
||||
|
||||
private ContentService contentService = ContentService.me;
|
||||
private ContentService service = ContentService.me;
|
||||
private int userId;
|
||||
|
||||
/**
|
||||
* 帖子详情
|
||||
*/
|
||||
@Clear(LoginInterceptor.class)
|
||||
public void index(){
|
||||
int contentId = getParaToInt(0);
|
||||
|
||||
//ContentInfo content = contentService.contentInfo(sessionid, contentid);
|
||||
//Sheet<CommentInfo> comments = commentService.commentQuery(request.getSessionid(false) ,contentid, new Flipper().limit(30));
|
||||
|
||||
Content content = Content.dao.findFirst(Kv.by("contentId", contentId));
|
||||
|
||||
//评论
|
||||
Page<Comment> comments = Comment.dao.findPage(getPn(), getPs(), Kv.by("contentId", contentId));
|
||||
|
||||
//热议
|
||||
List<Content> hotReply = Content.dao.findPage(1, 8, Kv.by("order", "replyNum DESC")).getList();
|
||||
|
||||
setAttr("bean", content);
|
||||
setAttr("comments", comments);
|
||||
setAttr("hotReply", hotReply);
|
||||
|
||||
//todo: 访问量+1
|
||||
|
||||
render("detail.html");
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加/修改帖子
|
||||
*/
|
||||
@Before(LoginInterceptor.class)
|
||||
public void add(){
|
||||
setAttr("bean", Content.dao.findById(getParaToInt()));
|
||||
|
||||
@@ -50,13 +57,62 @@ public class JieController extends IController{
|
||||
/**
|
||||
* 帖子保存
|
||||
*/
|
||||
@Before(LoginInterceptor.class)
|
||||
public void save() {
|
||||
Content content = getModel(Content.class);
|
||||
|
||||
contentService.save(content, getUserId());
|
||||
service.save(content, getUserId());
|
||||
|
||||
renderJson(JsonBean.success());
|
||||
renderJson(JBean.success);
|
||||
}
|
||||
|
||||
/**
|
||||
* 帖子删除
|
||||
*/
|
||||
public void del(){
|
||||
JBean bean = new JBean(1);
|
||||
try {
|
||||
service.del(getParaToInt("contentId"), getUserId());
|
||||
} catch (Exception e) {
|
||||
bean.setCode(-1, e.getMessage());
|
||||
}
|
||||
|
||||
renderJson(bean);
|
||||
}
|
||||
|
||||
/**
|
||||
* 帖子收藏
|
||||
*/
|
||||
public void collect(){
|
||||
JBean bean = new JBean(1);
|
||||
|
||||
Integer contentId = getParaToInt("contentId");
|
||||
Integer status = getParaToInt("ok", 1);
|
||||
try {
|
||||
service.collect(contentId, getUserId(), status);
|
||||
|
||||
} catch (Exception e) {
|
||||
bean.setCode(-1, e.getMessage());
|
||||
}
|
||||
|
||||
renderJson(bean);
|
||||
}
|
||||
|
||||
/**
|
||||
* 帖子加精/置顶
|
||||
*/
|
||||
public void set(){
|
||||
JBean bean = new JBean(1);
|
||||
|
||||
Integer contentId = getParaToInt("id");
|
||||
String field = getPara("field");
|
||||
Integer v = getParaToInt("v");
|
||||
|
||||
try {
|
||||
service.upField(contentId, field, v, getUserId());
|
||||
} catch (Exception e) {
|
||||
bean.setCode(-1, e.getMessage());
|
||||
}
|
||||
|
||||
renderJson(bean);
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package com.lxyer.controller;
|
||||
|
||||
import com.lxyer.config.JsonBean;
|
||||
import com.lxyer.config.JBean;
|
||||
import com.lxyer.model.User;
|
||||
import com.lxyer.service.UserService;
|
||||
|
||||
@@ -15,7 +15,7 @@ public class UserController extends IController {
|
||||
* 注册
|
||||
*/
|
||||
public void create(){
|
||||
JsonBean bean = new JsonBean(1);
|
||||
JBean bean = new JBean(1);
|
||||
String email = getPara("email");
|
||||
String pwd = getPara("pwd");
|
||||
String nickname = getPara("nickname");
|
||||
@@ -39,10 +39,10 @@ public class UserController extends IController {
|
||||
return;
|
||||
}else if ("out".equals(para)){
|
||||
removeSessionAttr("user");
|
||||
renderJson(JsonBean.success());
|
||||
renderJson(JBean.success);
|
||||
return;
|
||||
}
|
||||
JsonBean bean = new JsonBean(1);
|
||||
JBean bean = new JBean(1);
|
||||
String username = getPara("username");
|
||||
String pwd = getPara("pwd");
|
||||
|
||||
@@ -73,7 +73,7 @@ public class UserController extends IController {
|
||||
* 修改密码
|
||||
*/
|
||||
public void repwd(){
|
||||
JsonBean bean = new JsonBean(1);
|
||||
JBean bean = new JBean(1);
|
||||
String pwd = getPara("pwd");
|
||||
|
||||
try {
|
||||
|
Reference in New Issue
Block a user