Reputation: 63
@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";
}
}
My question: How to generate links to sort using the Page object on view layer with Thymeleaf template engine?
Upvotes: 2
Views: 1940
Reputation: 63
<a th:href="@{~/admin/hotel(sort=(${page?.sort?.getOrderFor('title')?.ascending} ? 'title,desc' : 'title,asc'))}">title</a>
Upvotes: 2