1、mybatits+springboot分页

1、导入依赖

   1、1mysql

   1、2mybatis

   1、3web

   1、4pagehelper

  

    <!-- spring boot 提供了一个插件 -->
            <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper-spring-boot-starter</artifactId>
            <version>1.2.5</version>
        </dependency>

 

2、代码生成器

1、mybatits+springboot分页

 

 

2、配置文件

spring:
  datasource:
    url: jdbc:mysql://localhost:3306/1706b?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&serverTimezone=Asia/Shanghai
    username: root
    password: root
 
    ##声明mybatis持久层扫描的包路径
mybatis:
  mapper-locations:
    classpath:com/bw/mapper/*.xml
logging:
  level:
    com.bw: debug

  

3、测试

package com.bw;

import java.util.List;

import javax.annotation.Resource;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import com.bw.mapper.TEmpMapper;
import com.bw.pojo.TEmp;
import com.bw.pojo.TEmpExample;
import com.bw.pojo.TEmpExample.Criteria;
import com.github.pagehelper.PageHelper;

@RunWith(SpringRunner.class)
@SpringBootTest
public class Week01ApplicationTests {
   @Resource private TEmpMapper tEmpMapper;
   
   
    @Test
    public void query() {
        TEmpExample example = new TEmpExample();
        Criteria c = example.createCriteria();
        /* c.andEnameLike("%"+"allen"+"%"); */
        
        
        PageHelper.startPage(0, 3);
        
        List<TEmp> list = tEmpMapper.selectByExample(example);
        for (TEmp tEmp : list) {
            System.out.println(tEmp.toString());
        }
    }

}
上一篇:java中流关闭及带资源的try语句(try-with-resource)作用


下一篇:缓冲字节流、缓冲字符流