This commit is contained in:
2018-01-07 19:28:20 +08:00
parent b24d4be809
commit 4c7a0d6e91
170 changed files with 4155 additions and 32 deletions

View File

@@ -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

View 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 +
'}';
}
}

View 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);
}
}

View File

@@ -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);
}
}