.
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package com.lxyer.controller;
|
||||
|
||||
import com.jfinal.aop.Before;
|
||||
import com.jfinal.aop.Clear;
|
||||
import com.jfinal.aop.*;
|
||||
import com.jfinal.kit.Kv;
|
||||
import com.jfinal.plugin.activerecord.Page;
|
||||
import com.lxyer.config.JBean;
|
||||
@@ -15,12 +14,14 @@ import com.lxyer.service.CommentService;
|
||||
@Before(LoginInterceptor.class)
|
||||
public class CommentController extends IController {
|
||||
|
||||
CommentService service = CommentService.me;
|
||||
@Inject
|
||||
CommentService service;
|
||||
|
||||
/**
|
||||
* 评论列表
|
||||
*/
|
||||
@Clear(LoginInterceptor.class)
|
||||
public void list(){
|
||||
public void list() {
|
||||
Kv kv = getParams("contentId");
|
||||
Page<Comment> page = Comment.dao.findPage(getPn(), getPs(), kv);
|
||||
|
||||
@@ -31,7 +32,7 @@ public class CommentController extends IController {
|
||||
* 评论详情
|
||||
*/
|
||||
@Clear(LoginInterceptor.class)
|
||||
public void info(){
|
||||
public void info() {
|
||||
|
||||
}
|
||||
|
||||
@@ -39,7 +40,7 @@ public class CommentController extends IController {
|
||||
* 评论保存
|
||||
*/
|
||||
@Before(LoginInterceptor.class)
|
||||
public void save(){
|
||||
public void save() {
|
||||
Comment comment = getModel(Comment.class);
|
||||
|
||||
service.save(comment, getUserId());
|
||||
@@ -49,14 +50,14 @@ public class CommentController extends IController {
|
||||
/**
|
||||
* 更新状态
|
||||
*/
|
||||
public void update_status(){
|
||||
public void update_status() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 评论点赞
|
||||
*/
|
||||
public void support(){
|
||||
public void support() {
|
||||
JBean bean = new JBean(1);
|
||||
Integer commentId = getParaToInt("commentId");
|
||||
Integer ok = getParaToInt("ok");
|
||||
|
@@ -4,6 +4,6 @@ package com.lxyer.controller;
|
||||
* 文件管理
|
||||
* Created by JUECHENG at 2018/1/7 16:44.
|
||||
*/
|
||||
public class FileController extends IController{
|
||||
public class FileController extends IController {
|
||||
|
||||
}
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package com.lxyer.controller;
|
||||
|
||||
import com.jfinal.aop.Inject;
|
||||
import com.jfinal.kit.Kv;
|
||||
import com.jfinal.plugin.activerecord.Page;
|
||||
import com.lxyer.model.Content;
|
||||
@@ -13,21 +14,26 @@ import java.util.List;
|
||||
public class HomeController extends IController {
|
||||
public static final Kv column = Kv.by("qz", 10).set("fx", 20).set("jy", 30).set("gg", 40).set("dt", 50);//栏目
|
||||
|
||||
public void index(){
|
||||
@Inject
|
||||
Content contentDao;
|
||||
@Inject
|
||||
User userDao;
|
||||
|
||||
public void index() {
|
||||
|
||||
//置顶贴
|
||||
List<Content> top = Content.dao.findPage(1, 5, Kv.by("top", 1)).getList();
|
||||
List<Content> top = contentDao.findPage(1, 5, Kv.by("top", 1)).getList();
|
||||
|
||||
//非置顶贴
|
||||
List<Content> contents = Content.dao.findPage(1, 30,Kv.by("top", 0)).getList();
|
||||
List<Content> contents = contentDao.findPage(1, 30, Kv.by("top", 0)).getList();
|
||||
|
||||
//热帖
|
||||
|
||||
//热议
|
||||
List<Content> hotReply = Content.dao.findPage(1, 8, Kv.by("order", "replyNum DESC")).getList();
|
||||
List<Content> hotReply = contentDao.findPage(1, 8, Kv.by("order", "replyNum DESC")).getList();
|
||||
|
||||
//最新加入
|
||||
List<User> lastReg = User.dao.findPage(1, 8, Kv.by("order", "createTime DESC")).getList();
|
||||
List<User> lastReg = userDao.findPage(1, 8, Kv.by("order", "createTime DESC")).getList();
|
||||
|
||||
setAttr("top", top);
|
||||
setAttr("contents", contents);
|
||||
@@ -40,7 +46,7 @@ public class HomeController extends IController {
|
||||
/**
|
||||
* 帖子栏目列表
|
||||
*/
|
||||
public void column(){
|
||||
public void column() {
|
||||
String para = getPara(0, "");
|
||||
int solved = getParaToInt("solved", -1);
|
||||
int wonderful = getParaToInt("wonderful", -1);
|
||||
|
@@ -9,10 +9,7 @@ import com.lxyer.config.E;
|
||||
import com.lxyer.config.JBean;
|
||||
import com.lxyer.model.User;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Created by Lxyer at 2017/9/10 13:55.
|
||||
@@ -21,7 +18,7 @@ public class IController extends Controller {
|
||||
|
||||
public static final Cache cache = Redis.use();
|
||||
|
||||
public void index(){
|
||||
public void index() {
|
||||
String para = getPara(0, "index");
|
||||
|
||||
render(para + ".html");
|
||||
@@ -33,7 +30,7 @@ public class IController extends Controller {
|
||||
return user == null ? null : user.getUserId();
|
||||
}
|
||||
|
||||
public User getUser(){
|
||||
public User getUser() {
|
||||
return getSessionAttr("user");
|
||||
}
|
||||
|
||||
@@ -52,32 +49,36 @@ public class IController extends Controller {
|
||||
return kv;
|
||||
}
|
||||
|
||||
public void renderJBean(Object obj){
|
||||
public void renderJBean(Object obj) {
|
||||
renderJson(new JBean(1, null, obj));
|
||||
}
|
||||
|
||||
public int getPn(){
|
||||
public int getPn() {
|
||||
return getParaToInt("pn", 1);
|
||||
}
|
||||
public int getPs(){
|
||||
|
||||
public int getPs() {
|
||||
return getParaToInt("ps", 15);
|
||||
}
|
||||
public int getPn(int pn){
|
||||
|
||||
public int getPn(int pn) {
|
||||
return getParaToInt("pn", pn);
|
||||
}
|
||||
public int getPs(int ps){
|
||||
|
||||
public int getPs(int ps) {
|
||||
return getParaToInt("ps", ps);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置动态属性
|
||||
*
|
||||
* @param page
|
||||
* @param dynAttr
|
||||
*/
|
||||
public void setDynAttr(Page<Model> page, E.DynamicAttr dynAttr, String ... s){
|
||||
public void setDynAttr(Page<Model> page, E.DynamicAttr dynAttr, String... s) {
|
||||
if (page == null || page.getList().size() == 0 || dynAttr == null) return;
|
||||
List ids = new ArrayList<>();
|
||||
page.getList().forEach(x->ids.add(x.getInt(dynAttr.id_k())));
|
||||
page.getList().forEach(x -> ids.add(x.getInt(dynAttr.id_k())));
|
||||
if (!ids.isEmpty()) {
|
||||
String ids_ = ids.toString();
|
||||
ids_ = ids_.substring(1, ids_.length() - 1);
|
||||
@@ -91,45 +92,46 @@ public class IController extends Controller {
|
||||
List<Record> attrs = Db.find(sqlPara);
|
||||
|
||||
Map<Integer, Kv> attrMap = new HashMap();
|
||||
attrs.forEach(x->{
|
||||
attrs.forEach(x -> {
|
||||
Kv nAttr = attrMap.getOrDefault(x.getInt(dynAttr.gk()), Kv.create());
|
||||
nAttr.set(x.get("attr"), x.get("value"));
|
||||
attrMap.put(x.getInt(dynAttr.gk()), nAttr);
|
||||
});
|
||||
page.getList().forEach(x->{
|
||||
attrMap.getOrDefault(x.getInt(dynAttr.id_k()), Kv.create()).forEach((k, v)->x.put(k+"", v));
|
||||
page.getList().forEach(x -> {
|
||||
attrMap.getOrDefault(x.getInt(dynAttr.id_k()), Kv.create()).forEach((k, v) -> x.put(k + "", v));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置动态属性
|
||||
*
|
||||
* @param model
|
||||
* @param dynAttr
|
||||
*/
|
||||
public void setDynAttr(Model model, E.DynamicAttr dynAttr, String ... ss){
|
||||
public void setDynAttr(Model model, E.DynamicAttr dynAttr, String... ss) {
|
||||
Kv kv = Kv.by("table", dynAttr.table()).set("id_k", dynAttr.gk()).set("id_v", model.getInt(dynAttr.id_k())).set("cate", dynAttr.getCate());
|
||||
if (ss.length > 0) kv.set("attr", arrToStr(ss));
|
||||
|
||||
SqlPara sqlPara = Db.getSqlPara("m.dyn_attr", kv);
|
||||
List<Record> attrs = Db.find(sqlPara);
|
||||
attrs.forEach(x-> model.put(x.get("attr"), x.get("value")));
|
||||
attrs.forEach(x -> model.put(x.get("attr"), x.get("value")));
|
||||
}
|
||||
|
||||
private String arrToStr(String ... ss){
|
||||
private String arrToStr(String... ss) {
|
||||
String str = "";
|
||||
for (String x : ss){
|
||||
str += "'"+x+"',";
|
||||
for (String x : ss) {
|
||||
str += "'" + x + "',";
|
||||
}
|
||||
if (str.length() > 0)
|
||||
str = str.substring(0, str.length()-1);
|
||||
str = str.substring(0, str.length() - 1);
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* todo:文件上传
|
||||
*/
|
||||
public void upFile(){
|
||||
public void upFile() {
|
||||
|
||||
}
|
||||
|
||||
|
@@ -1,7 +1,6 @@
|
||||
package com.lxyer.controller;
|
||||
|
||||
import com.jfinal.aop.Before;
|
||||
import com.jfinal.aop.Clear;
|
||||
import com.jfinal.aop.*;
|
||||
import com.jfinal.kit.Kv;
|
||||
import com.jfinal.plugin.activerecord.Page;
|
||||
import com.lxyer.config.JBean;
|
||||
@@ -16,16 +15,16 @@ import java.util.List;
|
||||
* Created by JUECHENG at 2018/1/7 16:48.
|
||||
*/
|
||||
@Before(LoginInterceptor.class)
|
||||
public class JieController extends IController{
|
||||
public class JieController extends IController {
|
||||
|
||||
private ContentService service = ContentService.me;
|
||||
private int userId;
|
||||
@Inject
|
||||
private ContentService service;
|
||||
|
||||
/**
|
||||
* 帖子详情
|
||||
*/
|
||||
@Clear(LoginInterceptor.class)
|
||||
public void index(){
|
||||
public void index() {
|
||||
int contentId = getParaToInt(0);
|
||||
|
||||
Content content = Content.dao.findFirst(Kv.by("contentId", contentId));
|
||||
@@ -48,7 +47,7 @@ public class JieController extends IController{
|
||||
/**
|
||||
* 添加/修改帖子
|
||||
*/
|
||||
public void add(){
|
||||
public void add() {
|
||||
setAttr("bean", Content.dao.findById(getParaToInt()));
|
||||
|
||||
render("add.html");
|
||||
@@ -68,7 +67,7 @@ public class JieController extends IController{
|
||||
/**
|
||||
* 帖子删除
|
||||
*/
|
||||
public void del(){
|
||||
public void del() {
|
||||
JBean bean = new JBean(1);
|
||||
try {
|
||||
service.del(getParaToInt("contentId"), getUserId());
|
||||
@@ -82,7 +81,7 @@ public class JieController extends IController{
|
||||
/**
|
||||
* 帖子收藏
|
||||
*/
|
||||
public void collect(){
|
||||
public void collect() {
|
||||
JBean bean = new JBean(1);
|
||||
|
||||
Integer contentId = getParaToInt("contentId");
|
||||
@@ -100,7 +99,7 @@ public class JieController extends IController{
|
||||
/**
|
||||
* 帖子加精/置顶
|
||||
*/
|
||||
public void set(){
|
||||
public void set() {
|
||||
JBean bean = new JBean(1);
|
||||
|
||||
Integer contentId = getParaToInt("id");
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package com.lxyer.controller;
|
||||
|
||||
import com.jfinal.aop.Inject;
|
||||
import com.lxyer.config.JBean;
|
||||
import com.lxyer.model.User;
|
||||
import com.lxyer.service.UserService;
|
||||
@@ -9,12 +10,13 @@ import com.lxyer.service.UserService;
|
||||
*/
|
||||
public class UserController extends IController {
|
||||
|
||||
private UserService userService = UserService.me;
|
||||
@Inject
|
||||
private UserService userService;
|
||||
|
||||
/**
|
||||
* 注册
|
||||
*/
|
||||
public void create(){
|
||||
public void create() {
|
||||
JBean bean = new JBean(1);
|
||||
String email = getPara("email");
|
||||
String pwd = getPara("pwd");
|
||||
@@ -32,12 +34,12 @@ public class UserController extends IController {
|
||||
/**
|
||||
* 登录
|
||||
*/
|
||||
public void login(){
|
||||
public void login() {
|
||||
String para = getPara();
|
||||
if (para == null) {
|
||||
render("login.html");
|
||||
return;
|
||||
}else if ("out".equals(para)){
|
||||
} else if ("out".equals(para)) {
|
||||
removeSessionAttr("user");
|
||||
renderJson(JBean.success);
|
||||
return;
|
||||
@@ -65,14 +67,14 @@ public class UserController extends IController {
|
||||
/**
|
||||
* todo:用户修改资料
|
||||
*/
|
||||
public void update(){
|
||||
public void update() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改密码
|
||||
*/
|
||||
public void repwd(){
|
||||
public void repwd() {
|
||||
JBean bean = new JBean(1);
|
||||
String pwd = getPara("pwd");
|
||||
|
||||
|
Reference in New Issue
Block a user