mybatis在xml中使用OGNL取值简述

概述

在业务中如果dao层搭配了mybatis,那么通常会将一些业务查询写入到xml中,并且在过滤一些业务条件时会使用OGNL表达式

比如下面这段OGNL表达式

java 复制代码
<if test="null != params.applyTimeStart">
    and mpa.apply_time >= #{params.applyTimeStart}
</if>

<if test="null != params.applyTimeEnd">
    and mpa.apply_time &lt;= #{params.applyTimeEnd}
</if>

可以看到在表达式中是通过xxx.xxx的方式取值的;

先说结论,通过get方法获取的值

org.apache.ibatis.reflection.Reflector#getGetInvoker

mybatis:3.5.10

源码分析

思路大致是先从外层查询进去,然后一路debug进去;

我的查询入口是个分页查询,我在中间源码setParameters处打了个断点

com.baomidou.mybatisplus.core.MybatisParameterHandler#setParameters

然后一路往下跟踪到BeanWrapper中的metaClass.getGetInvoker方法,在其中看到了查询get方法的逻辑

org.apache.ibatis.reflection.wrapper.BeanWrapper#getBeanProperty

获取get方法的逻辑

org.apache.ibatis.reflection.Reflector#getGetInvoker

相关推荐
色空大师1 天前
mybatis动态sql
sql·mybatis·foreach·where·sql动态语法
BD_Marathon1 天前
自定义映射resultMap——通过collection解决一对多的映射关系(九)
mybatis
码农幻想梦1 天前
实验四 mybatis动态sql及逆向工程
sql·性能优化·mybatis
小北方城市网1 天前
SpringBoot 集成 MyBatis-Plus 实战(高效 CRUD 与复杂查询):简化数据库操作
java·数据库·人工智能·spring boot·后端·安全·mybatis
码农幻想梦1 天前
实验三 Mybatis多表查询操作
mybatis
cab51 天前
MyBatis如何处理数据库中的JSON字段
数据库·json·mybatis
小北方城市网1 天前
SpringBoot 安全认证实战(Spring Security + JWT):打造无状态安全接口体系
数据库·spring boot·后端·安全·spring·mybatis·restful
Z_W_H_1 天前
MyBatis-Plus 详细学习文档
学习·mybatis
程序员侠客行1 天前
Mybatis插件原理及分页插件
java·后端·架构·mybatis
qqqahhh2 天前
xml文件的动态化配置,导入
xml·spring·springboot