1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/ren365880-jfinal-annotation

Присоединиться к Gitlife
Откройте для себя и примите участие в публичных проектах с открытым исходным кодом с участием более 10 миллионов разработчиков. Приватные репозитории также полностью бесплатны :)
Присоединиться бесплатно
В этом репозитории не указан файл с открытой лицензией (LICENSE). При использовании обратитесь к конкретному описанию проекта и его зависимостям в коде.
Клонировать/Скачать
EmptyInterceptor.java 1.7 КБ
Копировать Редактировать Web IDE Исходные данные Просмотреть построчно История
梦里蓝天 Отправлено 23.10.2017 04:37 53f3c59
import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.core.Controller;
import com.xinxing.annotation.EmptyInterface;
import com.xinxing.utils.StampToDate;
/**
* 方法不能为空注解验证
* @author Administrator
*
*/
public class EmptyInterceptor implements Interceptor {
@Override
public void intercept(Invocation inv) {
Annotation annotation = inv.getMethod().getAnnotation(Annotation.class);
//如果有使用注解就调用验证方法,如果没有就继续继续往下往下运行
if (annotation != null) {
noEmpty(annotation, inv);
}else{
inv.invoke();
}
}
public void noEmpty(Annotation 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
//form-data模式需要根据自己的情况修改下
String folderName = "loss/" + StampToDate.getMonthDay();
con.getFile("photo",folderName);
}
String[] value = annotation.value();
boolean isTrue = true;
String key = "";
for (String v : value) {
String parameter = con.getPara(v);
if (parameter == null || parameter.trim().length() == 0) {
isTrue = false;
key = v;
break;
}
}
if(isTrue){
inv.invoke();
}else{
con.setAttr("msg", key+"不能为空");
con.setAttr("code", "509");
con.renderJson();
}
}
}

Опубликовать ( 0 )

Вы можете оставить комментарий после Вход в систему

1
https://api.gitlife.ru/oschina-mirror/ren365880-jfinal-annotation.git
git@api.gitlife.ru:oschina-mirror/ren365880-jfinal-annotation.git
oschina-mirror
ren365880-jfinal-annotation
ren365880-jfinal-annotation
master