【发布时间】:2019-09-09 12:41:15
【问题描述】:
我是 Spring Boot 新手,
我有一个问题,是否可以用JpaRepository<T, I> 对JSP 中的表格进行分页,我已经在互联网上搜索了两天但没有找到。查询结果主要针对 Thymeleaf,但我不想使用 thymeleaf。我知道如何在 JSP 中使用Jdbctemplate 进行分页,但为此,我必须手动编写查询和页数。我已经写了一个spring boot & JSP代码。
EmployeeRepository:
public interface EmployeeRepository extends JpaRepository<Emp, Integer> {}
员工控制器:
@Controller
public class EmployeeController {
@Autowired
private EmployeeRepository repo;
@GetMapping("/")
public String showPaginate(Model m, @RequestParam(defaultValue = "0") int page) {
m.addAttribute("data", repo.findAll(new PageRequest(page, 4)));
return "index";
}
}
index.jsp
<table border="2" width="70%" cellpadding="3"
class="table">
<thead class="thead-dark">
<tr align="center">
<th scope="col">Id</th>
<th scope="col">Name</th>
<th scope="col">Designation</th>
<th scope="col">Edit</th>
<th scope="col">Delete</th>
</tr>
</thead>
<c:forEach var="emp" items="${list}">
<tbody>
<tr align="center">
<td>${emp.id}</td>
<td>${emp.name}</td>
<td>${emp.designation}</td>
<td><a href="editemp/${emp.id}" class="btn btn-outline-info">Edit</a></td>
<td><a href="deleteemp/${emp.id}" class="btn btn-outline-danger">Delete</a></td>
</tr>
</tbody>
</c:forEach>
</table>
<hr>
<!-- Pagination code will come here -->
【问题讨论】:
标签: java spring-boot jsp pagination