PaginatorQueryHelper.java 文件源码

java
阅读 35 收藏 0 点赞 0 评论 0

项目:ismartonline 作者:
/**
 * 
 * @param manager {@link EntityManager} to create the query
 * @param klass klass to guess the list query and count query
 * @param currentPage 
 * @param max max number of elements
 * @return
 */
public <T> PaginatedList list(EntityManager manager, Class<T> klass,
      int currentPage, int max)
{

   if (!klass.isAnnotationPresent(Entity.class))
   {
      throw new IllegalArgumentException("Your entity is not annotated with @Entity");
   }

   TypedQuery<T> listQuery = manager.createQuery(
         "select o from " + klass.getSimpleName() + " o", klass);

   TypedQuery<Number> countQuery = manager.createQuery(
         "select count(1) from " + klass.getSimpleName() + " o",
         Number.class);

   return list(listQuery, countQuery, currentPage, max);
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号