Commit d49799fa by Jan Hrabal

wip

parent c4a30006
......@@ -16,12 +16,16 @@ import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Order;
import javax.persistence.criteria.Root;
import org.hibernate.query.NativeQuery;
import org.hibernate.query.criteria.internal.OrderImpl;
import org.springframework.util.StringUtils;
import com.jh.boot.web.list.Page;
import com.jh.boot.web.list.PagingInfo;
import com.jh.boot.web.list.SortTrend;
/**
......@@ -138,6 +142,10 @@ public abstract class AbstractHibernateRepository {
@SuppressWarnings("unchecked")
protected <T> Page<T> pagedCriteria(CriteriaBuilder cb, CriteriaQuery<T> cq, Root<T> root, PagingInfo pagingInfo) {
if (StringUtils.hasText(pagingInfo.getField())) {
cq.orderBy(new OrderImpl(root.get(pagingInfo.getField()), pagingInfo.getTrend() == SortTrend.ASCENDING));
}
Query query = entityManager.createQuery(cq);
query.setFirstResult(pagingInfo.getPage() * pagingInfo.getPageSize());
query.setMaxResults(pagingInfo.getPageSize());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment