Hibernate 实现Oracle的中文汉字按照拼音排序 之延续,通用的查询排序能力。
2013-05-31 16:27
766 查看
之前有写过oracle 结合hibernate支持拼音排序,优化一下,之前写的有一个小的bug,就是在重写了hibernate 的Order接口后,出现所有的字段都通过拼音排序,
导致时间、数字类型的排序都乱了,加一个判断,之正对string类型做拼音排序
原文地址:/article/2626666.html
修改后的代码如下
导致时间、数字类型的排序都乱了,加一个判断,之正对string类型做拼音排序
原文地址:/article/2626666.html
修改后的代码如下
package com.sencloud.dh.core.command; import org.hibernate.Criteria; import org.hibernate.HibernateException; import org.hibernate.criterion.CriteriaQuery; import org.hibernate.criterion.Order; import org.hibernate.type.Type; /** * 实现Oracle数据库中文字段按照拼音排序问题 <一句话功能简述> <功能详细描述> * * @author xutianlong * @version [版本号, Mar 5, 2013] * @see [相关类/方法] * @since [产品/模块版本] */ public class OracleOrder extends Order { private String propertyName; private boolean ascending; protected OracleOrder(String propertyName, boolean ascending) { super(propertyName, ascending); this.propertyName = propertyName; this.ascending = ascending; } /** * 只考虑按一个字段排序的情况 */ public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException { String[] columns = criteriaQuery.getColumnsUsingProjection(criteria, propertyName); Type propertyType= criteriaQuery.getTypeUsingProjection(criteria, propertyName);
//只有string类型支持拼音排序 if("string".equals(propertyType.getName())) { return " nlssort(" + columns[0] + ",'NLS_SORT=SCHINESE_PINYIN_M') " + (ascending ? "" : "desc"); } else { return super.toSqlString(criteria, criteriaQuery); } } public static OracleOrder getOrder(String propertyName, boolean ascending) { return new OracleOrder(propertyName, ascending); } }
相关文章推荐
- Hibernate 实现Oracle的中文汉字按照拼音排序
- oracle实现汉字按照拼音、笔画和部首排序
- ORACLE按照比划、部首和拼音排序的实现
- mysql 查询的时候处理中文汉字按照字母排序问题
- Oracle中实现查询结果按照in中条件排序 InStr函数
- 使用Oracle函数实现按汉字拼音首字母查询功能
- 使用ORACLE函数实现按汉字拼音首字母查询
- 查询中文按照拼音排序
- JS实现中文汉字按拼音排序的方法
- ORACLE按照比划、部首和拼音排序的实现(转)
- java中实现汉字按照拼音排序(示例代码)
- Oracle大文本查询 汉字按拼音排序
- 解决oracle排序时按照汉字拼音排序不正确的问题
- Oracle使用NLSSORT函数实现汉字的排序
- mysql中文排序(按照中文拼音顺序排序)
- 如何让数据库排序的时候按照中文的拼音来排序
- Android 对汉字字符串按照拼音排序 Java
- Android实现ListView的A-Z字母排序和过滤搜索功能,实现汉字转成拼音
- mysql中文字段排序( 按拼音首字母排序)的查询语句