共计 1503 个字符,预计需要花费 4 分钟才能阅读完成。
HandlerMethodArgumentResolver
1、策略接口:用于在给定申请的上下文中将办法参数解析为参数值,它是 HandlerMethod 办法的解析器,将 HttpServletRequest 解析为 HandlerMethod 办法的参数。
public interface HandlerMethodArgumentResolver {
/**
* 性能形容: 判断是否反对 MethodParameter
* 〈〉
* @Param:
* @Return:
* @Author: Steven
* @Date: 2020/12/15 11:47
*/
boolean supportsParameter(MethodParameter parameter);
/**
* 性能形容: 用于数据绑定解析申请参数
* 〈〉
* @Param:
* @Return:
* @Author: Steven
* @Date: 2020/12/15 11:47
*/
Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, NativeWebRequest webRequest, @Nullable WebDataBinderFactory binderFactory) throws Exception;
}
2、
public class SqlFilterArgumentResolver implements HandlerMethodArgumentResolver {
/**
* 性能形容: 判断 controller 申请参数中是否蕴含 CurrentUser
* 〈〉
* @Param:
* @Return:
* @Author: Steven
* @Date: 2020/12/15 11:47
*/
@Override
public boolean supportsParameter(MethodParameter parameter) {return parameter.getParameterType().equals(CurrentUser.class);
}
/**
* 性能形容: 获取获取申请体重的报文、解析
* 〈〉
* @Param:
* @Return:
* @Author: Steven
* @Date: 2020/12/15 11:47
*/
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
NativeWebRequest webRequest, WebDataBinderFactory binderFactory) {Optional.ofNullable(descs).ifPresent(s -> orderItemList.addAll( Arrays.stream(s).filter(sqlInjectPredicate()).map(OrderItem::desc).collect(Collectors.toList())));
}
/**
* 性能形容: 解决查问关键字
* 〈〉
* @Param:
* @Return:
* @Author: Steven
* @Date: 2020/12/15 11:47
*/
private Predicate<String> sqlInjectPredicate() {
return sql -> {for (String keyword : KEYWORDS) {if (StrUtil.containsIgnoreCase(sql, keyword)){return false;}
}
return true;
}
}
}
正文完
发表至: springboot
2020-12-15