From fa11eab71d3afe88c2f2ffb7eb30d480b7f3e988 Mon Sep 17 00:00:00 2001 From: lbw Date: Mon, 4 Mar 2024 22:06:15 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=E5=89=8D=E7=AB=AF=E6=8E=92?= =?UTF-8?q?=E5=BA=8F=E6=9D=A1=E4=BB=B6=E5=A4=B1=E6=95=88=20SqlFilterArgume?= =?UTF-8?q?ntResolver?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resolver/SqlFilterArgumentResolver.java | 87 ++++++++++--------- 1 file changed, 44 insertions(+), 43 deletions(-) diff --git a/pig-common/pig-common-mybatis/src/main/java/com/pig4cloud/pig/common/mybatis/resolver/SqlFilterArgumentResolver.java b/pig-common/pig-common-mybatis/src/main/java/com/pig4cloud/pig/common/mybatis/resolver/SqlFilterArgumentResolver.java index 7ebb3e322..fe0953a95 100644 --- a/pig-common/pig-common-mybatis/src/main/java/com/pig4cloud/pig/common/mybatis/resolver/SqlFilterArgumentResolver.java +++ b/pig-common/pig-common-mybatis/src/main/java/com/pig4cloud/pig/common/mybatis/resolver/SqlFilterArgumentResolver.java @@ -46,55 +46,56 @@ @Slf4j public class SqlFilterArgumentResolver implements HandlerMethodArgumentResolver { - /** - * 判断Controller是否包含page 参数 - * @param parameter 参数 - * @return 是否过滤 - */ - @Override - public boolean supportsParameter(MethodParameter parameter) { - return parameter.getParameterType().equals(Page.class); - } + /** + * 判断Controller是否包含page 参数 + * + * @param parameter 参数 + * @return 是否过滤 + */ + @Override + public boolean supportsParameter(MethodParameter parameter) { + return parameter.getParameterType().equals(Page.class); + } - /** - * @param parameter 入参集合 - * @param mavContainer model 和 view - * @param webRequest web相关 - * @param binderFactory 入参解析 - * @return 检查后新的page对象 - *

- * page 只支持查询 GET .如需解析POST获取请求报文体处理 - */ - @Override - public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, - NativeWebRequest webRequest, WebDataBinderFactory binderFactory) { + /** + * @param parameter 入参集合 + * @param mavContainer model 和 view + * @param webRequest web相关 + * @param binderFactory 入参解析 + * @return 检查后新的page对象 + *

+ * page 只支持查询 GET .如需解析POST获取请求报文体处理 + */ + @Override + public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, + NativeWebRequest webRequest, WebDataBinderFactory binderFactory) { - HttpServletRequest request = webRequest.getNativeRequest(HttpServletRequest.class); + HttpServletRequest request = webRequest.getNativeRequest(HttpServletRequest.class); - String[] ascs = request.getParameterValues("ascs"); - String[] descs = request.getParameterValues("descs"); - String current = request.getParameter("current"); - String size = request.getParameter("size"); + String[] ascs = request.getParameterValues("ascs"); + String[] descs = request.getParameterValues("descs"); + String current = request.getParameter("current"); + String size = request.getParameter("size"); - Page page = new Page<>(); - if (StrUtil.isNotBlank(current)) { - page.setCurrent(Long.parseLong(current)); - } + Page page = new Page<>(); + if (StrUtil.isNotBlank(current)) { + page.setCurrent(Long.parseLong(current)); + } - if (StrUtil.isNotBlank(size)) { - page.setSize(Long.parseLong(size)); - } + if (StrUtil.isNotBlank(size)) { + page.setSize(Long.parseLong(size)); + } - List orderItemList = new ArrayList<>(); - Optional.ofNullable(ascs) - .ifPresent(s -> orderItemList.addAll( - Arrays.stream(s).filter(SqlInjectionUtils::check).map(OrderItem::asc).collect(Collectors.toList()))); - Optional.ofNullable(descs) - .ifPresent(s -> orderItemList.addAll( - Arrays.stream(s).filter(SqlInjectionUtils::check).map(OrderItem::desc).collect(Collectors.toList()))); - page.addOrder(orderItemList); + List orderItemList = new ArrayList<>(); + Optional.ofNullable(ascs) + .ifPresent(s -> orderItemList.addAll( + Arrays.stream(s).filter(asc -> !SqlInjectionUtils.check(asc)).map(OrderItem::asc).collect(Collectors.toList()))); + Optional.ofNullable(descs) + .ifPresent(s -> orderItemList.addAll( + Arrays.stream(s).filter(desc -> !SqlInjectionUtils.check(desc)).map(OrderItem::desc).collect(Collectors.toList()))); + page.addOrder(orderItemList); - return page; - } + return page; + } }