帖子功能加入[发布/更新/评论/置顶/加精/删除]
This commit is contained in:
@@ -6,12 +6,15 @@ import java.util.Map;
|
||||
/**
|
||||
* Created by Lxyer lxy208@126.com at 2016/8/4 0:13.
|
||||
*/
|
||||
public class JsonBean {
|
||||
public class JBean {
|
||||
public int code;//全局状态码: -1失败,1成功,2未登录
|
||||
public String msg;
|
||||
public Object obj;
|
||||
|
||||
public JsonBean(int code){
|
||||
public static final JBean success = new JBean(1, "操作成功");
|
||||
public static final JBean error = new JBean(-1, "操作失败");
|
||||
|
||||
public JBean(int code){
|
||||
this.code = code;
|
||||
if (code == 1)
|
||||
this.msg = "操作成功";
|
||||
@@ -21,11 +24,11 @@ public class JsonBean {
|
||||
this.msg = "未登录,请前往登录";
|
||||
}
|
||||
|
||||
public JsonBean(int code, String msg){
|
||||
public JBean(int code, String msg){
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
}
|
||||
public JsonBean(int code, String msg, Object obj){
|
||||
public JBean(int code, String msg, Object obj){
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
this.obj = obj;
|
||||
@@ -35,7 +38,7 @@ public class JsonBean {
|
||||
return msg;
|
||||
}
|
||||
|
||||
public JsonBean setMsg(String msg) {
|
||||
public JBean setMsg(String msg) {
|
||||
this.msg = msg;
|
||||
return this;
|
||||
}
|
||||
@@ -44,7 +47,7 @@ public class JsonBean {
|
||||
return code;
|
||||
}
|
||||
|
||||
public JsonBean setCode(int code) {
|
||||
public JBean setCode(int code) {
|
||||
this.code = code;
|
||||
if (code == 1)
|
||||
this.msg = "操作成功";
|
||||
@@ -53,12 +56,12 @@ public class JsonBean {
|
||||
return this;
|
||||
}
|
||||
|
||||
public JsonBean setCode(int code, String msg) {
|
||||
public JBean setCode(int code, String msg) {
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
return this;
|
||||
}
|
||||
public JsonBean setCode(int code, String msg, Object obj) {
|
||||
public JBean setCode(int code, String msg, Object obj) {
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
this.obj = obj;
|
||||
@@ -69,11 +72,11 @@ public class JsonBean {
|
||||
return obj;
|
||||
}
|
||||
|
||||
public JsonBean setObj(Object obj) {
|
||||
public JBean setObj(Object obj) {
|
||||
this.obj = obj;
|
||||
return this;
|
||||
}
|
||||
public <K, V> JsonBean set(Object k, Object v){
|
||||
public <K, V> JBean set(Object k, Object v){
|
||||
if (!(obj instanceof Map)){
|
||||
obj = new HashMap();
|
||||
}
|
||||
@@ -86,35 +89,29 @@ public class JsonBean {
|
||||
下面的是一些快速创建JsonBean的方式,
|
||||
使用中可以使用new ,同时也可以直接使用
|
||||
*/
|
||||
public static JsonBean success(){
|
||||
return new JsonBean(1, "操作成功");
|
||||
public static JBean success(Object obj){
|
||||
return new JBean(1, "操作成功",obj);
|
||||
}
|
||||
public static JsonBean success(Object obj){
|
||||
return new JsonBean(1, "操作成功",obj);
|
||||
public static JBean success(int code, String msg){
|
||||
return new JBean(1, msg);
|
||||
}
|
||||
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 JBean success(int code, String msg, Object obj){
|
||||
return new JBean(1, msg, obj);
|
||||
}
|
||||
|
||||
public static JsonBean error(){
|
||||
return new JsonBean(-1, "操作失败");
|
||||
public static JBean error(int code, String msg){
|
||||
return new JBean(code, msg);
|
||||
}
|
||||
public static JsonBean error(int code, String msg){
|
||||
return new JsonBean(code, msg);
|
||||
public static JBean error(int code, String msg, Object obj){
|
||||
return new JBean(code, msg, obj);
|
||||
}
|
||||
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);
|
||||
public static JBean error(String msg){
|
||||
return new JBean(-1, msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "JsonBean{" +
|
||||
return "JBean{" +
|
||||
"code=" + code +
|
||||
", msg='" + msg + '\'' +
|
||||
", obj=" + obj +
|
@@ -3,6 +3,7 @@ package com.lxyer.config.interceptor;
|
||||
import com.jfinal.aop.Interceptor;
|
||||
import com.jfinal.aop.Invocation;
|
||||
import com.jfinal.core.Controller;
|
||||
import com.lxyer.config.JBean;
|
||||
import com.lxyer.model.User;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
@@ -22,7 +23,8 @@ public class LoginInterceptor implements Interceptor {
|
||||
User user = controller.getSessionAttr("user");
|
||||
if (user == null){
|
||||
if ("XMLHttpRequest".equals(request.getHeader("X-Requested-With"))){
|
||||
|
||||
controller.renderJson(new JBean(-1,"请登录后再尝试"));
|
||||
return;
|
||||
}else {
|
||||
controller.redirect("/user/login");
|
||||
}
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package com.lxyer.config.route;
|
||||
|
||||
import com.jfinal.config.Routes;
|
||||
import com.lxyer.controller.CommentController;
|
||||
import com.lxyer.controller.HomeController;
|
||||
import com.lxyer.controller.JieController;
|
||||
import com.lxyer.controller.UserController;
|
||||
@@ -16,5 +17,6 @@ public class SiteRoute extends Routes {
|
||||
add("/", HomeController.class);
|
||||
add("/user", UserController.class);
|
||||
add("/jie", JieController.class);
|
||||
add("/comment", CommentController.class);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user