首页 > 其他 > 详细

使用拦截器对前端传入的字符串进行trim操作

时间:2019-03-30 16:14:38      阅读:361      评论:0      收藏:0      [点我收藏+]
 1   @Before("apiItf()")
 2     public void before(JoinPoint joinPoint) throws Exception {
 3         Object[] args = joinPoint.getArgs();
 4         if (args != null) {
 5             Method proxyMethod = ((MethodSignature) joinPoint.getSignature()).getMethod();
 6             ApiOperation apiOperation = proxyMethod.getAnnotation(ApiOperation.class);
 7             log.info("[" + apiOperation.value() + "] Request {}", JacksonUtils.jsonObjectSerializer(joinPoint.getArgs()));
 8 
 9             Object[] object = joinPoint.getArgs();
10             Object request = object[0];
11             Field[] fields = request.getClass().getDeclaredFields();
12             for (Field field : fields) {
13                 String name = field.getName();
14                 name = name.substring(0, 1).toUpperCase() + name.substring(1);
15                 if (field.getGenericType().getTypeName().equals("java.lang.String")) {
16                     Method getField = request.getClass().getMethod("get" + name);
17                     Method setFiled = request.getClass().getMethod("set" + name, new Class[]{String.class});
18                     String value = (String) getField.invoke(request);
19                     if (!Strings.isNullOrEmpty(value)) {
20                         setFiled.invoke(request, new Object[]{value.trim()});
21                     }
22                 }
23             }
24         }
25     }

 

使用拦截器对前端传入的字符串进行trim操作

原文:https://www.cnblogs.com/aut-lory/p/10627772.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!