feilong
feilong

Reputation: 731

context:property-placeholder is a good thing, but I do not want some bean configuration to use placeholder

context:property-placeholder is a good thing, but I do not want some bean configuration to use placeholder

same property parameters that I just want to use the $ {num} string.

How to do?

like:

<bean id="Sku.findSkuRelationByCategory" class="loxia.dao.support.DynamicQueryHolder">
    <constructor-arg>
        <value>
    <![CDATA[select 
    r.sku_id as sku_id,
    r.sku_category_id as sku_category_id
                from t_ma_sc_sku_relation r
                where r.sku_id in(#foreach($num in [1..$skuCount]) #if($num == 1) :s${num} #else ,:s${num} #end #end)
                and r.sku_category_id in(#foreach($num in [1..$categoryCount]) #if($num == 1) :c${num} #else ,:c${num} #end #end)
                order by sku_category_id]]>
        </value>
    </constructor-arg>
</bean>

Upvotes: 2

Views: 1565

Answers (1)

Ralph
Ralph

Reputation: 120761

My understanding of you problem is: you need to escape the placeholder marker

I think you can use only workarrounds, I know two of them:

  • Change the placeholder configuration to use other pre and postfixes that are not used in your text

    <contextroperty-placeholder ....>
         ....
         <property name="placeholderPrefix" value="~{"/>
         <property name="placeholderSuffix" value="}" />
    </contextroperty-placeholder>
    
  • Use an SpEL expressin (#{'$'}) in your text to slice the prefix (that should be no prefix) in two parts

    <value>...#if($num == 1) :s#{'$'}num} #else ,:s#{'$'}num} #end #end)....</value>
    

    This second idea is not from me, I found it after some googling: http://jazzjuice.blogspot.de/2011/06/escaping-property-placeholders-in.html

Upvotes: 3

Related Questions