Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

only one parameter not use @param, may not work for DynamicSqlSource #1950

Closed
xiaolongzhao2015 opened this issue Jun 6, 2020 · 4 comments
Closed

Comments

@xiaolongzhao2015
Copy link

xiaolongzhao2015 commented Jun 6, 2020

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 selectOnlyIf(String entryDate);

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 ?

@kazuki43zoo
Copy link
Member

kazuki43zoo commented Jun 7, 2020

@xiaolongzhao2015

Could you try latest version (3.5.5)? Probably, this issue has been fixed since 3.5.2 via gh-1487.

@kazuki43zoo
Copy link
Member

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.

@xiaolongzhao2015
Copy link
Author

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

@kazuki43zoo
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants