我是春季靴子的新成员,所以要努力使搜索结果列表分页。实际上,我首先要从数据库中对所有列表进行分页,然后从百里香中已经显示的列表中搜索数据并在搜索数据中进行分页。
答案 0 :(得分:1)
带有弹簧靴百里香的分页示例:
* HTML百里香叶分页div * :
<!-- pagination liste client -->
<nav aria-label="Page navigation example" class="navbar navbar toggleable-md navbar-light bg-faded">
<ul class="pagination nav nav-pills">
<li class="nav-item" th:classappend="${p}==${pageCourante}? 'active':''" th:each="p:${pages}" >
<a class="page-link" th:classappend="${p}==${pageCourante}? 'active':''" th:text="${p}" th:href="@{listeClient(page=${p},motCle=${motCle})}">
</a>
</li>
</ul>
</nav>
*控制器* :
@Controller
public class ClientController {
@Autowired
private ClientRepository clientRepository;
@RequestMapping(value="/listeClient", method=RequestMethod.GET)
public String listeClient(Model model,
@RequestParam(name="page", defaultValue="0")int p,
@RequestParam(name="motCle", defaultValue="")String mc) {
Page<Client> pageClients = clientRepository.chercherClients("%"+mc+"%", PageRequest.of(p, 5));
int pagesCount = pageClients.getTotalPages();
int[] pages = new int[pagesCount];
for(int i=0; i<pagesCount; i++) pages[i] = i;
model.addAttribute("pages", pages);
model.addAttribute("pageCourante", p);
model.addAttribute("motCle", mc);
model.addAttribute("pageClients", pageClients);
return "listeClient";
}
*客户端存储库* :
public interface ClientRepository extends JpaRepository<Client, Long> {
@Query ("select c from Client c where c.nomClient like :x")
public Page<Client> chercherClients(@Param("x")String mc, Pageable pageable);
}