This commit is contained in:
lxyer 2019-06-17 23:41:47 +08:00
parent e1f3052174
commit 42bbbac170
33 changed files with 608 additions and 618 deletions

View File

@ -19,16 +19,16 @@ import java.io.File;
*/ */
public class DbMap { public class DbMap {
public static void mapping(ActiveRecordPlugin arp) { public static void mapping(ActiveRecordPlugin arp) {
arp.addMapping("act_log", "logid", ActLog.class); arp.addMapping("act_log", "logid", ActLog.class);
arp.addMapping("comment", "commentId", Comment.class); arp.addMapping("comment", "commentId", Comment.class);
arp.addMapping("content", "contentId", Content.class); arp.addMapping("content", "contentId", Content.class);
arp.addMapping("content_item", "itemId", ContentItem.class); arp.addMapping("content_item", "itemId", ContentItem.class);
// Composite Primary Key order: tid,cate,attr // Composite Primary Key order: tid,cate,attr
arp.addMapping("dyna_attr", "tid,cate,attr", DynaAttr.class); arp.addMapping("dyna_attr", "tid,cate,attr", DynaAttr.class);
arp.addMapping("user", "userId", User.class); arp.addMapping("user", "userId", User.class);
arp.addMapping("user_pwd", "userId", UserPwd.class); arp.addMapping("user_pwd", "userId", UserPwd.class);
} }
public static void addSqlTemplate(ActiveRecordPlugin arp) { public static void addSqlTemplate(ActiveRecordPlugin arp) {
String baseSqlTemplatePath = PathKit.getRootClassPath() + "/sql/"; String baseSqlTemplatePath = PathKit.getRootClassPath() + "/sql/";
@ -36,8 +36,8 @@ public class DbMap {
File sqlFiles = new File(baseSqlTemplatePath); File sqlFiles = new File(baseSqlTemplatePath);
File[] files = sqlFiles.listFiles(); File[] files = sqlFiles.listFiles();
for (File f : files){ for (File f : files) {
if (f.isFile() || f.getName().endsWith(".sql")){ if (f.isFile() || f.getName().endsWith(".sql")) {
arp.addSqlTemplate(f.getName()); arp.addSqlTemplate(f.getName());
} }
} }

View File

@ -8,27 +8,31 @@ public class E {
public enum DynamicAttr { public enum DynamicAttr {
//table,id_k,gk, cate //table,id_k,gk, cate
NEWS("dyna_attr", "contentId", "tid", 1), NEWS("dyna_attr", "contentId", "tid", 1),
USER("dyna_attr", "userId", "tid", 3) USER("dyna_attr", "userId", "tid", 3);
;
private String table; private String table;
private String id_k; private String id_k;
private String gk; private String gk;
private int cate; private int cate;
DynamicAttr(String table, String id_k, String gk, int cate) { DynamicAttr(String table, String id_k, String gk, int cate) {
this.table = table; this.table = table;
this.id_k = id_k; this.id_k = id_k;
this.gk = gk; this.gk = gk;
this.cate = cate; this.cate = cate;
} }
public String table(){
public String table() {
return this.table; return this.table;
} }
public String id_k(){
public String id_k() {
return this.id_k; return this.id_k;
} }
public String gk(){
public String gk() {
return this.gk; return this.gk;
} }
public int getCate() { public int getCate() {
return cate; return cate;
} }

View File

@ -24,6 +24,7 @@ public class FlyConfig extends JFinalConfig {
@Override @Override
public void configConstant(Constants me) { public void configConstant(Constants me) {
me.setDevMode(true); me.setDevMode(true);
me.setInjectDependency(true);
PropKit.use("config.properties"); PropKit.use("config.properties");
} }
@ -54,8 +55,9 @@ public class FlyConfig extends JFinalConfig {
DbMap.mapping(arp); DbMap.mapping(arp);
DbMap.addSqlTemplate(arp); DbMap.addSqlTemplate(arp);
me.add(new RedisPlugin(getProperty("redis.cache_name"), getProperty("redis.host"), getPropertyToInt("redis.port"), getPropertyToInt("redis.timeout"), getProperty("redis.password"))); //redis 配置
me.add(new EhCachePlugin()); //me.add(new RedisPlugin(getProperty("redis.cache_name"), getProperty("redis.host"), getPropertyToInt("redis.port"), getPropertyToInt("redis.timeout"), getProperty("redis.password")));
//me.add(new EhCachePlugin());
} }
@Override @Override

View File

@ -14,7 +14,7 @@ public class JBean {
public static final JBean success = new JBean(1, "操作成功"); public static final JBean success = new JBean(1, "操作成功");
public static final JBean error = new JBean(-1, "操作失败"); public static final JBean error = new JBean(-1, "操作失败");
public JBean(int code){ public JBean(int code) {
this.code = code; this.code = code;
if (code == 1) if (code == 1)
this.msg = "操作成功"; this.msg = "操作成功";
@ -24,11 +24,12 @@ public class JBean {
this.msg = "未登录,请前往登录"; this.msg = "未登录,请前往登录";
} }
public JBean(int code, String msg){ public JBean(int code, String msg) {
this.code = code; this.code = code;
this.msg = msg; this.msg = msg;
} }
public JBean(int code, String msg, Object obj){
public JBean(int code, String msg, Object obj) {
this.code = code; this.code = code;
this.msg = msg; this.msg = msg;
this.obj = obj; this.obj = obj;
@ -61,6 +62,7 @@ public class JBean {
this.msg = msg; this.msg = msg;
return this; return this;
} }
public JBean setCode(int code, String msg, Object obj) { public JBean setCode(int code, String msg, Object obj) {
this.code = code; this.code = code;
this.msg = msg; this.msg = msg;
@ -76,8 +78,9 @@ public class JBean {
this.obj = obj; this.obj = obj;
return this; return this;
} }
public <K, V> JBean set(Object k, Object v){
if (!(obj instanceof Map)){ public <K, V> JBean set(Object k, Object v) {
if (!(obj instanceof Map)) {
obj = new HashMap(); obj = new HashMap();
} }
((Map) obj).put(k, v); ((Map) obj).put(k, v);
@ -89,23 +92,27 @@ public class JBean {
下面的是一些快速创建JsonBean的方式 下面的是一些快速创建JsonBean的方式
使用中可以使用new 同时也可以直接使用 使用中可以使用new 同时也可以直接使用
*/ */
public static JBean success(Object obj){ public static JBean success(Object obj) {
return new JBean(1, "操作成功",obj); return new JBean(1, "操作成功", obj);
} }
public static JBean success(int code, String msg){
public static JBean success(int code, String msg) {
return new JBean(1, msg); return new JBean(1, msg);
} }
public static JBean success(int code, String msg, Object obj){
public static JBean success(int code, String msg, Object obj) {
return new JBean(1, msg, obj); return new JBean(1, msg, obj);
} }
public static JBean error(int code, String msg){ public static JBean error(int code, String msg) {
return new JBean(code, msg); return new JBean(code, msg);
} }
public static JBean error(int code, String msg, Object obj){
public static JBean error(int code, String msg, Object obj) {
return new JBean(code, msg, obj); return new JBean(code, msg, obj);
} }
public static JBean error(String msg){
public static JBean error(String msg) {
return new JBean(-1, msg); return new JBean(-1, msg);
} }

View File

@ -11,7 +11,7 @@ import java.text.SimpleDateFormat;
*/ */
public final class LxyKit { public final class LxyKit {
public static String dateFmt(long time){ public static String dateFmt(long time) {
/** /**
* 刚刚 60秒内 60 * 1000 * 刚刚 60秒内 60 * 1000
* x分钟前 1小时候内 60 * 60*1000 * x分钟前 1小时候内 60 * 60*1000
@ -24,18 +24,18 @@ public final class LxyKit {
long diff = now - time; long diff = now - time;
if (diff < 60 * 1000) if (diff < 60 * 1000)
return "刚刚"; return "刚刚";
else if (diff < 60 * 60 *1000) else if (diff < 60 * 60 * 1000)
return Math.floorDiv(diff, 60 *1000) + "分钟前"; return Math.floorDiv(diff, 60 * 1000) + "分钟前";
else if (diff < 24 * 60*60*1000) else if (diff < 24 * 60 * 60 * 1000)
return Math.floorDiv(diff, 60 *60*1000) + "小时前"; return Math.floorDiv(diff, 60 * 60 * 1000) + "小时前";
else if (diff > 24 * 60*60*1000 && diff < 7 * 24*60*60*1000) else if (diff > 24 * 60 * 60 * 1000 && diff < 7 * 24 * 60 * 60 * 1000)
return Math.floorDiv(diff, 24 * 60*60*1000) + "天前"; return Math.floorDiv(diff, 24 * 60 * 60 * 1000) + "天前";
else else
return new SimpleDateFormat("yyyy-MM-dd").format(time); return new SimpleDateFormat("yyyy-MM-dd").format(time);
} }
public static String md5IfNeed(String password){ public static String md5IfNeed(String password) {
if (password == null || password.isEmpty()) return ""; if (password == null || password.isEmpty()) return "";
if (password.length() == 32) return password; if (password.length() == 32) return password;
MessageDigest md5 = null; MessageDigest md5 = null;

View File

@ -1,26 +0,0 @@
package com.lxyer.config;
/**
* Created by JUECHENG at 2018/1/7 23:45.
*/
public class MyException extends RuntimeException {
public MyException() {
super();
}
public MyException(String message) {
super(message);
}
public MyException(String message, Throwable cause) {
super(message, cause);
}
public MyException(Throwable cause) {
super(cause);
}
protected MyException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}

View File

@ -21,14 +21,14 @@ public class LoginInterceptor implements Interceptor {
HttpServletResponse response = controller.getResponse(); HttpServletResponse response = controller.getResponse();
User user = controller.getSessionAttr("user"); User user = controller.getSessionAttr("user");
if (user == null){ if (user == null) {
if ("XMLHttpRequest".equals(request.getHeader("X-Requested-With"))){ if ("XMLHttpRequest".equals(request.getHeader("X-Requested-With"))) {
controller.renderJson(new JBean(-1,"请登录后再尝试")); controller.renderJson(new JBean(-1, "请登录后再尝试"));
return; return;
}else { } else {
controller.redirect("/user/login"); controller.redirect("/user/login");
} }
}else { } else {
inv.invoke(); inv.invoke();
} }
} }

View File

@ -1,10 +1,7 @@
package com.lxyer.config.route; package com.lxyer.config.route;
import com.jfinal.config.Routes; import com.jfinal.config.Routes;
import com.lxyer.controller.CommentController; import com.lxyer.controller.*;
import com.lxyer.controller.HomeController;
import com.lxyer.controller.JieController;
import com.lxyer.controller.UserController;
/** /**
* Created by JUECHENG at 2018/1/7 11:16. * Created by JUECHENG at 2018/1/7 11:16.

View File

@ -1,7 +1,6 @@
package com.lxyer.controller; package com.lxyer.controller;
import com.jfinal.aop.Before; import com.jfinal.aop.*;
import com.jfinal.aop.Clear;
import com.jfinal.kit.Kv; import com.jfinal.kit.Kv;
import com.jfinal.plugin.activerecord.Page; import com.jfinal.plugin.activerecord.Page;
import com.lxyer.config.JBean; import com.lxyer.config.JBean;
@ -15,12 +14,14 @@ import com.lxyer.service.CommentService;
@Before(LoginInterceptor.class) @Before(LoginInterceptor.class)
public class CommentController extends IController { public class CommentController extends IController {
CommentService service = CommentService.me; @Inject
CommentService service;
/** /**
* 评论列表 * 评论列表
*/ */
@Clear(LoginInterceptor.class) @Clear(LoginInterceptor.class)
public void list(){ public void list() {
Kv kv = getParams("contentId"); Kv kv = getParams("contentId");
Page<Comment> page = Comment.dao.findPage(getPn(), getPs(), kv); Page<Comment> page = Comment.dao.findPage(getPn(), getPs(), kv);
@ -31,7 +32,7 @@ public class CommentController extends IController {
* 评论详情 * 评论详情
*/ */
@Clear(LoginInterceptor.class) @Clear(LoginInterceptor.class)
public void info(){ public void info() {
} }
@ -39,7 +40,7 @@ public class CommentController extends IController {
* 评论保存 * 评论保存
*/ */
@Before(LoginInterceptor.class) @Before(LoginInterceptor.class)
public void save(){ public void save() {
Comment comment = getModel(Comment.class); Comment comment = getModel(Comment.class);
service.save(comment, getUserId()); 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); JBean bean = new JBean(1);
Integer commentId = getParaToInt("commentId"); Integer commentId = getParaToInt("commentId");
Integer ok = getParaToInt("ok"); Integer ok = getParaToInt("ok");

View File

@ -4,6 +4,6 @@ package com.lxyer.controller;
* 文件管理 * 文件管理
* Created by JUECHENG at 2018/1/7 16:44. * Created by JUECHENG at 2018/1/7 16:44.
*/ */
public class FileController extends IController{ public class FileController extends IController {
} }

View File

@ -1,5 +1,6 @@
package com.lxyer.controller; package com.lxyer.controller;
import com.jfinal.aop.Inject;
import com.jfinal.kit.Kv; import com.jfinal.kit.Kv;
import com.jfinal.plugin.activerecord.Page; import com.jfinal.plugin.activerecord.Page;
import com.lxyer.model.Content; import com.lxyer.model.Content;
@ -13,21 +14,26 @@ import java.util.List;
public class HomeController extends IController { 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 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("top", top);
setAttr("contents", contents); setAttr("contents", contents);
@ -40,7 +46,7 @@ public class HomeController extends IController {
/** /**
* 帖子栏目列表 * 帖子栏目列表
*/ */
public void column(){ public void column() {
String para = getPara(0, ""); String para = getPara(0, "");
int solved = getParaToInt("solved", -1); int solved = getParaToInt("solved", -1);
int wonderful = getParaToInt("wonderful", -1); int wonderful = getParaToInt("wonderful", -1);

View File

@ -9,10 +9,7 @@ import com.lxyer.config.E;
import com.lxyer.config.JBean; import com.lxyer.config.JBean;
import com.lxyer.model.User; import com.lxyer.model.User;
import java.util.ArrayList; import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/** /**
* Created by Lxyer at 2017/9/10 13:55. * 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 static final Cache cache = Redis.use();
public void index(){ public void index() {
String para = getPara(0, "index"); String para = getPara(0, "index");
render(para + ".html"); render(para + ".html");
@ -33,7 +30,7 @@ public class IController extends Controller {
return user == null ? null : user.getUserId(); return user == null ? null : user.getUserId();
} }
public User getUser(){ public User getUser() {
return getSessionAttr("user"); return getSessionAttr("user");
} }
@ -52,32 +49,36 @@ public class IController extends Controller {
return kv; return kv;
} }
public void renderJBean(Object obj){ public void renderJBean(Object obj) {
renderJson(new JBean(1, null, obj)); renderJson(new JBean(1, null, obj));
} }
public int getPn(){ public int getPn() {
return getParaToInt("pn", 1); return getParaToInt("pn", 1);
} }
public int getPs(){
public int getPs() {
return getParaToInt("ps", 15); return getParaToInt("ps", 15);
} }
public int getPn(int pn){
public int getPn(int pn) {
return getParaToInt("pn", pn); return getParaToInt("pn", pn);
} }
public int getPs(int ps){
public int getPs(int ps) {
return getParaToInt("ps", ps); return getParaToInt("ps", ps);
} }
/** /**
* 设置动态属性 * 设置动态属性
*
* @param page * @param page
* @param dynAttr * @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; if (page == null || page.getList().size() == 0 || dynAttr == null) return;
List ids = new ArrayList<>(); 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()) { if (!ids.isEmpty()) {
String ids_ = ids.toString(); String ids_ = ids.toString();
ids_ = ids_.substring(1, ids_.length() - 1); ids_ = ids_.substring(1, ids_.length() - 1);
@ -91,45 +92,46 @@ public class IController extends Controller {
List<Record> attrs = Db.find(sqlPara); List<Record> attrs = Db.find(sqlPara);
Map<Integer, Kv> attrMap = new HashMap(); Map<Integer, Kv> attrMap = new HashMap();
attrs.forEach(x->{ attrs.forEach(x -> {
Kv nAttr = attrMap.getOrDefault(x.getInt(dynAttr.gk()), Kv.create()); Kv nAttr = attrMap.getOrDefault(x.getInt(dynAttr.gk()), Kv.create());
nAttr.set(x.get("attr"), x.get("value")); nAttr.set(x.get("attr"), x.get("value"));
attrMap.put(x.getInt(dynAttr.gk()), nAttr); attrMap.put(x.getInt(dynAttr.gk()), nAttr);
}); });
page.getList().forEach(x->{ page.getList().forEach(x -> {
attrMap.getOrDefault(x.getInt(dynAttr.id_k()), Kv.create()).forEach((k, v)->x.put(k+"", v)); attrMap.getOrDefault(x.getInt(dynAttr.id_k()), Kv.create()).forEach((k, v) -> x.put(k + "", v));
}); });
} }
} }
/** /**
* 设置动态属性 * 设置动态属性
*
* @param model * @param model
* @param dynAttr * @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()); 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)); if (ss.length > 0) kv.set("attr", arrToStr(ss));
SqlPara sqlPara = Db.getSqlPara("m.dyn_attr", kv); SqlPara sqlPara = Db.getSqlPara("m.dyn_attr", kv);
List<Record> attrs = Db.find(sqlPara); 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 = ""; String str = "";
for (String x : ss){ for (String x : ss) {
str += "'"+x+"',"; str += "'" + x + "',";
} }
if (str.length() > 0) if (str.length() > 0)
str = str.substring(0, str.length()-1); str = str.substring(0, str.length() - 1);
return str; return str;
} }
/** /**
* todo:文件上传 * todo:文件上传
*/ */
public void upFile(){ public void upFile() {
} }

View File

@ -1,7 +1,6 @@
package com.lxyer.controller; package com.lxyer.controller;
import com.jfinal.aop.Before; import com.jfinal.aop.*;
import com.jfinal.aop.Clear;
import com.jfinal.kit.Kv; import com.jfinal.kit.Kv;
import com.jfinal.plugin.activerecord.Page; import com.jfinal.plugin.activerecord.Page;
import com.lxyer.config.JBean; import com.lxyer.config.JBean;
@ -16,16 +15,16 @@ import java.util.List;
* Created by JUECHENG at 2018/1/7 16:48. * Created by JUECHENG at 2018/1/7 16:48.
*/ */
@Before(LoginInterceptor.class) @Before(LoginInterceptor.class)
public class JieController extends IController{ public class JieController extends IController {
private ContentService service = ContentService.me; @Inject
private int userId; private ContentService service;
/** /**
* 帖子详情 * 帖子详情
*/ */
@Clear(LoginInterceptor.class) @Clear(LoginInterceptor.class)
public void index(){ public void index() {
int contentId = getParaToInt(0); int contentId = getParaToInt(0);
Content content = Content.dao.findFirst(Kv.by("contentId", contentId)); 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())); setAttr("bean", Content.dao.findById(getParaToInt()));
render("add.html"); render("add.html");
@ -68,7 +67,7 @@ public class JieController extends IController{
/** /**
* 帖子删除 * 帖子删除
*/ */
public void del(){ public void del() {
JBean bean = new JBean(1); JBean bean = new JBean(1);
try { try {
service.del(getParaToInt("contentId"), getUserId()); 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); JBean bean = new JBean(1);
Integer contentId = getParaToInt("contentId"); Integer contentId = getParaToInt("contentId");
@ -100,7 +99,7 @@ public class JieController extends IController{
/** /**
* 帖子加精/置顶 * 帖子加精/置顶
*/ */
public void set(){ public void set() {
JBean bean = new JBean(1); JBean bean = new JBean(1);
Integer contentId = getParaToInt("id"); Integer contentId = getParaToInt("id");

View File

@ -1,5 +1,6 @@
package com.lxyer.controller; package com.lxyer.controller;
import com.jfinal.aop.Inject;
import com.lxyer.config.JBean; import com.lxyer.config.JBean;
import com.lxyer.model.User; import com.lxyer.model.User;
import com.lxyer.service.UserService; import com.lxyer.service.UserService;
@ -9,12 +10,13 @@ import com.lxyer.service.UserService;
*/ */
public class UserController extends IController { 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); JBean bean = new JBean(1);
String email = getPara("email"); String email = getPara("email");
String pwd = getPara("pwd"); String pwd = getPara("pwd");
@ -32,12 +34,12 @@ public class UserController extends IController {
/** /**
* 登录 * 登录
*/ */
public void login(){ public void login() {
String para = getPara(); String para = getPara();
if (para == null) { if (para == null) {
render("login.html"); render("login.html");
return; return;
}else if ("out".equals(para)){ } else if ("out".equals(para)) {
removeSessionAttr("user"); removeSessionAttr("user");
renderJson(JBean.success); renderJson(JBean.success);
return; return;
@ -65,14 +67,14 @@ public class UserController extends IController {
/** /**
* todo:用户修改资料 * todo:用户修改资料
*/ */
public void update(){ public void update() {
} }
/** /**
* 修改密码 * 修改密码
*/ */
public void repwd(){ public void repwd() {
JBean bean = new JBean(1); JBean bean = new JBean(1);
String pwd = getPara("pwd"); String pwd = getPara("pwd");

View File

@ -7,25 +7,25 @@ import com.lxyer.model.base.BaseComment;
/** /**
* Generated by JFinal. * Generated by JFinal.
*/ */
@SuppressWarnings("serial")
public class Comment extends BaseComment<Comment> { public class Comment extends BaseComment<Comment> {
public static final Comment dao = new Comment().dao(); public static final Comment dao = new Comment().dao();
@Override @Override
public String sqlSpace() { public String sqlSpace() {
return "comment"; return "comment";
} }
@Override @Override
public Comment getDao() { public Comment getDao() {
return dao; return dao;
} }
/** /**
* 更新点赞数 * 更新点赞数
* @param commentId *
*/ * @param commentId
public static void upSupportNum(Integer commentId) { */
Db.update(Db.getSqlPara("comment.upSupportNum", Kv.by("commentId", commentId))); public static void upSupportNum(Integer commentId) {
} Db.update(Db.getSqlPara("comment.upSupportNum", Kv.by("commentId", commentId)));
}
} }

View File

@ -7,7 +7,6 @@ import com.lxyer.model.base.BaseContent;
/** /**
* Generated by JFinal. * Generated by JFinal.
*/ */
@SuppressWarnings("serial")
public class Content extends BaseContent<Content> { public class Content extends BaseContent<Content> {
public static final Content dao = new Content().dao(); public static final Content dao = new Content().dao();
@ -21,7 +20,7 @@ public class Content extends BaseContent<Content> {
return dao; return dao;
} }
public static void upReplyNum(int contentId){ public static void upReplyNum(int contentId) {
Db.update(Db.getSqlPara("content.upReplyNum", Kv.by("contentId", contentId))); Db.update(Db.getSqlPara("content.upReplyNum", Kv.by("contentId", contentId)));
} }
} }

View File

@ -5,7 +5,6 @@ import com.lxyer.model.base.BaseContentItem;
/** /**
* Generated by JFinal. * Generated by JFinal.
*/ */
@SuppressWarnings("serial")
public class ContentItem extends BaseContentItem<ContentItem> { public class ContentItem extends BaseContentItem<ContentItem> {
} }

View File

@ -5,7 +5,6 @@ import com.lxyer.model.base.BaseDynaAttr;
/** /**
* Generated by JFinal. * Generated by JFinal.
*/ */
@SuppressWarnings("serial")
public class DynaAttr extends BaseDynaAttr<DynaAttr> { public class DynaAttr extends BaseDynaAttr<DynaAttr> {
} }

View File

@ -5,7 +5,6 @@ import com.lxyer.model.base.BaseUser;
/** /**
* Generated by JFinal. * Generated by JFinal.
*/ */
@SuppressWarnings("serial")
public class User extends BaseUser<User> { public class User extends BaseUser<User> {
public static final User dao = new User().dao(); public static final User dao = new User().dao();

View File

@ -6,7 +6,6 @@ import com.lxyer.model.base.BaseUserPwd;
/** /**
* Generated by JFinal. * Generated by JFinal.
*/ */
@SuppressWarnings("serial")
public class UserPwd extends BaseUserPwd<UserPwd> { public class UserPwd extends BaseUserPwd<UserPwd> {
public static final UserPwd dao = new UserPwd().dao(); public static final UserPwd dao = new UserPwd().dao();
@ -16,7 +15,7 @@ public class UserPwd extends BaseUserPwd<UserPwd> {
setPwd(LxyKit.md5IfNeed(getPwd())); setPwd(LxyKit.md5IfNeed(getPwd()));
if (findById(getUserId()) == null) { if (findById(getUserId()) == null) {
return super.save(); return super.save();
}else { } else {
return super.update(); return super.update();
} }
} }

View File

@ -1,12 +1,12 @@
/** /**
* 请勿将俱乐部专享资源复制给其他人保护知识产权即是保护我们所在的行业进而保护我们自己的利益 * 请勿将俱乐部专享资源复制给其他人保护知识产权即是保护我们所在的行业进而保护我们自己的利益
* 即便是公司的同事也请尊重 JFinal 作者的努力与付出不要复制给同事 * 即便是公司的同事也请尊重 JFinal 作者的努力与付出不要复制给同事
* * <p>
* 如果你尚未加入俱乐部请立即删除该项目或者现在加入俱乐部http://jfinal.com/club * 如果你尚未加入俱乐部请立即删除该项目或者现在加入俱乐部http://jfinal.com/club
* * <p>
* 俱乐部将提供 jfinal-club 项目文档与设计资源专用 QQ 以及作者在俱乐部定期的分享与答疑 * 俱乐部将提供 jfinal-club 项目文档与设计资源专用 QQ 以及作者在俱乐部定期的分享与答疑
* 价值远比仅仅拥有 jfinal club 项目源代码要大得多 * 价值远比仅仅拥有 jfinal club 项目源代码要大得多
* * <p>
* JFinal 俱乐部是五年以来首次寻求外部资源的尝试以便于有资源创建更加 * JFinal 俱乐部是五年以来首次寻求外部资源的尝试以便于有资源创建更加
* 高品质的产品与服务为大家带来更大的价值所以请大家多多支持不要将 * 高品质的产品与服务为大家带来更大的价值所以请大家多多支持不要将
* 首次的尝试扼杀在了摇篮之中 * 首次的尝试扼杀在了摇篮之中
@ -25,62 +25,61 @@ import javax.sql.DataSource;
/** /**
* ModelBaseModel_MappingKit 生成器 * ModelBaseModel_MappingKit 生成器
*/ */
@SuppressWarnings("ALL")
public class _Generator { public class _Generator {
/** /**
* 部分功能使用 Db + Record 模式实现无需生成 model table 在此配置 * 部分功能使用 Db + Record 模式实现无需生成 model table 在此配置
*/ */
private static String[] excludedTable = { private static String[] excludedTable = {
"comment", "comment",
"content", "content",
"content_item", "content_item",
"dyna_attr", "dyna_attr",
"act_log", "act_log",
"user", "user",
"user_pwd" "user_pwd"
}; };
/** /**
* 重用 JFinalClubConfig 中的数据源配置避免冗余配置 * 重用 JFinalClubConfig 中的数据源配置避免冗余配置
*/ */
public static DataSource getDataSource() { public static DataSource getDataSource() {
//HikariCpPlugin hikariCpPlugin = new HikariCpPlugin("jdbc:mysql://558cfc37a10ef.sh.cdb.myqcloud.com:3817/db_toutiao?nullNamePatternMatchesAll=true", "cdb_outerroot", "l237809796", "com.mysql.cj.jdbc.Driver"); //HikariCpPlugin hikariCpPlugin = new HikariCpPlugin("jdbc:mysql://558cfc37a10ef.sh.cdb.myqcloud.com:3817/db_toutiao?nullNamePatternMatchesAll=true", "cdb_outerroot", "l237809796", "com.mysql.cj.jdbc.Driver");
HikariCpPlugin hikariCpPlugin = new HikariCpPlugin("jdbc:mysql://dbserver:3306/jfly?nullNamePatternMatchesAll=true", "guest", "hello", "com.mysql.cj.jdbc.Driver"); HikariCpPlugin hikariCpPlugin = new HikariCpPlugin("jdbc:mysql://dbserver:3306/jfly?nullNamePatternMatchesAll=true", "guest", "hello", "com.mysql.cj.jdbc.Driver");
hikariCpPlugin.start(); hikariCpPlugin.start();
return hikariCpPlugin.getDataSource(); return hikariCpPlugin.getDataSource();
} }
public static void main(String[] args) { public static void main(String[] args) {
// base model 所使用的包名 // base model 所使用的包名
String baseModelPackageName = "com.lxyer.model.base"; String baseModelPackageName = "com.lxyer.model.base";
// base model 文件保存路径 // base model 文件保存路径
String baseModelOutputDir = PathKit.getWebRootPath() String baseModelOutputDir = PathKit.getWebRootPath()
+ "/src/main/java/com/lxyer/model/dev/base"; + "/src/main/java/com/lxyer/model/dev/base";
System.out.println("输出路径:"+ baseModelOutputDir); System.out.println("输出路径:" + baseModelOutputDir);
// model 所使用的包名 (MappingKit 默认使用的包名) // model 所使用的包名 (MappingKit 默认使用的包名)
String modelPackageName = "com.lxyer.dev"; String modelPackageName = "com.lxyer.dev";
// model 文件保存路径 (MappingKit DataDictionary 文件默认保存路径) // model 文件保存路径 (MappingKit DataDictionary 文件默认保存路径)
String modelOutputDir = baseModelOutputDir + "/.."; String modelOutputDir = baseModelOutputDir + "/..";
// 创建生成器 // 创建生成器
Generator gen = new Generator(getDataSource(), baseModelPackageName, baseModelOutputDir, modelPackageName, modelOutputDir); Generator gen = new Generator(getDataSource(), baseModelPackageName, baseModelOutputDir, modelPackageName, modelOutputDir);
// 设置数据库方言 // 设置数据库方言
gen.setDialect(new MysqlDialect()); gen.setDialect(new MysqlDialect());
// 添加不需要生成的表名 // 添加不需要生成的表名
for (String table : excludedTable) { for (String table : excludedTable) {
gen.addExcludedTable(table); gen.addExcludedTable(table);
} }
// 设置是否在 Model 中生成 getDao 对象 // 设置是否在 Model 中生成 getDao 对象
gen.setGenerateDaoInModel(false); gen.setGenerateDaoInModel(false);
// 设置是否生成字典文件 // 设置是否生成字典文件
gen.setGenerateDataDictionary(false); gen.setGenerateDataDictionary(false);
gen.setMappingKitClassName("DbMap"); gen.setMappingKitClassName("DbMap");
// 设置需要被移除的表名前缀用于生成modelName例如表名 "osc_user"移除前缀 "osc_"后生成的model名为 "User"而非 OscUser // 设置需要被移除的表名前缀用于生成modelName例如表名 "osc_user"移除前缀 "osc_"后生成的model名为 "User"而非 OscUser
// gernerator.setRemovedTableNamePrefixes("t_"); // gernerator.setRemovedTableNamePrefixes("t_");
// 生成 // 生成
gen.generate(); gen.generate();
} }
} }

View File

@ -1,68 +1,68 @@
package com.lxyer.model.base; package com.lxyer.model.base;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.IBean; import com.jfinal.plugin.activerecord.IBean;
import com.jfinal.plugin.activerecord.Model;
/** /**
* Generated by JFinal, do not modify this file. * Generated by JFinal, do not modify this file.
*/ */
@SuppressWarnings("serial") @SuppressWarnings("serial")
public abstract class BaseActLog<M extends BaseActLog<M>> extends Model<M> implements IBean,IModel<M> { public abstract class BaseActLog<M extends BaseActLog<M>> extends Model<M> implements IBean, IModel<M> {
public void setLogid(java.lang.Integer logid) { public void setLogid(java.lang.Integer logid) {
set("logid", logid); set("logid", logid);
} }
public java.lang.Integer getLogid() { public java.lang.Integer getLogid() {
return getInt("logid"); return getInt("logid");
} }
public void setCate(java.lang.Integer cate) { public void setCate(java.lang.Integer cate) {
set("cate", cate); set("cate", cate);
} }
public java.lang.Integer getCate() { public java.lang.Integer getCate() {
return getInt("cate"); return getInt("cate");
} }
public void setTid(java.lang.Integer tid) { public void setTid(java.lang.Integer tid) {
set("tid", tid); set("tid", tid);
} }
public java.lang.Integer getTid() { public java.lang.Integer getTid() {
return getInt("tid"); return getInt("tid");
} }
public void setUserId(java.lang.Integer userId) { public void setUserId(java.lang.Integer userId) {
set("userId", userId); set("userId", userId);
} }
public java.lang.Integer getUserId() { public java.lang.Integer getUserId() {
return getInt("userId"); return getInt("userId");
} }
public void setCreateTime(java.lang.Long createTime) { public void setCreateTime(java.lang.Long createTime) {
set("createTime", createTime); set("createTime", createTime);
} }
public java.lang.Long getCreateTime() { public java.lang.Long getCreateTime() {
return getLong("createTime"); return getLong("createTime");
} }
public void setRemark(java.lang.String remark) { public void setRemark(java.lang.String remark) {
set("remark", remark); set("remark", remark);
} }
public java.lang.String getRemark() { public java.lang.String getRemark() {
return getStr("remark"); return getStr("remark");
} }
public void setStatus(java.lang.Integer status) { public void setStatus(java.lang.Integer status) {
set("status", status); set("status", status);
} }
public java.lang.Integer getStatus() { public java.lang.Integer getStatus() {
return getInt("status"); return getInt("status");
} }
} }

View File

@ -1,84 +1,84 @@
package com.lxyer.model.base; package com.lxyer.model.base;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.IBean; import com.jfinal.plugin.activerecord.IBean;
import com.jfinal.plugin.activerecord.Model;
/** /**
* Generated by JFinal, do not modify this file. * Generated by JFinal, do not modify this file.
*/ */
@SuppressWarnings("serial") @SuppressWarnings("serial")
public abstract class BaseComment<M extends BaseComment<M>> extends Model<M> implements IBean,IModel<M> { public abstract class BaseComment<M extends BaseComment<M>> extends Model<M> implements IBean, IModel<M> {
public void setCommentId(java.lang.Integer commentId) { public void setCommentId(java.lang.Integer commentId) {
set("commentId", commentId); set("commentId", commentId);
} }
public java.lang.Integer getCommentId() { public java.lang.Integer getCommentId() {
return getInt("commentId"); return getInt("commentId");
} }
public void setUserId(java.lang.Integer userId) { public void setUserId(java.lang.Integer userId) {
set("userId", userId); set("userId", userId);
} }
public java.lang.Integer getUserId() { public java.lang.Integer getUserId() {
return getInt("userId"); return getInt("userId");
} }
public void setPid(java.lang.Integer pid) { public void setPid(java.lang.Integer pid) {
set("pid", pid); set("pid", pid);
} }
public java.lang.Integer getPid() { public java.lang.Integer getPid() {
return getInt("pid"); return getInt("pid");
} }
public void setCate(java.lang.Integer cate) { public void setCate(java.lang.Integer cate) {
set("cate", cate); set("cate", cate);
} }
public java.lang.Integer getCate() { public java.lang.Integer getCate() {
return getInt("cate"); return getInt("cate");
} }
public void setContentId(java.lang.Integer contentId) { public void setContentId(java.lang.Integer contentId) {
set("contentId", contentId); set("contentId", contentId);
} }
public java.lang.Integer getContentId() { public java.lang.Integer getContentId() {
return getInt("contentId"); return getInt("contentId");
} }
public void setContent(java.lang.String content) { public void setContent(java.lang.String content) {
set("content", content); set("content", content);
} }
public java.lang.String getContent() { public java.lang.String getContent() {
return getStr("content"); return getStr("content");
} }
public void setCreateTime(java.lang.Long createTime) { public void setCreateTime(java.lang.Long createTime) {
set("createTime", createTime); set("createTime", createTime);
} }
public java.lang.Long getCreateTime() { public java.lang.Long getCreateTime() {
return getLong("createTime"); return getLong("createTime");
} }
public void setSupportNum(java.lang.Integer supportNum) { public void setSupportNum(java.lang.Integer supportNum) {
set("supportNum", supportNum); set("supportNum", supportNum);
} }
public java.lang.Integer getSupportNum() { public java.lang.Integer getSupportNum() {
return getInt("supportNum"); return getInt("supportNum");
} }
public void setStatus(java.lang.Integer status) { public void setStatus(java.lang.Integer status) {
set("status", status); set("status", status);
} }
public java.lang.Integer getStatus() { public java.lang.Integer getStatus() {
return getInt("status"); return getInt("status");
} }
} }

View File

@ -1,125 +1,124 @@
package com.lxyer.model.base; package com.lxyer.model.base;
import com.jfinal.kit.Kv;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.IBean; import com.jfinal.plugin.activerecord.IBean;
import com.jfinal.plugin.activerecord.Model;
/** /**
* Generated by JFinal, do not modify this file. * Generated by JFinal, do not modify this file.
*/ */
@SuppressWarnings("serial") @SuppressWarnings("serial")
public abstract class BaseContent<M extends BaseContent<M>> extends Model<M> implements IBean,IModel<M> { public abstract class BaseContent<M extends BaseContent<M>> extends Model<M> implements IBean, IModel<M> {
public void setContentId(java.lang.Integer contentId) { public void setContentId(java.lang.Integer contentId) {
set("contentId", contentId); set("contentId", contentId);
} }
public java.lang.Integer getContentId() { public java.lang.Integer getContentId() {
return getInt("contentId"); return getInt("contentId");
} }
public void setUserId(java.lang.Integer userId) { public void setUserId(java.lang.Integer userId) {
set("userId", userId); set("userId", userId);
} }
public java.lang.Integer getUserId() { public java.lang.Integer getUserId() {
return getInt("userId"); return getInt("userId");
} }
public void setTitle(java.lang.String title) { public void setTitle(java.lang.String title) {
set("title", title); set("title", title);
} }
public java.lang.String getTitle() { public java.lang.String getTitle() {
return getStr("title"); return getStr("title");
} }
public void setDigest(java.lang.String digest) { public void setDigest(java.lang.String digest) {
set("digest", digest); set("digest", digest);
} }
public java.lang.String getDigest() { public java.lang.String getDigest() {
return getStr("digest"); return getStr("digest");
} }
public void setContent(java.lang.String content) { public void setContent(java.lang.String content) {
set("content", content); set("content", content);
} }
public java.lang.String getContent() { public java.lang.String getContent() {
return getStr("content"); return getStr("content");
} }
public void setCreateTime(java.lang.Long createTime) { public void setCreateTime(java.lang.Long createTime) {
set("createTime", createTime); set("createTime", createTime);
} }
public java.lang.Long getCreateTime() { public java.lang.Long getCreateTime() {
return getLong("createTime"); return getLong("createTime");
} }
public void setCate(java.lang.Integer cate) { public void setCate(java.lang.Integer cate) {
set("cate", cate); set("cate", cate);
} }
public java.lang.Integer getCate() { public java.lang.Integer getCate() {
return getInt("cate"); return getInt("cate");
} }
public void setType(java.lang.Integer type) { public void setType(java.lang.Integer type) {
set("type", type); set("type", type);
} }
public java.lang.Integer getType() { public java.lang.Integer getType() {
return getInt("type"); return getInt("type");
} }
public void setReplyNum(java.lang.Integer replyNum) { public void setReplyNum(java.lang.Integer replyNum) {
set("replyNum", replyNum); set("replyNum", replyNum);
} }
public java.lang.Integer getReplyNum() { public java.lang.Integer getReplyNum() {
return getInt("replyNum"); return getInt("replyNum");
} }
public void setViewNum(java.lang.Integer viewNum) { public void setViewNum(java.lang.Integer viewNum) {
set("viewNum", viewNum); set("viewNum", viewNum);
} }
public java.lang.Integer getViewNum() { public java.lang.Integer getViewNum() {
return getInt("viewNum"); return getInt("viewNum");
} }
public void setWonderful(java.lang.Integer wonderful) { public void setWonderful(java.lang.Integer wonderful) {
set("wonderful", wonderful); set("wonderful", wonderful);
} }
public java.lang.Integer getWonderful() { public java.lang.Integer getWonderful() {
return getInt("wonderful"); return getInt("wonderful");
} }
public void setTop(java.lang.Integer top) { public void setTop(java.lang.Integer top) {
set("top", top); set("top", top);
} }
public java.lang.Integer getTop() { public java.lang.Integer getTop() {
return getInt("top"); return getInt("top");
} }
public void setSolved(java.lang.Integer solved) { public void setSolved(java.lang.Integer solved) {
set("solved", solved); set("solved", solved);
} }
public java.lang.Integer getSolved() { public java.lang.Integer getSolved() {
return getInt("solved"); return getInt("solved");
} }
public void setStatus(java.lang.Integer status) { public void setStatus(java.lang.Integer status) {
set("status", status); set("status", status);
} }
public java.lang.Integer getStatus() { public java.lang.Integer getStatus() {
return getInt("status"); return getInt("status");
} }
} }

View File

@ -1,7 +1,7 @@
package com.lxyer.model.base; package com.lxyer.model.base;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.IBean; import com.jfinal.plugin.activerecord.IBean;
import com.jfinal.plugin.activerecord.Model;
/** /**
* Generated by JFinal, do not modify this file. * Generated by JFinal, do not modify this file.
@ -9,36 +9,36 @@ import com.jfinal.plugin.activerecord.IBean;
@SuppressWarnings("serial") @SuppressWarnings("serial")
public abstract class BaseContentItem<M extends BaseContentItem<M>> extends Model<M> implements IBean { public abstract class BaseContentItem<M extends BaseContentItem<M>> extends Model<M> implements IBean {
public void setItemId(java.lang.Integer itemId) { public void setItemId(java.lang.Integer itemId) {
set("itemId", itemId); set("itemId", itemId);
} }
public java.lang.Integer getItemId() { public java.lang.Integer getItemId() {
return getInt("itemId"); return getInt("itemId");
} }
public void setContentId(java.lang.Integer contentId) { public void setContentId(java.lang.Integer contentId) {
set("contentId", contentId); set("contentId", contentId);
} }
public java.lang.Integer getContentId() { public java.lang.Integer getContentId() {
return getInt("contentId"); return getInt("contentId");
} }
public void setCreateTime(java.util.Date createTime) { public void setCreateTime(java.util.Date createTime) {
set("createTime", createTime); set("createTime", createTime);
} }
public java.util.Date getCreateTime() { public java.util.Date getCreateTime() {
return get("createTime"); return get("createTime");
} }
public void setStatus(java.lang.Integer status) { public void setStatus(java.lang.Integer status) {
set("status", status); set("status", status);
} }
public java.lang.Integer getStatus() { public java.lang.Integer getStatus() {
return getInt("status"); return getInt("status");
} }
} }

View File

@ -1,7 +1,7 @@
package com.lxyer.model.base; package com.lxyer.model.base;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.IBean; import com.jfinal.plugin.activerecord.IBean;
import com.jfinal.plugin.activerecord.Model;
/** /**
* Generated by JFinal, do not modify this file. * Generated by JFinal, do not modify this file.
@ -9,36 +9,36 @@ import com.jfinal.plugin.activerecord.IBean;
@SuppressWarnings("serial") @SuppressWarnings("serial")
public abstract class BaseDynaAttr<M extends BaseDynaAttr<M>> extends Model<M> implements IBean { public abstract class BaseDynaAttr<M extends BaseDynaAttr<M>> extends Model<M> implements IBean {
public void setTid(java.lang.Integer tid) { public void setTid(java.lang.Integer tid) {
set("tid", tid); set("tid", tid);
} }
public java.lang.Integer getTid() { public java.lang.Integer getTid() {
return getInt("tid"); return getInt("tid");
} }
public void setCate(java.lang.Integer cate) { public void setCate(java.lang.Integer cate) {
set("cate", cate); set("cate", cate);
} }
public java.lang.Integer getCate() { public java.lang.Integer getCate() {
return getInt("cate"); return getInt("cate");
} }
public void setAttr(java.lang.String attr) { public void setAttr(java.lang.String attr) {
set("attr", attr); set("attr", attr);
} }
public java.lang.String getAttr() { public java.lang.String getAttr() {
return getStr("attr"); return getStr("attr");
} }
public void setValue(java.lang.String value) { public void setValue(java.lang.String value) {
set("value", value); set("value", value);
} }
public java.lang.String getValue() { public java.lang.String getValue() {
return getStr("value"); return getStr("value");
} }
} }

View File

@ -1,108 +1,108 @@
package com.lxyer.model.base; package com.lxyer.model.base;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.IBean; import com.jfinal.plugin.activerecord.IBean;
import com.jfinal.plugin.activerecord.Model;
/** /**
* Generated by JFinal, do not modify this file. * Generated by JFinal, do not modify this file.
*/ */
@SuppressWarnings("serial") @SuppressWarnings("serial")
public abstract class BaseUser<M extends BaseUser<M>> extends Model<M> implements IBean,IModel<M> { public abstract class BaseUser<M extends BaseUser<M>> extends Model<M> implements IBean, IModel<M> {
public void setUserId(java.lang.Integer userId) { public void setUserId(java.lang.Integer userId) {
set("userId", userId); set("userId", userId);
} }
public java.lang.Integer getUserId() { public java.lang.Integer getUserId() {
return getInt("userId"); return getInt("userId");
} }
public void setUsername(java.lang.String username) { public void setUsername(java.lang.String username) {
set("username", username); set("username", username);
} }
public java.lang.String getUsername() { public java.lang.String getUsername() {
return getStr("username"); return getStr("username");
} }
public void setSex(java.lang.Integer sex) { public void setSex(java.lang.Integer sex) {
set("sex", sex); set("sex", sex);
} }
public java.lang.Integer getSex() { public java.lang.Integer getSex() {
return getInt("sex"); return getInt("sex");
} }
public void setPhone(java.lang.String phone) { public void setPhone(java.lang.String phone) {
set("phone", phone); set("phone", phone);
} }
public java.lang.String getPhone() { public java.lang.String getPhone() {
return getStr("phone"); return getStr("phone");
} }
public void setNickname(java.lang.String nickname) { public void setNickname(java.lang.String nickname) {
set("nickname", nickname); set("nickname", nickname);
} }
public java.lang.String getNickname() { public java.lang.String getNickname() {
return getStr("nickname"); return getStr("nickname");
} }
public void setAvatar(java.lang.String avatar) { public void setAvatar(java.lang.String avatar) {
set("avatar", avatar); set("avatar", avatar);
} }
public java.lang.String getAvatar() { public java.lang.String getAvatar() {
return getStr("avatar"); return getStr("avatar");
} }
public void setRealname(java.lang.String realname) { public void setRealname(java.lang.String realname) {
set("realname", realname); set("realname", realname);
} }
public java.lang.String getRealname() { public java.lang.String getRealname() {
return getStr("realname"); return getStr("realname");
} }
public void setEmail(java.lang.String email) { public void setEmail(java.lang.String email) {
set("email", email); set("email", email);
} }
public java.lang.String getEmail() { public java.lang.String getEmail() {
return getStr("email"); return getStr("email");
} }
public void setCreateTime(java.lang.Long createTime) { public void setCreateTime(java.lang.Long createTime) {
set("createTime", createTime); set("createTime", createTime);
} }
public java.lang.Long getCreateTime() { public java.lang.Long getCreateTime() {
return getLong("createTime"); return getLong("createTime");
} }
public void setSign(java.lang.String sign) { public void setSign(java.lang.String sign) {
set("sign", sign); set("sign", sign);
} }
public java.lang.String getSign() { public java.lang.String getSign() {
return getStr("sign"); return getStr("sign");
} }
public void setCity(java.lang.String city) { public void setCity(java.lang.String city) {
set("city", city); set("city", city);
} }
public java.lang.String getCity() { public java.lang.String getCity() {
return getStr("city"); return getStr("city");
} }
public void setStatus(java.lang.Integer status) { public void setStatus(java.lang.Integer status) {
set("status", status); set("status", status);
} }
public java.lang.Integer getStatus() { public java.lang.Integer getStatus() {
return getInt("status"); return getInt("status");
} }
} }

View File

@ -1,7 +1,7 @@
package com.lxyer.model.base; package com.lxyer.model.base;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.IBean; import com.jfinal.plugin.activerecord.IBean;
import com.jfinal.plugin.activerecord.Model;
/** /**
* Generated by JFinal, do not modify this file. * Generated by JFinal, do not modify this file.
@ -9,28 +9,28 @@ import com.jfinal.plugin.activerecord.IBean;
@SuppressWarnings("serial") @SuppressWarnings("serial")
public abstract class BaseUserPwd<M extends BaseUserPwd<M>> extends Model<M> implements IBean { public abstract class BaseUserPwd<M extends BaseUserPwd<M>> extends Model<M> implements IBean {
public void setUserId(java.lang.Integer userId) { public void setUserId(java.lang.Integer userId) {
set("userId", userId); set("userId", userId);
} }
public java.lang.Integer getUserId() { public java.lang.Integer getUserId() {
return getInt("userId"); return getInt("userId");
} }
public void setPwd(java.lang.String pwd) { public void setPwd(java.lang.String pwd) {
set("pwd", pwd); set("pwd", pwd);
} }
public java.lang.String getPwd() { public java.lang.String getPwd() {
return getStr("pwd"); return getStr("pwd");
} }
public void setUpdateTime(java.lang.Long updateTime) { public void setUpdateTime(java.lang.Long updateTime) {
set("updateTime", updateTime); set("updateTime", updateTime);
} }
public java.lang.Long getUpdateTime() { public java.lang.Long getUpdateTime() {
return getLong("updateTime"); return getLong("updateTime");
} }
} }

View File

@ -11,21 +11,22 @@ import java.util.List;
public interface IModel<M extends Model<M>> { public interface IModel<M extends Model<M>> {
String sqlSpace(); String sqlSpace();
M getDao(); M getDao();
default List<M> findList(Kv kv){ default List<M> findList(Kv kv) {
SqlPara sqlPara = getDao().getSqlPara(sqlSpace()+".list", kv); SqlPara sqlPara = getDao().getSqlPara(sqlSpace() + ".list", kv);
return getDao().find(sqlPara); return getDao().find(sqlPara);
} }
default M findFirst(Kv kv){ default M findFirst(Kv kv) {
SqlPara sqlPara = Db.getSqlPara(sqlSpace()+".list", kv); SqlPara sqlPara = Db.getSqlPara(sqlSpace() + ".list", kv);
return getDao().findFirst(sqlPara); return getDao().findFirst(sqlPara);
} }
default Page<M> findPage(int pn, int ps, Kv kv){ default Page<M> findPage(int pn, int ps, Kv kv) {
SqlPara sqlPara = Db.getSqlPara(sqlSpace()+".list", kv); SqlPara sqlPara = Db.getSqlPara(sqlSpace() + ".list", kv);
return getDao().paginate(pn, ps, sqlPara); return getDao().paginate(pn, ps, sqlPara);
} }

View File

@ -1,23 +1,19 @@
package com.lxyer.service; package com.lxyer.service;
import com.jfinal.kit.Kv; import com.jfinal.kit.Kv;
import com.lxyer.model.ActLog; import com.lxyer.model.*;
import com.lxyer.model.Comment;
import com.lxyer.model.Content;
/** /**
* Created by JUECHENG at 2018/1/9 11:59. * Created by JUECHENG at 2018/1/9 11:59.
*/ */
public class CommentService { public class CommentService extends IService {
public static final CommentService me = new CommentService();
public void save(Comment comment, Integer userId) { public void save(Comment comment, Integer userId) {
if (comment.getCommentId() == null){ if (comment.getCommentId() == null) {
comment.setUserId(userId); comment.setUserId(userId);
comment.setCreateTime(System.currentTimeMillis()); comment.setCreateTime(System.currentTimeMillis());
comment.save(); comment.save();
}else { } else {
comment.update(); comment.update();
} }
@ -27,6 +23,7 @@ public class CommentService {
/** /**
* 评论点赞 * 评论点赞
*
* @param commentId * @param commentId
* @param ok * @param ok
* @param userId * @param userId
@ -38,7 +35,7 @@ public class CommentService {
throw new Exception("操作失败,未查询到相关信息"); throw new Exception("操作失败,未查询到相关信息");
ActLog actLog = ActLog.dao.findFirst(Kv.by("userId", userId).set("tid", commentId).set("cate", 1)); ActLog actLog = ActLog.dao.findFirst(Kv.by("userId", userId).set("tid", commentId).set("cate", 1));
if (actLog == null){ if (actLog == null) {
actLog = new ActLog(); actLog = new ActLog();
actLog.setTid(commentId); actLog.setTid(commentId);
actLog.setUserId(userId); actLog.setUserId(userId);
@ -46,7 +43,7 @@ public class CommentService {
actLog.setStatus(1); actLog.setStatus(1);
actLog.setCreateTime(System.currentTimeMillis()); actLog.setCreateTime(System.currentTimeMillis());
actLog.save(); actLog.save();
}else if (actLog.getStatus() != ok){ } else if (actLog.getStatus() != ok) {
actLog.setStatus(ok == 1 ? 1 : -1); actLog.setStatus(ok == 1 ? 1 : -1);
actLog.setCreateTime(System.currentTimeMillis()); actLog.setCreateTime(System.currentTimeMillis());
actLog.update(); actLog.update();

View File

@ -7,12 +7,13 @@ import com.lxyer.model.Content;
/** /**
* Created by JUECHENG at 2018/1/7 16:49. * Created by JUECHENG at 2018/1/7 16:49.
*/ */
public class ContentService { public class ContentService extends IService {
public static final ContentService me = new ContentService(); public static final ContentService me = new ContentService();
/** /**
* 帖子保存 * 帖子保存
*
* @param content * @param content
* @param userId * @param userId
*/ */
@ -21,13 +22,14 @@ public class ContentService {
content.setCreateTime(System.currentTimeMillis()); content.setCreateTime(System.currentTimeMillis());
content.setUserId(userId); content.setUserId(userId);
content.save(); content.save();
}else { } else {
content.update(); content.update();
} }
} }
/** /**
* 删除帖子 * 删除帖子
*
* @param contentId * @param contentId
* @param userId * @param userId
* @throws Exception * @throws Exception
@ -47,6 +49,7 @@ public class ContentService {
/** /**
* 帖子收藏 * 帖子收藏
*
* @param contentId * @param contentId
* @param userId * @param userId
* @param status * @param status
@ -60,14 +63,14 @@ public class ContentService {
Kv kv = Kv.by("tid", contentId).set("userId", userId).set("cate", 2);//cate:2收藏 Kv kv = Kv.by("tid", contentId).set("userId", userId).set("cate", 2);//cate:2收藏
ActLog actLog = ActLog.dao.findFirst(kv); ActLog actLog = ActLog.dao.findFirst(kv);
if (actLog == null){ if (actLog == null) {
actLog = new ActLog(); actLog = new ActLog();
actLog.setCate(2); actLog.setCate(2);
actLog.setTid(contentId); actLog.setTid(contentId);
actLog.setUserId(userId); actLog.setUserId(userId);
actLog.setCreateTime(System.currentTimeMillis()); actLog.setCreateTime(System.currentTimeMillis());
actLog.save(); actLog.save();
}else if (actLog.getStatus() != status){ } else if (actLog.getStatus() != status) {
actLog.setStatus(status == 1 ? 1 : -1); actLog.setStatus(status == 1 ? 1 : -1);
actLog.setCreateTime(System.currentTimeMillis()); actLog.setCreateTime(System.currentTimeMillis());
actLog.update(); actLog.update();
@ -79,6 +82,7 @@ public class ContentService {
/** /**
* 帖子置顶/加精 * 帖子置顶/加精
*
* @param contentId * @param contentId
* @param field * @param field
* @param v * @param v

View File

@ -11,11 +11,11 @@ import java.util.Random;
/** /**
* Created by JUECHENG at 2018/1/7 22:59. * Created by JUECHENG at 2018/1/7 22:59.
*/ */
public class UserService { public class UserService extends IService {
public static final UserService me = new UserService();
/** /**
* 创建用户 * 创建用户
*
* @param email * @param email
* @param pwd * @param pwd
* @param nickname * @param nickname
@ -33,7 +33,7 @@ public class UserService {
user.setUsername(email); user.setUsername(email);
user.setEmail(email); user.setEmail(email);
user.setNickname(nickname); user.setNickname(nickname);
user.setAvatar("/res/images/avatar/"+ new Random().nextInt(21) +".jpg");//默认头像 user.setAvatar("/res/images/avatar/" + new Random().nextInt(21) + ".jpg");//默认头像
user.setCreateTime(System.currentTimeMillis()); user.setCreateTime(System.currentTimeMillis());
user.setStatus(1); user.setStatus(1);
user.save(); user.save();
@ -46,16 +46,16 @@ public class UserService {
public User login(String username, String pwd) throws Exception { public User login(String username, String pwd) throws Exception {
User user = User.dao.findFirst(Kv.by("username", username)); User user = User.dao.findFirst(Kv.by("username", username));
if (user == null){ if (user == null) {
throw new Exception("密码错误!"); throw new Exception("密码错误!");
} }
UserPwd userPwd = UserPwd.dao.findById(user.getUserId()); UserPwd userPwd = UserPwd.dao.findById(user.getUserId());
if (userPwd == null || !LxyKit.md5IfNeed(pwd).equalsIgnoreCase(userPwd.getPwd())){ if (userPwd == null || !LxyKit.md5IfNeed(pwd).equalsIgnoreCase(userPwd.getPwd())) {
throw new Exception("密码错误!"); throw new Exception("密码错误!");
} }
if (user.getInt("status") == -1){ if (user.getInt("status") == -1) {
throw new Exception("限制登录"); throw new Exception("限制登录");
} }
@ -68,6 +68,7 @@ public class UserService {
/** /**
* 修改密码 * 修改密码
*
* @param userId * @param userId
* @param pwd * @param pwd
*/ */

View File

@ -111,7 +111,7 @@
#(x.content) #(x.content)
</div> </div>
<div class="jieda-reply"> <div class="jieda-reply">
#if(x.hadSupport > 1) #if(x.hadSupport??0 > 1)
<span class="jieda-zan zanok" type="zan"><i class="iconfont icon-zan"></i><em>#(x.supportNum)</em></span> <span class="jieda-zan zanok" type="zan"><i class="iconfont icon-zan"></i><em>#(x.supportNum)</em></span>
#else #else
<span class="jieda-zan" type="zan"><i class="iconfont icon-zan"></i><em>#(x.supportNum)</em></span> <span class="jieda-zan" type="zan"><i class="iconfont icon-zan"></i><em>#(x.supportNum)</em></span>