首页>代码>JPA使用视图进行查询、使用Adobe Acrobat准备表单生成PDF>/JpaFormPdf/src/main/java/com/ldg/test/controller/UserViewController.java
package com.ldg.test.controller; import com.ldg.test.modal.User; import com.ldg.test.modal.UserView; import com.ldg.test.service.IUserService; import com.ldg.test.service.IUserViewService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.*; import org.springframework.web.servlet.ModelAndView; import java.util.List; @Controller public class UserViewController { @Autowired private IUserViewService userViewService; @RequestMapping("/") public String viewIndexPage(Model model) { String keyword = null; return listByPage(model, 1, "id", "asc", keyword); } @RequestMapping("/userView") public String viewIndexPage1(Model model) { String keyword = null; return listByPage(model, 1, "id", "asc", keyword); } @GetMapping("/userView/page/{pageNumber}") public String listByPage(Model model, @PathVariable("pageNumber") int currentPage, @Param("sortField") String sortField, @Param("sortDir") String sortDir, @Param("keyword") String keyword) { Page<UserView> page = userViewService.listAll(currentPage, sortField, sortDir, keyword); long totalItems = page.getTotalElements(); int totalPages = page.getTotalPages(); // int currentPage = page.previousPageable().getPageNumber(); List<UserView> listUsers = page.getContent(); model.addAttribute("totalItems", totalItems); model.addAttribute("totalPages", totalPages); model.addAttribute("currentPage", currentPage); model.addAttribute("listUsers", listUsers); // next bc of thymeleaf we make the user.html model.addAttribute("sortField", sortField); model.addAttribute("sortDir", sortDir); model.addAttribute("keyword", keyword); String reverseSortDir = sortDir.equals("asc") ? "desc" : "asc"; model.addAttribute("reverseSortDir", reverseSortDir); return "userView"; } }
最近浏览更多
kenhomeliu LV29
4月30日
youwuzuichen LV10
4月17日
woldxy LV12
4月1日
wanglinddad LV55
3月13日
田DJ sozzled
3月2日
暂无贡献等级
1134116035
2月28日
暂无贡献等级
houxianzheng
2月19日
暂无贡献等级
WBelong LV7
2023年12月28日
710581799
2023年12月21日
暂无贡献等级
hxy19991216 LV4
2023年12月20日