@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模板引擎使用视图层上的Page对象生成链接以进行排序?
<a th:href="@{~/admin/hotel(sort=(${page?.sort?.getOrderFor('title')?.ascending} ? 'title,desc' : 'title,asc'))}">title</a>