mybatis interceptor 处理查询参数及查询结果
拦截器:拦截update,query方法,处理查询参数及返回结果。
/**
* Created by windwant on 2017/1/12.
*/
@Intercepts({
@Signature(type=Executor.class,method="update",args={MappedStatement.class,Object.class}),
@Signature(type=Executor.class,method="query",args={MappedStatement.class,Object.class,RowBounds.class,ResultHandler.class})
})
public class EncryptInterceptor implements Interceptor {
public static final Logger logger = LoggerFactory.getLogger(EncryptInterceptor.class); @Override
public Object intercept(Invocation invocation) throws Throwable {
dealParameter(invocation);
Object returnValue = invocation.proceed();
dealReturnValue(returnValue);
return returnValue;
} //查询参数加密处理
private void dealParameter(Invocation invocation) {
MappedStatement statement = (MappedStatement) invocation.getArgs()[0];
String mapperl = ConfigUtils.get("mybaits.mapper.path");
String methodName = statement.getId().substring(statement.getId().indexOf(mapperl) + mapperl.length() + 1);
if (methodName.startsWith("UserBaseMapper")){
if(methodName.equals("UserBaseMapper.updateDriver")){
((Driver) invocation.getArgs()[1]).encrypt();
}
}
logger.info("Mybatis Encrypt parameters Interceptor, method: {}, args: {}", methodName, invocation.getArgs()[1]);
} //查询结果解密处理
private void dealReturnValue(Object returnValue){
if(returnValue instanceof ArrayList<?>){
List<?> list = (ArrayList<?>)returnValue;
for(Object val: list){
if(val instanceof Passenger){///
//TODO
}
logger.info("Mybatis Decrypt result Interceptor, result object: {}", ToStringBuilder.reflectionToString(val));
}
}
} @Override
public Object plugin(Object target) {
return Plugin.wrap(target, this);
} @Override
public void setProperties(Properties properties) { }
}
添加xml配置:
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="typeAliasesPackage" value="com.xx.model"/>
<property name="dataSource" ref="dataSource"/>
<!-- 自动扫描mapping.xml文件 -->
<property name="mapperLocations" value="classpath*:mybatis/*.xml"></property>
<property name="plugins">//拦截器插件
<array>
<bean class="com.github.pagehelper.PageHelper">
<property name="properties">
<value>dialect=hsqldb</value>
</property>
</bean>
<bean class="com.xx.interceptor.EncryptInterceptor">
<property name="properties">
<value>property-key=property-value</value>
</property>
</bean>
</array>
</property>
</bean>
mybatis interceptor 处理查询参数及查询结果的更多相关文章
- odoo 11 实现多个字段对应一个查询参数的查询
在整理英语单词开发模块的过程中,有这样一个需求,就是我在查询界面里输入一个查询的值A,这个A可能是下面的任何一个值 1.一个英语单词 2.汉语文字 3.一个英语单词的部分 这里有两张表:engli ...
- MyBatis基础入门《八》查询参数传入Map
MyBatis基础入门<八>查询参数传入Map 描述: 在执行select查询数据的时候,方法传入的参数是java.util.Map类型. 接口方法: xml文件 注意: 书写SQL语句的 ...
- MyBatis基础入门《七》查询参数传入对象
MyBatis基础入门<七>查询参数传入对象 描述: 在执行查询语句的时候,传入的参数是一个对象,依据对象的属性,进行检索数据.此时,书写SQL语句中的条件时,其参数需要和对象中的属性保持 ...
- Mybatis中多个参数的问题&&动态SQL&&查询结果与类的对应
### 1. 抽象方法中多个参数的问题 在使用MyBatis时,接口中的抽象方法只允许有1个参数,如果有多个参数,例如: Integer updatePassword( Integer id, Str ...
- mybatis报表,动态列与查询参数+行列转换
这是报表原型,在这张报表中,使用了动态的列与动态查询参数,动态列与动态查询参数全部使用map将参数传入 map参数: //拼接查询时间 for (String month : monthList) { ...
- Mybatis 传入多个参数查询数据 (3种方法)
第一种方案 DAO层的函数方法 public User selectUser(String name,String area); 对应的Mapper.xml <select id="s ...
- Mybatis高级查询之关联查询
learn from:http://www.mybatis.org/mybatis-3/zh/sqlmap-xml.html#Result_Maps 关联查询 准备 关联结果查询(一对一) resul ...
- Mybatis高级查询之一对一查询的四种方法
目录 1. 一对一查询 1.1 一对一嵌套结果查询 1.2 使用resultMap配置一对一映射 1.3 使用resultMap的association标签配置一对一映射 1.4 associatio ...
- mybatis的一对一,一对多查询,延迟加载,缓存介绍
一对一查询 需求 查询订单信息关联查询用户信息 sql语句 /*通过orders关联查询用户使用user_id一个外键,只能关联查询出一条用户记录就可以使用内连接*/ SELECT orders.*, ...
随机推荐
- $Yeasion$的码风修改历程
总之,今天是一个值得纪念的伟大日子,我将自己的码风进行了彻底的修改,大概是参考了Pks和\(Rqy\)的码风,分为以下几点. 1.变量名.在所有的计算符号之前和之后加空格.如:"&& ...
- wshShell.SendKeys模拟键盘操作
Dim wshShellSet wshShell = CreateObject("Wscript.Shell")wshShell.SendKeys "{ENTER}&qu ...
- 使你的ActiveX控件执行时不弹出安全性提示(转载)
我们编写一个ActiveX控件在IE中运行,一般会弹出一个安全提示,如何避免这种情况?下面是我在参考前人的文章后,总结出“在浏览器中执行时不弹出警告的ActiveX控件”的两种编写方法,予以备忘.注意 ...
- 5.同步关键字(synchronized)
同步关键字(synchronized): 多线程给我们提供方便的时候,也给整个编程增加了难度,尤其是对临界资源的控制,尤为重要. 一个在操作系统课上,老掉牙的事例,就把这种情况解释的明明白白. 一对夫 ...
- OpenID Connect Core 1.0(二)ID Token
2.ID Token(ID Token) OpenID Connect主要是对OAuth 2.0 能够使得终端用户通过ID Token的数据结构进行验证.当客户端和潜在的其他请求声明,ID Token ...
- 【Linux资源管理】使用sar进行性能分析
sar可用于监控Linux系统性能,帮助我们分析性能瓶颈.sar工具的使用方式为”sar [选项] intervar [count]”,其中interval为统计信息采样时间,count为采样次数. ...
- Colored Boots题解
题目来自Codeforce 1141Dhttp://codeforces.com/problemset/problem/1141/D 因为是全英文题面,就先简单的阐述一下题面. 首先输入一个数n,然后 ...
- percona数据库监控工具的安装部署
Percona Monitoring and Management 安装 PMM是一个开源,免费的mysql管理监控平台,他可以用来分析mysql,mariadb和mongodb的服务器性能. 安装步 ...
- php与java
作者:eechen链接:https://www.zhihu.com/question/20377398/answer/141328982来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转 ...
- vue组件间传值详解
1.父传子----传值要点: <1> 在组件注册的时候必须要使用 return 去返回 data对象;