I have a conversationScope.myVar=”myValue” variable;
I would like to use it inside a mybatis map such as,
select col1, col1, conversationScope.myVar as ScopeVar
from table1;
desired result
col1 col2 ScopeVar
xxxx xxxx myValue
yyyy yyyy myValue
...
MyBatis does support dynamic SQL in the nature you need. The big trick, is to use ${variable} instead of #{variable}. Just be careful, it leaves you susceptible to SQL injection attacks. When using # MyBatis uses PreparedStatements to avoid SQL injection, and then
So take for example example, you had a Mapper interface with method.
Your SQL map could use the parameter in part of the actual select code.
i.e.
If you need a global variable, check out this question. MyBatis – defining a global parameter