.
This commit is contained in:
@@ -36,6 +36,7 @@ public class FlyConfig extends JFinalConfig {
|
||||
me.setBaseTemplatePath(PathKit.getWebRootPath());
|
||||
|
||||
me.addSharedFunction("/WEB-INF/_t/layout.html");
|
||||
me.addSharedObject("lxyKit", new LxyKit());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
123
src/main/java/com/lxyer/config/JsonBean.java
Normal file
123
src/main/java/com/lxyer/config/JsonBean.java
Normal file
@@ -0,0 +1,123 @@
|
||||
package com.lxyer.config;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by Lxyer lxy208@126.com at 2016/8/4 0:13.
|
||||
*/
|
||||
public class JsonBean {
|
||||
public int code;//全局状态码: -1失败,1成功,2未登录
|
||||
public String msg;
|
||||
public Object obj;
|
||||
|
||||
public JsonBean(int code){
|
||||
this.code = code;
|
||||
if (code == 1)
|
||||
this.msg = "操作成功";
|
||||
if (code == -1)
|
||||
this.msg = "操作失败";
|
||||
if (code == 2)
|
||||
this.msg = "未登录,请前往登录";
|
||||
}
|
||||
|
||||
public JsonBean(int code, String msg){
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
}
|
||||
public JsonBean(int code, String msg, Object obj){
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
this.obj = obj;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
public JsonBean setMsg(String msg) {
|
||||
this.msg = msg;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public JsonBean setCode(int code) {
|
||||
this.code = code;
|
||||
if (code == 1)
|
||||
this.msg = "操作成功";
|
||||
if (code == -1)
|
||||
this.msg = "操作失败";
|
||||
return this;
|
||||
}
|
||||
|
||||
public JsonBean setCode(int code, String msg) {
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
return this;
|
||||
}
|
||||
public JsonBean setCode(int code, String msg, Object obj) {
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
this.obj = obj;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Object getObj() {
|
||||
return obj;
|
||||
}
|
||||
|
||||
public JsonBean setObj(Object obj) {
|
||||
this.obj = obj;
|
||||
return this;
|
||||
}
|
||||
public <K, V> JsonBean set(Object k, Object v){
|
||||
if (!(obj instanceof Map)){
|
||||
obj = new HashMap();
|
||||
}
|
||||
((Map) obj).put(k, v);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
下面的是一些快速创建JsonBean的方式,
|
||||
使用中可以使用new ,同时也可以直接使用
|
||||
*/
|
||||
public static JsonBean success(){
|
||||
return new JsonBean(1, "操作成功");
|
||||
}
|
||||
public static JsonBean success(Object obj){
|
||||
return new JsonBean(1, "操作成功",obj);
|
||||
}
|
||||
public static JsonBean success(int code, String msg){
|
||||
return new JsonBean(1, msg);
|
||||
}
|
||||
public static JsonBean success(int code, String msg, Object obj){
|
||||
return new JsonBean(1, msg, obj);
|
||||
}
|
||||
|
||||
public static JsonBean error(){
|
||||
return new JsonBean(-1, "操作失败");
|
||||
}
|
||||
public static JsonBean error(int code, String msg){
|
||||
return new JsonBean(code, msg);
|
||||
}
|
||||
public static JsonBean error(int code, String msg, Object obj){
|
||||
return new JsonBean(code, msg, obj);
|
||||
}
|
||||
public static JsonBean error(String msg){
|
||||
return new JsonBean(-1, msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "JsonBean{" +
|
||||
"code=" + code +
|
||||
", msg='" + msg + '\'' +
|
||||
", obj=" + obj +
|
||||
'}';
|
||||
}
|
||||
}
|
33
src/main/java/com/lxyer/config/LxyKit.java
Normal file
33
src/main/java/com/lxyer/config/LxyKit.java
Normal file
@@ -0,0 +1,33 @@
|
||||
package com.lxyer.config;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
/**
|
||||
* Created by Lxy at 2017/11/29 15:17.
|
||||
*/
|
||||
public final class LxyKit {
|
||||
|
||||
public static String dateFmt(long time){
|
||||
/**
|
||||
* 刚刚 60秒内 60 * 1000
|
||||
* x分钟前 1小时候内 60 * 60*1000
|
||||
* x小时前 1天内 24 * 60*60*1000
|
||||
* x天前 1周内 7 * 24*60*60*1000
|
||||
* 年-月-日 1周前
|
||||
*/
|
||||
long now = System.currentTimeMillis();
|
||||
|
||||
long diff = now - time;
|
||||
if (diff < 60 * 1000)
|
||||
return "刚刚";
|
||||
else if (diff < 60 * 60 *1000)
|
||||
return Math.floorDiv(diff, 60 *1000) + "分钟前";
|
||||
else if (diff < 24 * 60*60*1000)
|
||||
return Math.floorDiv(diff, 60 *60*1000) + "小时前";
|
||||
else if (diff > 24 * 60*60*1000 && diff < 7 * 24*60*60*1000)
|
||||
return Math.floorDiv(diff, 24 * 60*60*1000) + "天前";
|
||||
else
|
||||
return new SimpleDateFormat("yyyy-MM-dd").format(time);
|
||||
|
||||
}
|
||||
}
|
@@ -2,6 +2,7 @@ package com.lxyer.config.route;
|
||||
|
||||
import com.jfinal.config.Routes;
|
||||
import com.lxyer.controller.HomeController;
|
||||
import com.lxyer.controller.UserController;
|
||||
|
||||
/**
|
||||
* Created by JUECHENG at 2018/1/7 11:16.
|
||||
@@ -12,5 +13,6 @@ public class SiteRoute extends Routes {
|
||||
setBaseViewPath("/WEB-INF/fly");
|
||||
|
||||
add("/", HomeController.class);
|
||||
add("/user", UserController.class);
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,9 @@
|
||||
package com.lxyer.controller;
|
||||
|
||||
/**
|
||||
* Created by JUECHENG at 2018/1/7 16:48.
|
||||
*/
|
||||
public class ContentController extends IController{
|
||||
|
||||
|
||||
}
|
9
src/main/java/com/lxyer/controller/FileController.java
Normal file
9
src/main/java/com/lxyer/controller/FileController.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package com.lxyer.controller;
|
||||
|
||||
/**
|
||||
* 文件管理
|
||||
* Created by JUECHENG at 2018/1/7 16:44.
|
||||
*/
|
||||
public class FileController extends IController{
|
||||
|
||||
}
|
@@ -1,11 +1,9 @@
|
||||
package com.lxyer.controller;
|
||||
|
||||
import com.jfinal.aop.Before;
|
||||
import com.jfinal.plugin.activerecord.Db;
|
||||
import com.jfinal.plugin.activerecord.SqlPara;
|
||||
import com.jfinal.plugin.ehcache.CacheInterceptor;
|
||||
import com.jfinal.plugin.redis.Cache;
|
||||
import com.jfinal.plugin.redis.Redis;
|
||||
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;
|
||||
|
||||
import java.util.List;
|
||||
@@ -14,36 +12,71 @@ import java.util.List;
|
||||
* Created by JUECHENG at 2018/1/7 14:40.
|
||||
*/
|
||||
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(){
|
||||
String para = getPara();
|
||||
|
||||
Cache cache = Redis.use();
|
||||
String cacheKey = "user-" + para;
|
||||
//置顶贴
|
||||
List<Content> top = Content.dao.findPage(1, 5, Kv.by("top", 1)).getList();
|
||||
|
||||
User user = cache.get(cacheKey);
|
||||
if (user == null)
|
||||
cache.setex(cacheKey, 10, user = User.dao.findById(para+""));
|
||||
//非置顶贴
|
||||
List<Content> contents = Content.dao.findPage(1, 30,Kv.by("top", 0)).getList();
|
||||
|
||||
if (user != null)
|
||||
System.out.println(user.toJson());
|
||||
//热帖
|
||||
|
||||
renderText("hello fly");
|
||||
//热议
|
||||
List<Content> hotReply = Content.dao.findPage(1, 8, Kv.by("order", "replyNum DESC")).getList();
|
||||
|
||||
//最新加入
|
||||
List<User> lastReg = User.dao.findPage(1, 8, Kv.by("order", "createTime DESC")).getList();
|
||||
|
||||
setAttr("top", top);
|
||||
setAttr("contents", contents);
|
||||
setAttr("hotReply", hotReply);
|
||||
setAttr("lastReg", lastReg);
|
||||
|
||||
render("index.html");
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询用户
|
||||
* 帖子栏目列表
|
||||
*/
|
||||
@Before(CacheInterceptor.class)
|
||||
public void query_user(){
|
||||
public void column(){
|
||||
String para = getPara(0, "");
|
||||
int solved = getParaToInt("solved", -1);
|
||||
int wonderful = getParaToInt("wonderful", -1);
|
||||
|
||||
//User.dao.find("select * from user")
|
||||
Kv kv = Kv.by("type", column.get(para)).set("order", "top DESC,createTime DESC");
|
||||
Page<Content> contents = Content.dao.findPage(getPn(), getPs(3), kv);
|
||||
|
||||
SqlPara sqlPara = Db.getSqlPara("user.list");
|
||||
//热议
|
||||
List<Content> hotReply = Content.dao.findPage(1, 8, Kv.by("order", "replyNum DESC")).getList();
|
||||
|
||||
setAttrs(Kv.by("contents", contents).set("hotReply", hotReply)
|
||||
.set("solved", solved).set("wonderful", wonderful).set("column", para));
|
||||
|
||||
List<User> users = User.dao.find(sqlPara);
|
||||
|
||||
renderJson(users);
|
||||
render("jie/index.html");
|
||||
}
|
||||
|
||||
/**
|
||||
* 帖子详情
|
||||
*/
|
||||
public void jie(){
|
||||
int contentId = getParaToInt(0);
|
||||
|
||||
//ContentInfo content = contentService.contentInfo(sessionid, contentid);
|
||||
//Sheet<CommentInfo> comments = commentService.commentQuery(request.getSessionid(false) ,contentid, new Flipper().limit(30));
|
||||
|
||||
Record content = Content.dao.findFirst(Kv.by("contentId", contentId));
|
||||
|
||||
//热议
|
||||
List<Content> hotReply = Content.dao.findPage(1, 8, Kv.by("order", "replyNum DESC")).getList();
|
||||
|
||||
setAttr("bean", content);
|
||||
setAttr("hotReply", hotReply);
|
||||
|
||||
render("jie/detail.html");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -3,6 +3,8 @@ package com.lxyer.controller;
|
||||
import com.jfinal.core.Controller;
|
||||
import com.jfinal.kit.Kv;
|
||||
import com.jfinal.plugin.activerecord.*;
|
||||
import com.jfinal.plugin.redis.Cache;
|
||||
import com.jfinal.plugin.redis.Redis;
|
||||
import com.lxyer.config.E;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -15,6 +17,8 @@ import java.util.Map;
|
||||
*/
|
||||
public class IController extends Controller {
|
||||
|
||||
public static final Cache cache = Redis.use();
|
||||
|
||||
public Kv getParams(String... key) {
|
||||
Kv kv = Kv.create();
|
||||
for (String k : key) {
|
||||
|
28
src/main/java/com/lxyer/controller/UserController.java
Normal file
28
src/main/java/com/lxyer/controller/UserController.java
Normal file
@@ -0,0 +1,28 @@
|
||||
package com.lxyer.controller;
|
||||
|
||||
/**
|
||||
* Created by JUECHENG at 2018/1/7 16:40.
|
||||
*/
|
||||
public class UserController extends IController {
|
||||
/**
|
||||
* 注册
|
||||
*/
|
||||
public void create(){
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录
|
||||
*/
|
||||
public void login(){
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
public void update(){
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -7,5 +7,10 @@ import com.lxyer.model.base.BaseContent;
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class Content extends BaseContent<Content> {
|
||||
|
||||
public static final Content dao = new Content().dao();
|
||||
|
||||
@Override
|
||||
public String sqlSpace() {
|
||||
return "content";
|
||||
}
|
||||
}
|
||||
|
@@ -8,5 +8,9 @@ import com.lxyer.model.base.BaseUser;
|
||||
@SuppressWarnings("serial")
|
||||
public class User extends BaseUser<User> {
|
||||
public static final User dao = new User().dao();
|
||||
|
||||
|
||||
@Override
|
||||
public String sqlSpace() {
|
||||
return "user";
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package com.lxyer.model.base;
|
||||
|
||||
import com.jfinal.kit.Kv;
|
||||
import com.jfinal.plugin.activerecord.Model;
|
||||
import com.jfinal.plugin.activerecord.IBean;
|
||||
|
||||
@@ -7,7 +8,7 @@ import com.jfinal.plugin.activerecord.IBean;
|
||||
* Generated by JFinal, do not modify this file.
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public abstract class BaseContent<M extends BaseContent<M>> extends Model<M> implements IBean {
|
||||
public abstract class BaseContent<M extends BaseContent<M>> extends Model<M> implements IBean,IModel<M> {
|
||||
|
||||
public void setContentId(java.lang.Integer contentId) {
|
||||
set("contentId", contentId);
|
||||
|
@@ -7,7 +7,7 @@ import com.jfinal.plugin.activerecord.IBean;
|
||||
* Generated by JFinal, do not modify this file.
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public abstract class BaseUser<M extends BaseUser<M>> extends Model<M> implements IBean {
|
||||
public abstract class BaseUser<M extends BaseUser<M>> extends Model<M> implements IBean,IModel<M> {
|
||||
|
||||
public void setUserId(java.lang.Integer userId) {
|
||||
set("userId", userId);
|
||||
|
36
src/main/java/com/lxyer/model/base/IModel.java
Normal file
36
src/main/java/com/lxyer/model/base/IModel.java
Normal file
@@ -0,0 +1,36 @@
|
||||
package com.lxyer.model.base;
|
||||
|
||||
import com.jfinal.kit.Kv;
|
||||
import com.jfinal.plugin.activerecord.Db;
|
||||
import com.jfinal.plugin.activerecord.Page;
|
||||
import com.jfinal.plugin.activerecord.Record;
|
||||
import com.jfinal.plugin.activerecord.SqlPara;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by JUECHENG at 2018/1/7 16:52.
|
||||
*/
|
||||
public interface IModel<M extends IModel<M>> {
|
||||
|
||||
String sqlSpace();
|
||||
|
||||
default List<M> findList(Kv kv){
|
||||
SqlPara sqlPara = Db.getSqlPara(sqlSpace()+".list", kv);
|
||||
|
||||
return (List) Db.find(sqlPara);
|
||||
}
|
||||
|
||||
default Record findFirst(Kv kv){
|
||||
SqlPara sqlPara = Db.getSqlPara(sqlSpace()+".list", kv);
|
||||
|
||||
return Db.findFirst(sqlPara);
|
||||
}
|
||||
|
||||
default Page<M> findPage(int pn, int ps, Kv kv){
|
||||
SqlPara sqlPara = Db.getSqlPara(sqlSpace()+".list", kv);
|
||||
|
||||
return (Page) Db.paginate(pn, ps, sqlPara);
|
||||
}
|
||||
|
||||
}
|
9
src/main/java/com/lxyer/service/ContentService.java
Normal file
9
src/main/java/com/lxyer/service/ContentService.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package com.lxyer.service;
|
||||
|
||||
/**
|
||||
* Created by JUECHENG at 2018/1/7 16:49.
|
||||
*/
|
||||
public class ContentService {
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user