Scope variables in spring/mybatis maps

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

...

Answers


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.

ComplexObject selectSomeObject(@Param("columnName") String columnName);

Your SQL map could use the parameter in part of the actual select code.

i.e.

<select id="selectSomeObject" resultType="someObject"> 
    select t1.column as ${columnName}    
    from table1 t1
 </select>

If you need a global variable, check out this question. MyBatis - defining a global parameter


Need Your Help

ActionBar not changing colour

android xml android-actionbar android-styles

I'm trying to test out changing the colour of the ActionBar, I've followed the answer of this question: How do I change the background color of the ActionBar of an ActionBarActivity using XML? but ...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.