我有一个conversationScope。myvar# ="括号"变量;
我想在mybatis map中使用它,例如
select col1, col1, conversationScope.myVar as ScopeVar
from table1;
desired result
col1 col2 ScopeVar
xxxx xxxx myValue
yyyy yyyy myValue
...
MyBatis确实支持您所需要的动态SQL。最大的技巧是使用${variable}而不是#{variable}。只是要小心,它使您容易受到SQL注入攻击。当使用# MyBatis使用PreparedStatements来避免SQL注入,然后
举个例子,你有一个Mapper接口带有方法。
ComplexObject selectSomeObject(@Param("columnName") String columnName);
您的SQL映射可以在实际选择代码的一部分中使用该参数。
。
<select id="selectSomeObject" resultType="someObject">
select t1.column as ${columnName}
from table1 t1
</select>
如果您需要一个全局变量,请查看这个问题。MyBatis -定义一个全局参数