概述
在业务中如果dao层搭配了mybatis,那么通常会将一些业务查询写入到xml中,并且在过滤一些业务条件时会使用OGNL表达式
比如下面这段OGNL表达式
<iftest="null != params.applyTimeStart">and mpa.apply_time>=#{params.applyTimeStart}</if><iftest="null != params.applyTimeEnd">and mpa.apply_time<=#{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