@Controller
@RequestMapping("/admin/hotel")
class HotelController {
@Autowired
private HotelRepository repository;
@RequestMapping(method = RequestMethod.GET)
public String list(Model model, @PageableDefault(page = 0, value = 10) Pageable pageable) {
Page<Hotel> page = repository.findAll(pageable);
model.addAttribute("page", page);
return "hotel/list";
}
}
我的问题:如何使用 Thymeleaf 模板引擎在 View 层上使用 Page 对象生成排序链接?
最佳答案
<a th:href="@{~/admin/hotel(sort=(${page?.sort?.getOrderFor('title')?.ascending} ? 'title,desc' : 'title,asc'))}">title</a>
关于spring-mvc - Spring Data JPA如何使用排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22931852/