try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) { ActionResult<List> result = new ActionResult<>(); Wi wi = this.convertToWrapIn(jsonElement, Wi.class); List ids = new ArrayList<>(); EntityManager em = emc.get(RecordReadLog.class); CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery cq = cb.createQuery(String.class); Root root = cq.from(RecordReadLog.class); Predicate p = cb.equal(root.get(RecordReadLog_.idRecord),wi.getIdRecord().trim()); if(wi.getStartTime() != null) { p = cb.and(p, cb.greaterThanOrEqualTo(root.get(RecordReadLog_.createTime), wi.getStartTime())); } if(wi.getEndTime()!= null) { p = cb.and(p, cb.lessThanOrEqualTo(root.get(RecordReadLog_.createTime), wi.getEndTime())); } Order order; String sortField = wi.getSortField(); String sortType = wi.getSortType(); if(!StringUtils.isBlank(sortField)) { if(sortType.equalsIgnoreCase("asc")) { order = cb.asc(root.get(sortField)); }else { order = cb.desc(root.get(sortField)); } }else { order = cb.desc(root.get("createTime")); } cq.select(root.get(RecordReadLog_.id)).where(p).orderBy(order); TypedQuery<String> typedQuery = em.createQuery(cq); int pageIndex = (page-1)*size; int pageSize = size; typedQuery.setFirstResult(pageIndex); typedQuery.setMaxResults(pageSize); ids = typedQuery.getResultList(); TypedQuery<String> tqCount = em.createQuery( cq.select(root.get(RecordReadLog_.id)).where(p)); List<String> allid = tqCount.getResultList(); Long tpsize = (long) allid.size(); CriteriaQuery<RecordReadLog> cqRecord = cb.createQuery(RecordReadLog.class); Predicate pRecord = cb.isMember(root.get(RecordReadLog_.id), cb.literal(ids)); Root<RecordReadLog> rootRecord = cqRecord.from(RecordReadLog.class); cqRecord.select(rootRecord).where(pRecord).orderBy(order); List<RecordReadLog> os = em.createQuery(cqRecord).getResultList(); List<Wo> wos = Wo.copier.copy(os); result.setData(wos); result.setCount(tpsize); return result; }
Anonymous:匿名访问权限
Cipher:这个应该是服务器之间访问权限
Manager:管理员访问权限
User:普通用户放权权限
wi:接收接口输入参数对象
wo:接口返回参数对象
参考:https://www.w3cschool.cn/java/jpa-entitymanager.html