[英]Scope variables in spring/mybatis maps
我有一個對話范圍.myVar =“ myValue”變量;
我想在mybatis地圖中使用它,例如,
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-定義全局參數
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.