拦截器:拦截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 处理查询参数及查询结果的更多相关文章

  1. odoo 11 实现多个字段对应一个查询参数的查询

    在整理英语单词开发模块的过程中,有这样一个需求,就是我在查询界面里输入一个查询的值A,这个A可能是下面的任何一个值 1.一个英语单词  2.汉语文字  3.一个英语单词的部分 这里有两张表:engli ...

  2. MyBatis基础入门《八》查询参数传入Map

    MyBatis基础入门<八>查询参数传入Map 描述: 在执行select查询数据的时候,方法传入的参数是java.util.Map类型. 接口方法: xml文件 注意: 书写SQL语句的 ...

  3. MyBatis基础入门《七》查询参数传入对象

    MyBatis基础入门<七>查询参数传入对象 描述: 在执行查询语句的时候,传入的参数是一个对象,依据对象的属性,进行检索数据.此时,书写SQL语句中的条件时,其参数需要和对象中的属性保持 ...

  4. Mybatis中多个参数的问题&&动态SQL&&查询结果与类的对应

    ### 1. 抽象方法中多个参数的问题 在使用MyBatis时,接口中的抽象方法只允许有1个参数,如果有多个参数,例如: Integer updatePassword( Integer id, Str ...

  5. mybatis报表,动态列与查询参数+行列转换

    这是报表原型,在这张报表中,使用了动态的列与动态查询参数,动态列与动态查询参数全部使用map将参数传入 map参数: //拼接查询时间 for (String month : monthList) { ...

  6. Mybatis 传入多个参数查询数据 (3种方法)

    第一种方案 DAO层的函数方法 public User selectUser(String name,String area); 对应的Mapper.xml <select id="s ...

  7. Mybatis高级查询之关联查询

    learn from:http://www.mybatis.org/mybatis-3/zh/sqlmap-xml.html#Result_Maps 关联查询 准备 关联结果查询(一对一) resul ...

  8. Mybatis高级查询之一对一查询的四种方法

    目录 1. 一对一查询 1.1 一对一嵌套结果查询 1.2 使用resultMap配置一对一映射 1.3 使用resultMap的association标签配置一对一映射 1.4 associatio ...

  9. mybatis的一对一,一对多查询,延迟加载,缓存介绍

    一对一查询 需求 查询订单信息关联查询用户信息 sql语句 /*通过orders关联查询用户使用user_id一个外键,只能关联查询出一条用户记录就可以使用内连接*/ SELECT orders.*, ...

随机推荐

  1. css圆角和阴影兼容问题(ie7,ie8)

    <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Conten ...

  2. 【题解】洛谷P1879 [USACO06NOV] Corn Fields(状压DP)

    洛谷P1879:https://www.luogu.org/problemnew/show/P1879 思路 把题目翻译成人话 在n*m的棋盘 每个格子不是0就是1 1表示可以种 0表示不能种 相邻的 ...

  3. CodeForces - 616C(很有意思的bfs,set,map的使用)

    传送门: http://codeforces.com/problemset/problem/616/C C. The Labyrinth time limit per test 1 second me ...

  4. Kubernetes对象模型

    原文发表于https://www.fangzhipeng.com/kubernetes/2018/10/13/k8s-object-model/ 欢迎访问我的方志朋的博客 Kubernetes对象 在 ...

  5. weex图片加载更多方法loadmore的使用

    首先,放一个weex中loadmore使用的demo,可以看一下http://dotwe.org/vue/8dd2a10c69e149ae8971f8298cc8bebf 1.在list标签上添加 @ ...

  6. BZOJ1023: [SHOI2008]cactus仙人掌图(仙人掌dp)

    Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 3467  Solved: 1438[Submit][Status][Discuss] Descripti ...

  7. Django在windows系统下安装详情

    1. Django 下载地址:https://www.djangoproject.com/download/ 2. 解压到跟python安装目录平级目录: 如下图: 3.通过cmd控制台安装djang ...

  8. springboot-自定义起步依赖

    自定义起步依赖步骤: 1.  添加configuration注解文件 -          指定什么情况下加载配置 -          使用enableconfigurationProperties ...

  9. Linux下Git远程仓库的使用详解

    Git远程仓库Github 提示:Github网站作为远程代码仓库时的操作和本地代码仓库一样的,只是仓库位置不同而已! 准备Git源代码仓库 https://github.com/ 准备经理的文件 D ...

  10. 用RestTemplate调取接口,取得返回数据,携带header,动态拼接url ,动态参数

    记录我自己的工作 get 请求  ,携带 请求头 header (token) url 根据参数 动态拼接 参数   放入 map  动态拼接 private String lclUrl = &quo ...