首页>代码>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";
}
}
最近浏览更多
3993zby LV2
2024年11月11日
Peny_ZH LV5
2024年9月21日
liiiyou LV1
2024年6月2日
kenhomeliu LV29
2024年4月30日
youwuzuichen LV11
2024年4月17日
woldxy LV12
2024年4月1日
wanglinddad LV55
2024年3月13日
田DJ sozzled
2024年3月2日
暂无贡献等级
1134116035
2024年2月28日
暂无贡献等级
houxianzheng
2024年2月19日
暂无贡献等级

最近下载
