Question

@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?

Was it helpful?

Solution

<a th:href="@{~/admin/hotel(sort=(${page?.sort?.getOrderFor('title')?.ascending} ? 'title,desc' : 'title,asc'))}">title</a>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top