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

相关推荐
misL NITL1 天前
idea、mybatis报错Property ‘sqlSessionFactory‘ or ‘sqlSessionTemplate‘ are required
tomcat·intellij-idea·mybatis
是宇写的啊1 天前
MyBatis-Plus
java·开发语言·mybatis
工作log2 天前
Spring Boot 3.5 + MyBatis Plus + RabbitMQ:打造 AI 驱动的慢 SQL 监控与优化系统
spring boot·mybatis·java-rabbitmq
不会编程的懒洋洋2 天前
WPF XAML+布局+控件
xml·开发语言·c#·视觉检测·wpf·机器视觉·视图
河阿里2 天前
MyBatis-Plus:MyBatis的进阶开发
数据库·mybatis
橙子圆1232 天前
Mybatis之动态sql
sql·tomcat·mybatis
冷小鱼3 天前
MyBatis 与 MyBatis-Plus:从入门到精通的完整指南
java·tomcat·mybatis
香香甜甜的辣椒炒肉3 天前
SpringMVC高级应用和MyBatis-Plus的概念和使用
mybatis
鸡蛋灌Bean3 天前
mybatis分页深入了解
java·数据库·mybatis
鸽芷咕4 天前
KingbaseES数据类型完全指南:从基础CHAR到JSON/XML/几何类型
xml·oracle·json