如何通过配置自动实现ValueList中hql语句的整型参数转换
时间:2024-01-24 14:59:21
通过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>
标签:ValueList,hql语句,整型参数转换
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python 阶乘详解
2022-01-16 13:56:00
![](https://img.aspxhome.com/file/2023/1/66871_0s.png)
Python中新式类与经典类的区别详析
2022-02-04 05:11:16
最简洁的asp多重查询的解决方案
2011-04-15 10:50:00
使用Pyparsing处理复杂文本实现过程
2023-03-21 13:37:44
亚马逊购物用户体验分析 (一)
2009-10-25 12:40:00
![](https://img.aspxhome.com/file/UploadPic/200910/25/thumb2-70.jpg)
Python中win32com模块的使用
2021-01-22 11:46:52
python绘图subplots函数使用模板的示例代码
2023-05-23 06:05:01
![](https://img.aspxhome.com/file/2023/9/103779_0s.jpg)
python实现连连看游戏
2021-12-02 00:25:10
Python Flask框架模板操作实例分析
2022-09-21 02:56:23
![](https://img.aspxhome.com/file/2023/0/84060_0s.png)
利用Python实现智能合约的示例详解
2022-04-06 00:45:23
聊聊Python pandas 中loc函数的使用,及跟iloc的区别说明
2023-08-11 09:11:36
![](https://img.aspxhome.com/file/2023/8/99268_0s.jpg)
BeautifulSoup中find和find_all的使用详解
2023-11-08 21:00:22
![](https://img.aspxhome.com/file/2023/4/93514_0s.png)
利用python实现查看溧阳的摄影圈
2021-09-05 21:33:16
![](https://img.aspxhome.com/file/2023/0/77000_0s.webp)
jupyter notebook oepncv 显示一张图像的实现
2022-03-26 20:09:19
![](https://img.aspxhome.com/file/2023/5/104945_0s.jpg)
你知道mysql哪些查询情况不走索引吗
2024-01-15 06:32:00
python爬虫基础教程:requests库(二)代码实例
2023-05-31 07:56:35
数据库工具sysbench安装教程和性能测试例子
2024-01-28 06:00:42
SQL Server数据库对上亿表的操作
2008-11-16 18:13:00
Dhtml网页实例教程
2007-10-09 13:39:00
在Python中使用SimpleParse模块进行解析的教程
2021-04-11 12:17:53