2

context:property-placeholder 是个好东西,但我不希望某些 bean 配置使用 placeholder

我只想使用 $ {num} 字符串的相同属性参数。

怎么做?

像:

<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>
4

1 回答 1

3

我对您的问题的理解是:您需要转义占位符标记

我认为您只能使用解决方法,我知道其中两个:

  • 更改占位符配置以使用文本中未使用的其他前缀和后缀

    <contextroperty-placeholder ....>
         ....
         <property name="placeholderPrefix" value="~{"/>
         <property name="placeholderSuffix" value="}" />
    </contextroperty-placeholder>
    
  • 在文本中使用 SpEL 表达式 (#{'$'}) 将前缀(应该没有前缀)分成两部分

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

    这第二个想法不是来自我,我在谷歌搜索后找到了它:http: //jazzjuice.blogspot.de/2011/06/escaping-property-placeholders-in.html

于 2012-04-21T09:22:41.410 回答