如何通過(guò)配置自動(dòng)實(shí)現(xiàn)ValueList中hql語(yǔ)句的整型參數(shù)轉(zhuǎn)換
更新時(shí)間:2013年06月29日 15:33:11 作者:
本篇文章是對(duì)通過(guò)配置自動(dòng)實(shí)現(xiàn)ValueList中hql語(yǔ)句的整型參數(shù)轉(zhuǎn)換進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
通過(guò)valuelist的queryMap傳遞過(guò)來(lái)的參數(shù)默認(rèn)都為string類(lèi)型,在valuelist配置文件的hql中,如果直接將該值賦給整型的字段會(huì)報(bào)錯(cuò)。一般我們會(huì)在hql中利用轉(zhuǎn)型函數(shù)來(lái)進(jìn)行處理,如下:
<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>
該方法比較麻煩,在所有的整型字段地方都需要添加函數(shù)處理,并且進(jìn)行數(shù)據(jù)庫(kù)遷移時(shí)會(huì)出現(xiàn)函數(shù)不兼容的問(wèn)題??梢岳肰alueList配置來(lái)對(duì)整型的字段進(jìn)行統(tǒng)一設(shè)置,valuelist在拼裝sql前會(huì)對(duì)配置好的參數(shù)進(jìn)行轉(zhuǎn)型。如下:
<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>
復(fù)制代碼 代碼如下:
<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>
該方法比較麻煩,在所有的整型字段地方都需要添加函數(shù)處理,并且進(jìn)行數(shù)據(jù)庫(kù)遷移時(shí)會(huì)出現(xiàn)函數(shù)不兼容的問(wèn)題??梢岳肰alueList配置來(lái)對(duì)整型的字段進(jìn)行統(tǒng)一設(shè)置,valuelist在拼裝sql前會(huì)對(duì)配置好的參數(shù)進(jìn)行轉(zhuǎn)型。如下:
復(fù)制代碼 代碼如下:
<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>
相關(guān)文章
MySQL Union合并查詢(xún)數(shù)據(jù)及表別名、字段別名用法分析
這篇文章主要介紹了MySQL Union合并查詢(xún)數(shù)據(jù)及表別名、字段別名用法,結(jié)合實(shí)例形式較為詳細(xì)的分析了mysql使用Union合并連接查詢(xún)數(shù)據(jù)以及使用as實(shí)現(xiàn)表別名與字段別名操作,需要的朋友可以參考下2018-06-06

MySQL數(shù)據(jù)庫(kù)innodb啟動(dòng)失敗無(wú)法重啟的解決方法
這篇文章給大家分享了MySQL數(shù)據(jù)庫(kù)innodb啟動(dòng)失敗無(wú)法重啟的解決方法,通過(guò)總結(jié)自己遇到的問(wèn)題分享給大家,讓遇到同樣問(wèn)題的朋友們可以盡快解決,下面來(lái)一起看看吧。
2016-09-09 
MySQL如何通過(guò)Navicat實(shí)現(xiàn)遠(yuǎn)程連接
這篇文章主要介紹了MySQL如何通過(guò)Navicat實(shí)現(xiàn)遠(yuǎn)程連接,幫助大家更好的理解和使用MySQL數(shù)據(jù)庫(kù),感興趣的朋友可以了解下
2020-09-09 
Windows下mysql?8.0.28?安裝配置方法圖文教程
這篇文章主要為大家詳細(xì)介紹了Windows下mysql?8.0.28?安裝配置方法圖文教程,文中安裝步驟介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
2022-04-04 
mysql之查找所有數(shù)據(jù)庫(kù)中沒(méi)有主鍵的表問(wèn)題
這篇文章主要介紹了mysql之查找所有數(shù)據(jù)庫(kù)中沒(méi)有主鍵的表問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
2023-03-03 
mysql中關(guān)鍵詞exists的用法實(shí)例詳解
在mysql中exists用于檢查子查詢(xún)是否至少會(huì)返回一行數(shù)據(jù),該子查詢(xún)實(shí)際上并不返回任何數(shù)據(jù),而是返回true或false,下面這篇文章主要給大家介紹了關(guān)于mysql中關(guān)鍵詞exists用法的相關(guān)資料,需要的朋友可以參考下
2022-06-06 
解決Mysql主從錯(cuò)誤:could not find first log&nbs
這篇文章主要介紹了解決Mysql主從錯(cuò)誤:could not find first log file name in binary問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
2023-12-12