okinawa

IT勉強メモ

@PageableDefaultでページのソートやサイズ指定など

spring.pleiades.io

@PageableDefaultでページのソート、サイズ指定、開始ページ指定ができるよ。

かんたんだよ。

@Controller
public class AccountController {

    @Autowired
    private Service service;

    @GetMapping("/hello")
    public String getHello(
            @PageableDefault(page = 0, size = 2, direction = Direction.DESC, sort = { "id", "name" }) Pageable pageable,
            Model model) {

        Page<AccountEntity> accountAll = service.findAllAccount(pageable);
        model.addAttribute("page", accountAll);
        model.addAttribute("accountAll", accountAll.getContent());

        return "hello";
    }
}