How to implement pagination in spring boot with hibernate

后端 未结 5 1064
野的像风
野的像风 2020-12-15 07:21

I am using spring boot with hibernate and I want to use pagination in my project. I have searched on google and saw many examples but I am unable to implement it in my proje

5条回答
  •  忘掉有多难
    2020-12-15 07:53

    I have implemented pagination in spring boot. Below is my Repository.

        @Repository("userRepository")
        public interface UserRepository extends PagingAndSortingRepository {
      }
    

    Below is my Controller.

    @Controller
    public class SampleController {
    
        @Autowired
        private UserRepository repository;
    
        @GetMapping("/userview")
        public String getEmployees(@PageableDefault(size = 1) Pageable pageable,
                                   Model model) {
            Page page = repository.findAll(pageable);
            model.addAttribute("page", page);
            return "userdetail";
        }
    }
    

    Below is the view,for that I have used thymeleaf.

    
    
    
        
        
        
    
    
    

    USER DETAILS

    ID Name Last Name Email Role
    Previous [[${i}+1]] [[${i}+1]] Next

提交回复
热议问题