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

11.29 MyBatis分页插件PageHelper的使用 #63

Closed
vieyahn2017 opened this issue Nov 29, 2018 · 3 comments
Closed

11.29 MyBatis分页插件PageHelper的使用 #63

vieyahn2017 opened this issue Nov 29, 2018 · 3 comments

Comments

@vieyahn2017
Copy link
Owner

vieyahn2017 commented Nov 29, 2018

MyBatis分页插件PageHelper的使用
https://blog.csdn.net/eson_15/article/details/52270046

@vieyahn2017 vieyahn2017 changed the title 11.29 11.29 MyBatis分页插件PageHelper的使用 Jan 21, 2019
@vieyahn2017
Copy link
Owner Author

1.17遇到的一个巨坑:
pagehelper/pagehelper-spring-boot#34
spring boot 1.5.1.RELEASE集成pagehelper-spring-boot-starter 1.2.3启动报错

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.github.pagehelper.autoconfigure.PageHelperAutoConfiguration': Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pageHelperProperties': Could not bind properties to Properties (prefix=pagehelper, ignoreInvalidFields=false, ignoreUnknownFields=true, ignoreNestedProperties=false); nested exception is java.lang.IllegalStateException: Invalid target for Validator [org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor$ValidatedLocalValidatorFactoryBean@7bbcf6f0]: org.springframework.boot.bind.RelaxedDataBinder$MapHolder@2b80e5a9

tsaimn commented on 9 Mar 2018:
切换至spring boot 1.5.9.RELEASE可以正常启动

abel533 commented on 12 Mar 2018:
特地换了几个版本试了试,只有 1.5.0 和 1.5.1 版本有问题,建议别用这俩版本,其他都没问题。

@vieyahn2017
Copy link
Owner Author

SpringBoot整合通用Mapper以及Pagehelper分页插件
https://blog.csdn.net/LOVE_JA/article/details/80325715

@vieyahn2017
Copy link
Owner Author

vieyahn2017 commented Jan 30, 2019

/**
* 为了简单只有数据访问层,
* 写测试类测试
* 这里只用到了查询的方法,mapper提供
*/
@RunWith(SpringRunner.class)
@SpringBootTest
public class MapperTest {
    
    @Resource
    private StudentMapper studentMapper;
    
    @Test
    public void test1() {
        //不分页查询
        List<Student> lis1 = studentMapper.selectAll();     
        for (Student stu : lis1) {
            System.out.println(stu);
        }
        System.out.println("-------------------------------------------------------------------");
        System.out.println("-------------------------------------------------------------------");
        
        //分页查询,显示第一页,每页五条
        PageHelper.startPage(1,5);
        List<Student> lis2 = studentMapper.selectAll(); 
        for (Student stu : lis2) {
            System.out.println(stu);
        }
        System.out.println("-------------------------------------------------------------------");
        System.out.println("-------------------------------------------------------------------");
        
        //分页查询,显示第一页,每页五条,按id降序
        PageHelper.startPage(1,5,"stu_id desc");
        List<Student> lis3 = studentMapper.selectAll(); 
        for (Student stu : lis3) {
            System.out.println(stu);
        }
        System.out.println("-------------------------------------------------------------------");
        System.out.println("-------------------------------------------------------------------");
        
        //分页查询,显示第一页,每页五条,按id降序
        PageHelper.startPage(1,5,"stu_id desc");
        Student student = new Student();
        student.setName("二班张三");
        List<Student> lis4 = studentMapper.select(student); 
        for (Student stu : lis4) {
            System.out.println(stu);
        }
        
    }
    
}

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