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

相关推荐
考虑考虑21 小时前
Mybatis实现批量插入
java·后端·mybatis
敲个大西瓜14 天前
mybatis拦截器插件实现数据库字段加解密
mybatis
tianyuanwo14 天前
深入解析 RISC-V 虚拟化中的 UEFI 固件配置:从 XML 到 NVRAM 的生命周期管理
xml·linux·risc-v
武子康14 天前
Java-28 深入浅出 Spring 实现简易Ioc-04 在上节的业务下手动实现AOP
java·后端·mybatis
一条泥憨鱼14 天前
苍穹外卖【day6|微信登录与商品浏览功能】
后端·mybatis·苍穹外卖
vx-Biye_Design14 天前
springboot安阳地区研学旅游服务小程序-计算机毕业设计源码12785
java·vue.js·windows·spring boot·tomcat·maven·mybatis
摇滚侠15 天前
MyBatis+Spring+SpringMVC SSM 整合 179-185
java·spring·mybatis
摇滚侠15 天前
MyBatis+Spring+SpringMVC SSM ContextLoaderListener 177-178
java·spring·mybatis
Spring小子15 天前
【Spring Boot + Vue + DeepSeek】从零打造一个AI驱动的智能健康分析系统
java·spring boot·mybatis