加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MySql教程 > 正文

Mysql实例如何通过配置自动实现ValueList中hql语句的整型参数转

发布时间:2020-12-12 02:40:08 所属栏目:MySql教程 来源:网络整理
导读:《Mysql实例如何通过配置自动实现ValueList中hql语句的整型参数转换》要点: 本文介绍了Mysql实例如何通过配置自动实现ValueList中hql语句的整型参数转换,希望对您有用。如果有疑问,可以联系我们。 通过valuelist的queryMap传递过来的参数默认都为string类

《Mysql实例如何通过配置自动实现ValueList中hql语句的整型参数转换》要点:
本文介绍了Mysql实例如何通过配置自动实现ValueList中hql语句的整型参数转换,希望对您有用。如果有疑问,可以联系我们。

通过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>

欢迎参与《Mysql实例如何通过配置自动实现ValueList中hql语句的整型参数转换》讨论,分享您的想法,编程之家PHP学院为您提供专业教程。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读