JAVA编程132——springdata JPA使用Example快速实现动态查询

  /**
     * 条件-模糊-分页查询
     * @param page
     * @param rows
     * @Auther: Mollen
     * @return
     */
    @Override
    public Page<Employee> pageQuery(int page, int rows,Employee employee) {
        //创建查询条件
        ExampleMatcher matcher = ExampleMatcher.matching()
                .withMatcher("employeeNum" ,ExampleMatcher.GenericPropertyMatchers.contains())
                .withMatcher("employeName" ,ExampleMatcher.GenericPropertyMatchers.contains())
                .withMatcher("dept" ,ExampleMatcher.GenericPropertyMatchers.contains())
                .withMatcher("position" ,ExampleMatcher.GenericPropertyMatchers.contains());
        //分页
        PageRequest pageResult = PageRequest.of(page-1, rows);
        return courierDao.findAll(Example.of(courier,matcher),pageResult);
    }

猜你喜欢

转载自blog.csdn.net/mollen/article/details/86584415