Several ways to take on Spring JPA queries and handle page 01
4) Page processing
Java code * * * * * * * * * * * * * * * *
1. “100%” cellspacing=”0″ cellpadding=”0″>
2.
3. class=”Train_Resultlist-item”>
4. “50”>NO.
5.
6.
7.
8.
9.
10.
11. “item” items=”${itemList}” varStatus=”s”>
12.
13.
14.
15.
16.
22.
23.
24.
25.
26. “4” >
27. class=”green-black”>
${totalCount} ${totalCount}
Href =””
30. if test=”${currentPage le 1}” var=”syy”>
31. “previous” href=”#”> Previous
32. if>
33. if test=”${! syy}”>
34. “previous” href=””> Previous
35. if>
36. “pageNo” begin=”1″ end=”${pageNumShown}”>
37. “” >
38. if test=”${currentPage eq pageNo}” var=”rsFy”>
39. ${pageNo}
40. if>
41. if test=”${! rsFy}”>
42. ${pageNo}
43. if>
44.
45.
46. if test=”${currentPage ge pageNumShown}” var=”xyy”>
47. “next” href=”#”> Next page
48. if>
49. if test=”${! xyy}”>
50. “next page” href=””> Next page
51. if>
52. “tail” href=””> tail
53.
54.
55.
56.
57.
58.
The second createNativeQuery (returns as a collection of entity objects)
1) Dao layer code
Java code * * * * * * * * * * * * * * * *
1. @SuppressWarnings(“unchecked”)
2. public PageResult getList(Integer currentPage){
3. int pageSize = Constant.DEFAULT_PAGE_SIZE;
4. int start = (currentPage – 1) * pageSize;
5. String sql=”select a.* ”
6. +” from train_apply a inner join train_plan b on b.ID=a.PLAN_ID”;
7. PageResult pageResult = new PageResult();
8.
9. Query query = getEntityManager().createNativeQuery(sql.toString(),TrainApply.class);
10. int total = query.getResultList().size();
11. // Determine paging
12. if (start < total && pageSize > 0) {
13. query.setFirstResult(start);
14. query.setMaxResults(pageSize);
15. pageResult.setFirst(start);
16. pageResult.setPageSize(pageSize);
17.}
18. pageResult.setTotalCount(total);
19. pageResult.setPageResultList(query.getResultList());
20. return pageResult;
21.}
The entity class does not need to comment @namednativeQueries, etc. Page reads get data for item.planId like methods instead of item[0],item[1]… However, it is not suitable for complex SQL, such as a count(ID) column, currently can not implement several tables directly complex field display query. To study.
Training plan | The registration number | operation | |
---|---|---|---|
${s.index + 1} | ${item[2]} | ${item[3]} | 17. class=”applylist_operate”> 18. class=”icon icon_train_edit” href=””> 19. class${item[0]}.htm” href=”/${item[0]}. Data will not be recovered after deletion “> 20.21. |