java - Mybatis If statements using include properties -


i'm trying create generic sql include in mybatis apply comparator given particular value. idea reuse sql code snippet across several mappers. issue i'm having when using string substitution in if statement inside of include.

currently xml looks this:

<select id="get" parametertype="servicemodelqueryhelper" resultmap="servicerecordmap">     select * service     <if test="name.isapplicable()">         service.name         <include refid=comparatormapper>             <property name="comparator" value="${name.comparator}"/>             <property name="value" value="${name.value}"/>         </include>     </if> </select> <sql id="comparatormapper">     <if test="${comparator} == 'equals'">         = ${value}     </if>     <if test="${comparator} == 'contains'">         ~ ${value}     </if> </sql> 

when using ${comparator} inside of test ognl expression evaluated before string substitution occures causing parseexception because $ not valid first character.

is there way reference property of sql snippet inside of ognl expression?

take @ mybatis docs. conditional statements donĀ“t require #,$ style references.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

Redirect to a HTTPS version using .htaccess -

Unlimited choices in BASH case statement -