Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jpa return Page #2

Open
leqviet opened this issue Aug 13, 2019 · 1 comment
Open

Jpa return Page #2

leqviet opened this issue Aug 13, 2019 · 1 comment

Comments

@leqviet
Copy link
Owner

leqviet commented Aug 13, 2019

public Page<Customer> list(int start, int lenght, String sort, String order){
	int page =0;
	if (start > 0 ){
		page = start /lenght;
	}
	Pageable pageRequest;
	if (StringUtils.isEmpty(sort)){
		pageRequest = new PageRequest(page, lenght) ;
	}else{
		if (sort.equals("id")){
			sort ="uid";
		}
		pageRequest = new PageRequest(page, lenght,Sort.Direction.fromString(order),sort) ;
	}
	return customerRepository.findAll(pageRequest);
}
@leqviet
Copy link
Owner Author

leqviet commented Aug 13, 2019

Page page = service.list(start, lenght, sort, order);

	CustomerListModel list = new CustomerListModel();
	list.setTotal(page.getTotalElements());
	list.addAllRows(CustomerConverter.convertEntityToModel(page.getContent()));
	return list;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant