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.*, ...
随机推荐
- HDU 1078 FatMouse and Cheese ( DP, DFS)
HDU 1078 FatMouse and Cheese ( DP, DFS) 题目大意 给定一个 n * n 的矩阵, 矩阵的每个格子里都有一个值. 每次水平或垂直可以走 [1, k] 步, 从 ( ...
- CI框架下 ajax分页
用做于商品详情页的评论展示: html: <script> var commodityid=<?php echo $info['commodity_id'] ?>; var u ...
- 【微信开发】微信开发模式 api 接口文档简介
微信公众平台分为订阅号和服务号,服务号提供9大接口,需要通过微信认证后才能使用这些接口.认证费用300元.下面是接口的大致介绍: 1. 语音识别:通过语音识别接口,用户发送的语音,将会同时给出语音识别 ...
- Swift_可选链
Swift_可选链 点击查看源码 //可选链 func test() { class Person { //可选属性可能为nil或Residence类 var residence: Residence ...
- 浅析MySQL主从复制技术(异步复制、同步复制、半同步复制)
Preface As we all know,there're three kinds of replication in MySQL nowadays.Such as,asynchr ...
- springboot(2.0以上) --数据源切换时报错
在进行数据源切换时spring.datasource.type类型根据源码所给的默认值修改后依然报错 先看源码:标色部分 , 就是springboot所给的数据源 , 正常来说只要在配置文件中修改 ...
- mysql启动错误处理
1.当启动MySQL时,报如下错误 [ERROR] Plugin 'InnoDB' init function returned error.[ERROR] Plugin 'InnoDB' regis ...
- centos总结linux下svn安装与使用
一.安装篇 centos下yum安装 yum install subversion 查看安装是否成功: svnserve --version 查看安装内容与位置 rpm -ql subversion ...
- Mysql 关于处理NULL值的相关函数和操作符
操作符 <=> NULL-safe equal. This operator performs an equality comparison like the = operator, bu ...
- tp js结合时间戳
$(document).ready(function(){ $.extend({ show:function(){ } }); setInterval("show()",1000) ...