美文网首页基于springboot的支付系统实战
springboot整合mybatis,pagehelper分页

springboot整合mybatis,pagehelper分页

作者: faymanwang | 来源:发表于2020-12-28 16:01 被阅读0次
    1. 多环境配置
      默认使用application.yml的配置,其他环境 application-{profile}.yml
      开发环境:application-dev.yml
      测试环境:application-test.yml
      生产环境:application-prod.yml

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

            <!--mybatis-->
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <scope>runtime</scope>
            </dependency>
            <!--mybatis 和下面版本需要匹配-->
            <dependency>
                <groupId>org.mybatis.spring.boot</groupId>
                <artifactId>mybatis-spring-boot-starter</artifactId>
                <version>1.3.1</version>
            </dependency>
            <!--mapper-->
            <dependency>
                <groupId>tk.mybatis</groupId>
                <artifactId>mapper-spring-boot-starter</artifactId>
                <version>2.0.3</version>
            </dependency>
            <!--pagehelper-->
            <dependency>
                <groupId>com.github.pagehelper</groupId>
                <artifactId>pagehelper-spring-boot-starter</artifactId>
                <version>1.3.0</version>
            </dependency>
    
    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<PayBill> {
        /**
         * 测试数据库连接
         * @return
         */
        @Select("SELECT count(*) FROM pay_bill ")
        Integer countPayBill();
    }
    

    mapper

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
            "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
    <mapper namespace="com.baoxian.dao.PayBillDao">
    </mapper>
    

    相关文章

      网友评论

        本文标题:springboot整合mybatis,pagehelper分页

        本文链接:https://www.haomeiwen.com/subject/butunktx.html