一、
- 自定义一个方法:
private static Map<String, Object> getFieldsName(ProceedingJoinPoint point) throws ClassNotFoundException, NoSuchMethodException {
Map<String,Object> map = new HashMap<>();
Object[] paramObjs = point.getArgs();
Signature signature = point.getSignature();
MethodSignature methodSignature = (MethodSignature) signature;
String[] parameterNames = methodSignature.getParameterNames();
for(int i=0;i<parameterNames.length;i++){
map.put(parameterNames[i],paramObjs[i]);
}
return map;
}
- 想要不进入代理方法,只能使用@Around和ProceedingJoinPoint。
使用例子:
@Around(value = "pointCut()")
public Object paramValidateBefore(ProceedingJoinPoint point) throws Throwable {
Map<String, Object> map = getFieldsName(point);
if(null == map.get(BlacklistConst.UPLOAD_FILE_ID)){
return Resp.build(ResponseCode.ERROR.getCode(), "文件已失效,请重新上传!", map);
}
String key = (String) map.get(BlacklistConst.UPLOAD_FILE_ID);
if(ProgressManage.checkProgressMap.containsKey(key) || ProgressManage.importProgressMap.containsKey(key)){
return point.proceed();
}
if(map.containsKey("response")){
HttpServletResponse response = (HttpServletResponse) map.get("response");
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setHeader("content-Disposition", "attachment;filename=" + URLEncoder.encode("导出异常.csv", "utf-8"));
OutputStream stream = response.getOutputStream();
stream.write("操作间隔大于15分钟,文件已失效,请重新上传!".getBytes("GBK"));
return null;
}
return Resp.build(ResponseCode.ERROR.getCode(), "文件已失效,请重新上传!", map);
}