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

相关推荐
憧憬成为web高手9 小时前
皮卡丘靶场速通--sql 2
数据库·sql·mybatis
IT_Octopus19 小时前
一次由 RestTemplate 引发的 Connection reset:被 XML 截胡的请求体
xml·java·spring boot
Dontla20 小时前
网站爬虫控制策略介绍(robots.txt、sitemap.xml、x-robots-tag、noindex、nofollow)网站索引
xml·爬虫·dubbo
Java面试题总结2 天前
mybatis插件
java·tomcat·mybatis
风起洛阳@不良使2 天前
spring中xml和注解开发的对比
xml·java·spring
Devin~Y3 天前
互联网大厂Java面试实战:Spring Boot、MyBatis、Redis、Kafka、JWT、Spring Cloud 与 AI 场景追问
java·spring boot·redis·spring cloud·kafka·mybatis·spring security
Ethan01073 天前
mybatis插件
mybatis
Mikowoo0073 天前
批量汇总XML格式的发票信息
xml·python
逃逸线LOF3 天前
xml文件如何加载properties文件(spring容器加载properties文件)
xml
扎Zn了老Fe3 天前
MyBatis-Plus必知必会:告别低效CRUD,高效开发持久层
后端·mybatis