MyBatis version 3.4.6
Database vendor and version 5.7.20
i has a question in mybatis:3.4.6;
the sql refer method
List
when our sql has only one parameter, it't not must to add @Param annotation; as follow, this run ok,
SELECT * from tb_userInfo
where entry_date = #{entryDate}
order by id desc
is's because when runing,in MapperMethod.convertArgsToSqlCommandParam inner, it jude, when don't have @Param and paramCount=1, it's return origin parameterObject;
but,when my SQL change as follow:
SELECT *
from tb_userInfo
where
<if test="entryDate!=null">
entry_date = #{entryDate}
</if>
order by id desc
this sql will change to dynamic; when DynamicSqlSource => rootSqlNode.apply(context); rootSqlNode while contain four SqlNode: StaticTextSqlNode,StaticTextSqlNode,IfSqlNode,StaticTextSqlNode
when IfSqlNode apply: evaluator.evaluateBoolean(test, context.getBindings())) here it real like: evaluator.evaluateBoolean("entryDate!=null", context.getBindings()))
DynamicContext has two key: _parameter: ? _databaseId: null MetaObject parameterMetaObject,here,it's string;
OGNL.getValue, can't find any key for entryDate,will thrown error;
So, only one parameter not use @param can use for RawSqlSource, but not apply for DynamicSqlSource, this design, is a problem or we use it in the wrong way ?
Comment From: kazuki43zoo
@xiaolongzhao2015
Could you try latest version (3.5.5)? Probably, this issue has been fixed since 3.5.2 via gh-1487.
Comment From: kazuki43zoo
If you cannot upgrade to 3.5.2+, you need to use the _parameter
instead of argument name like as _parameter!=null
. By the way, we have no plan that backport gh-1487 to 3.4.x line.
Thanks.
Comment From: xiaolongzhao2015
thank you very much for so rapid response; i just pull the newest version 3.5.5, and look. and run test; it' ok; and is there any new features introduce when every new version publish, i want to follow and study, because i study code just for version 3.4.6, when new version, i can diff new features and to study
Comment From: kazuki43zoo
In latest version, there are many enhancements from 3.4.x. I suggest to confirm a release note on GitHub about new features and enhancements.
- https://github.com/mybatis/mybatis-3/releases