In conjunction with Spring MVC you can use PageableDefaults
annotation with value = Integer.MAX_VALUE
like
public String showUsers(Model model,
@PageableDefaults(pageNumber = 0, value = Integer.MAX_VALUE) Pageable pageable) { … }
see PageableDefaults annotation Javadoc.
In any other client code you can set second constructor parameter to Integer.MAX_VALUE
:
new PageRequest(
queryForm.getPageNumber()- 1,
queryForm.getPageSize() == null ? Integer.MAX_VALUE : queryForm.getPageSize(),
Sort.Direction.ASC,"id");
see PageRequest constructor. I assume that queryForm.getPageSize()
is a wrapper type not a primitive. Otherwise you get a zero if pageSize wasn't set by the user (intentionally for a "search all" request).
UPDATE:
Since Spring Data Commons 1.6 you should use PageableDefault
instead of PageableDefaults
public String showUsers(Model model,
@PageableDefault(page= 2 ,value = Integer.MAX_VALUE)
See PageableDefault annotation Javadoc.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…