|
|
|
@ -1,69 +0,0 @@
|
|
|
|
|
package com.dsideal.resource.Interceptor;
|
|
|
|
|
|
|
|
|
|
import com.dsideal.resource.Util.CommonUtil;
|
|
|
|
|
import com.jfinal.aop.Interceptor;
|
|
|
|
|
import com.jfinal.aop.Invocation;
|
|
|
|
|
import com.jfinal.core.Controller;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 检查是不是符合layui的分页查询规则
|
|
|
|
|
*
|
|
|
|
|
* @author Administrator
|
|
|
|
|
*/
|
|
|
|
|
public class LayUiPageInfoInterceptor implements Interceptor {
|
|
|
|
|
@Override
|
|
|
|
|
public void intercept(Invocation inv) {
|
|
|
|
|
LayUiPageInfoInterface annotation = inv.getMethod().getAnnotation(LayUiPageInfoInterface.class);
|
|
|
|
|
if (annotation != null) {
|
|
|
|
|
checkLayUiPageInfo(annotation, inv);
|
|
|
|
|
} else {
|
|
|
|
|
inv.invoke();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void checkLayUiPageInfo(LayUiPageInfoInterface annotation, Invocation inv) {
|
|
|
|
|
Controller con = inv.getController();
|
|
|
|
|
String header = con.getHeader("Content-Type"); //取出head头
|
|
|
|
|
if (header != null && header.indexOf("multipart/form-data") != -1) { //判断是否是form-data
|
|
|
|
|
inv.invoke();
|
|
|
|
|
}
|
|
|
|
|
String[] value = annotation.value();
|
|
|
|
|
|
|
|
|
|
String o_page = null;
|
|
|
|
|
String o_limit = null;
|
|
|
|
|
|
|
|
|
|
for (String v : value) {
|
|
|
|
|
String parameter = con.getPara(v);
|
|
|
|
|
if (v.equals("page")) {
|
|
|
|
|
o_page = parameter;
|
|
|
|
|
}
|
|
|
|
|
if (v.equals("limit")) {
|
|
|
|
|
o_limit = parameter;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (o_page != null && o_limit != null) {
|
|
|
|
|
if (!CommonUtil.isNumeric(o_page)) {
|
|
|
|
|
con.renderJson(CommonUtil.returnMessageJson(false, "传入的page参数不是数字!"));
|
|
|
|
|
}
|
|
|
|
|
if (!CommonUtil.isNumeric(o_limit)) {
|
|
|
|
|
con.renderJson(CommonUtil.returnMessageJson(false, "传入的limit参数不是数字!"));
|
|
|
|
|
}
|
|
|
|
|
//检查大小
|
|
|
|
|
int page = Integer.parseInt(o_page);
|
|
|
|
|
int limit = Integer.parseInt(o_limit);
|
|
|
|
|
|
|
|
|
|
if (limit > 100) {
|
|
|
|
|
con.renderJson(CommonUtil.returnMessageJson(false, "传入的limit参数大于100,被禁止!"));
|
|
|
|
|
}
|
|
|
|
|
if (limit < 1) {
|
|
|
|
|
con.renderJson(CommonUtil.returnMessageJson(false, "传入的limit参数小于1,被禁止!"));
|
|
|
|
|
}
|
|
|
|
|
//放行
|
|
|
|
|
inv.invoke();
|
|
|
|
|
} else if (o_page == null) {
|
|
|
|
|
con.renderJson(CommonUtil.returnMessageJson(false, "传入的page参数为空!"));
|
|
|
|
|
} else if (o_limit == null) {
|
|
|
|
|
con.renderJson(CommonUtil.returnMessageJson(false, "传入的limit参数为空!"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|