springboot整合mybatis,pagehelper分页插件

  1. 多环境配置
    默认使用application.yml的配置,其他环境 application-{profile}.yml
    开发环境:application-dev.yml
    测试环境:application-test.yml
    生产环境:application-prod.yml

  2. 添加依赖
    参考 https://github.com/abel533/MyBatis-Spring-Boot

        
        
            mysql
            mysql-connector-java
            runtime
        
        
        
            org.mybatis.spring.boot
            mybatis-spring-boot-starter
            1.3.1
        
        
        
            tk.mybatis
            mapper-spring-boot-starter
            2.0.3
        
        
        
            com.github.pagehelper
            pagehelper-spring-boot-starter
            1.3.0
        
  1. 配置文件
spring:
  datasource:
    username: 
    password: 
    url: jdbc:mysql://127.0.0.1:3306/pay?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=UTC
    driver-class-name: com.mysql.cj.jdbc.Driver

mybatis:
    type-aliases-package: com.baoxian.entity
    mapper-locations: classpath:mapper/*.xml
    #配置驼峰下划线
    configuration:
      map-underscore-to-camel-case: true
      log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

pagehelper:
    helperDialect: mysql
    reasonable: true
    supportMethodsArguments: true
    params: count=countSql
  1. dao层,测试数据库连接是否成功
/**
 * 账单
 */
public interface PayBillDao extends Mapper {
    /**
     * 测试数据库连接
     * @return
     */
    @Select("SELECT count(*) FROM pay_bill ")
    Integer countPayBill();
}

mapper





你可能感兴趣的:(springboot整合mybatis,pagehelper分页插件)