spring aop 解决模糊查询参数 % - /等特殊符号问题
import com.hsq.common.utils.StringUtil;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component; import java.lang.reflect.Field; @Component
@Aspect
public class FuzzyQueryAspect { @Around("@annotation(com.hsq.common.aop.FuzzyQuery)")
public Object proceed(ProceedingJoinPoint joinPoint)
throws Throwable {
Object[] args = joinPoint.getArgs();
for (Object arg : args) {
Field[] fields = arg.getClass().getDeclaredFields();
for (Field field : fields) {
FuzzyQuery fuzzyQuery = field.getAnnotation(FuzzyQuery.class);
if (fuzzyQuery != null) {
field.setAccessible(true);
String value = field.get(arg) == null ? null : String.valueOf(field.get(arg));
value = StringUtil.escapeSpecialChar(value);
field.set(arg, value);
}
}
}
return joinPoint.proceed();
} }
StringUtil
public static String escapeSpecialChar(String keyword){
log.info("input:"+keyword);
if (StringUtils.isNotBlank(keyword)) {
String[] fbsArr = { "\\", "$", "|","%","_" , "(", ")", "*", "+", ".", "[", "]", "?", "^", "{", "}"};
for (String key : fbsArr) {
if (keyword.contains(key)) {
log.info("escapeSpecialChar:"+key);
keyword = keyword.replace(key, "\\" + key);
}
}
}
log.info("output:"+keyword);
return keyword;
}
@Target({ElementType.FIELD,ElementType.PARAMETER,ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface FuzzyQuery {
}
使用
@FuzzyQuery
private String keyWord;//关键字查询 controller也加上@FuzzyQuery
spring aop 解决模糊查询参数 % - /等特殊符号问题的更多相关文章
- Spring AOP切面的时候参数的传递
Spring AOP切面的时候参数的传递 Xml: <?xml version="1.0" encoding="UTF-8"?> <beans ...
- spring aop通过joinpoint传递参数
三.总结. 我们可以通过Advice中添加一个JoinPoint参数,这个值会由spring自动传入,从JoinPoint中可以取得. 三.总结. 我们可以通过Advice中添加一个JoinPoint ...
- 使用Spring AOP预处理Controller的参数
实际编程中,可能会有这样一种情况,前台传过来的参数,我们需要一定的处理才能使用,比如有这样一个Controller @Controller public class MatchOddsControll ...
- spring aop 利用JoinPoint获取参数的值和方法名称
AspectJ使用org.aspectj.lang.JoinPoint接口表示目标类连接点对象,如果是环绕增强时,使用org.aspectj.lang.ProceedingJoinPoint表示连接点 ...
- Spring Aop 修改目标方法参数和返回值
一.新建注解 @Target({ElementType.METHOD, ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) @Document ...
- Spring AOP获取方法的参数名称和参数值
aop配置: <aop:aspectj-autoproxy expose-proxy="true" /> @Before(value = "execution ...
- Spring Aop——给Advice传递参数
给Advice传递参数 Advice除了可以接收JoinPoint(非Around Advice)或ProceedingJoinPoint(Around Advice)参数外,还可以直接接收与切入点方 ...
- 解决模糊查询问题 element UI 从服务器搜索数据,输入关键字进行查找
做项目是遇见下拉框的形式,后台返回来3万多条,用element UI中的select选择器中的搜索还是会造成页面卡顿和系统崩溃,因此用了它的远程搜索功能,发现还不错,解决了这个问题. 代码1 < ...
- Spring Data MongoDB 模糊查询
Pattern pattern = Pattern.compile("^.*" + value + ".*$"); Query query = new Quer ...
随机推荐
- 数据库root密码删除
1 打开mysql.exe和mysqld.exe所在的文件夹,复制路径地址 2 打开cmd命令提示符,进入上一步mysql.exe所在的文件夹. 3 输入命令 mysqld --skip-g ...
- 从零开始实现放置游戏(十)——实现战斗挂机(1)hessian服务端搭建
前面实现RMS系统时,我们让其直接访问底层数据库.后面我们在idlewow-game模块实现游戏逻辑时,将不再直接访问底层数据,而是通过hessian服务暴露接口给表现层. 本章,我们先把hessia ...
- scala刷LeetCode--26 删除排序数组中的重复项
一.题目描述 给定一个排序数组,你需要在原地删除重复出现的元素,使得每个元素只出现一次,返回移除后数组的新长度. 不要使用额外的数组空间,你必须在原地修改输入数组并在使用 O(1) 额外空间的条件下完 ...
- P2344 奶牛抗议 离散化+前缀和+动态规划+树状数组
[题目背景] Generic Cow Protests, 2011 Feb [题目描述] 约翰家的N 头奶牛正在排队游行抗议.一些奶牛情绪激动,约翰测算下来,排在第i 位的奶牛的理智度为Ai,数字可正 ...
- Java底层技术系列文章-总揽
对于工作中经常用到的东西,还是多看看实现原理,这样用着才能放心. 源码思想学习计划: 1.java基础库 HashCode深入理解 java线程框架窥探 2.集合类 java枚举类使用 递归 ...
- [Lydsy2017年4月月赛]抵制克苏恩题解
考试的时候以为就是简单的概率期望题,考完后知道是简单的概率期望DP题,完美爆零. 这道题数据范围很小,很容易让人想到状压,不过貌似没什么可压的.那么只能说明这道题复杂度很高了,状态数组f[o][i][ ...
- Lake Counting-C++
Description Due to recent rains, water has pooled in various places in Farmer John's field, which is ...
- 【DFS例题】等式
题目如下: 这道题依然是一道dfs(要求输出方案数很明显用dfs呐) 首先一个模板贴上来: void dfs()//参数用来表示状态 { if(到达终点状态) { ...//根据题意添加 return ...
- 洛谷 P2671 求和
题目描述 一条狭长的纸带被均匀划分出了nn个格子,格子编号从11到nn.每个格子上都染了一种颜色color\_icolor_i用[1,m][1,m]当中的一个整数表示),并且写了一个数字number\ ...
- local class incompatible: stream classdesc serialVersionUID = 4125096758372084309, local class serialVersionUID = 7725746634795906143
local class incompatible: stream classdesc serialVersionUID = 4125096758372084309, local class seria ...