通過valuelist的queryMap傳遞過來的參數默認都為string類型,在valuelist配置文件的hql中,如果直接將該值賦給整型的字段會報錯。一般我們會在hql中利用轉型函數來進行處理,如下:
復制代碼 代碼如下:
<entry key="areasInfoAdapter">
<bean parent="abstractHibernate30Adapter">
<property name="defaultNumberPerPage"><value>19</value></property>
<property name="statementBuilder"><ref bean="statementBuilderHql"/></property>
<property name="defaultSortColumn"><value>id</value></property>
<property name="defaultSortDirection"><value>desc</value></property>
<property name="hql">
<value>
from com.berheley.hcms.persistence.model.TBaseAreas as tb
where tb.status='1'
/~hId : and tb.hId = to_number{hId} ~/
/~oId : and tb.oId = to_number{oId} ~/
order by tb.code asc
</value>
</property>
<property name="defaultFocusPropertyObjectAlias"><value>vo</value></property>
<property name="maxRowsForFocus"><value>160000</value></property>
<property name="removeEmptyStrings"><value>true</value></property>
</bean>
</entry>
該方法比較麻煩,在所有的整型字段地方都需要添加函數處理,並且進行數據庫遷移時會出現函數不兼容的問題。可以利用ValueList配置來對整型的字段進行統一設置,valuelist在拼裝sql前會對配置好的參數進行轉型。如下:
復制代碼 代碼如下:
<bean id="integerSetterHql" class="net.mlw.vlh.adapter.hibernate3.util.setter.IntegerSetter"></bean>
<bean id="statementBuilderHql" class="net.mlw.vlh.adapter.hibernate3.util.StatementBuilder">
<property name="setters">
<map>
<entry key="uId"><ref bean="integerSetterHql"/></entry>
<entry key="oId"><ref bean="integerSetterHql"/></entry>
</map>
</property>
</bean>