本文介绍了标准addOrder按trim(字段)排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public List< Object> listEntry(final int rowNumMin,final int maxResult,
final String orderField,final int orderSort){
Criteria requete = getSession()。createCriteria(
getPersistentClass());
if(orderSort = 1){
requete.addOrder(Order.asc(orderField));
} else {
requete.addOrder(Order.desc(orderField));
}
requete.setMaxResults(maxResult);
requete.setFirstResult(rowNumMin);
final List< Object> resultat = requete.list();
返回结果;
}
这就好像
SELECT * FROM myTable ORDER BY orderField LIMIT rowNumMin,maxResult;
但我想获得
SELECT * FROM myTable ORDER BY TRIM(orderField)LIMIT rowNumMin,maxResult;
我该怎么做?
解决方案
您必须创建 org.hibernate.criterion.Order
的自定义子类,并覆盖 toSqlString
方法通过子句生成SQL 命令。
$ b
criteria.addOrder(new TrimOrder(orderField,true))
。
All is in this question, here is my method.
public List<Object> listEntry(final int rowNumMin, final int maxResult,
final String orderField, final int orderSort) {
final Criteria requete = getSession().createCriteria(
getPersistentClass());
if(orderSort=1){
requete.addOrder(Order.asc(orderField));
} else {
requete.addOrder(Order.desc(orderField));
}
requete.setMaxResults(maxResult);
requete.setFirstResult(rowNumMin);
final List<Object> resultat = requete.list();
return resultat;
}
This is like
SELECT * FROM myTable ORDER BY orderField LIMIT rowNumMin, maxResult;
but I would like to obtain
SELECT * FROM myTable ORDER BY TRIM(orderField) LIMIT rowNumMin, maxResult;
How can I do this ?
解决方案
You'll have to create a custom subclass of org.hibernate.criterion.Order
, and override the toSqlString
method to generate the SQL order by
clause you want.
And then use criteria.addOrder(new TrimOrder("orderField", true))
.
这篇关于标准addOrder按trim(字段)排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!