1. 添加依赖

  1. <!-- mybatis plus 代码生成器 -->
  2. <dependency>
  3. <groupId>com.baomidou</groupId>
  4. <artifactId>mybatis-plus-boot-starter</artifactId>
  5. <version>3.3.1</version>
  6. </dependency>
  7. <dependency>
  8. <groupId>com.baomidou</groupId>
  9. <artifactId>mybatis-plus-generator</artifactId>
  10. <version>3.3.1</version>
  11. </dependency>
  12. <dependency>
  13. <groupId>com.alibaba</groupId>
  14. <artifactId>fastjson</artifactId>
  15. <version>1.2.47</version>
  16. </dependency>

2. 配置application.yml

  1. spring:
  2. datasource:
  3. driver-class-name: com.mysql.jdbc.Driver
  4. url: jdbc:mysql://127.0.0.1:3306/springboot_demo?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true
  5. username: root
  6. password: 123456
  7. jackson:
  8. date-format: yyyy-MM-dd HH:mm:ss
  9. time-zone: GMT+8
  10. serialization:
  11. write-dates-as-timestamps: false
  12. mybatis-plus:
  13. # 输出sql日志
  14. configuration:
  15. map-underscore-to-camel-case: true
  16. auto-mapping-behavior: full
  17. log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
  18. # mapper.xml文件配置
  19. mapper-locations: classpath*:mapper/*.Mapper.xml

3. 配置MyBatisPlusConfig

  1. @Configuration
  2. public class MyBatisPlusConfig {
  3. /**
  4. * 分页插件
  5. * @return
  6. */
  7. @Bean
  8. public PaginationInterceptor paginationInterceptor() {
  9. return new PaginationInterceptor();
  10. }
  11. }

4. 启动类添加mapper扫描

  1. @SpringBootApplication
  2. @MapperScan("com.xuwei.springboot.mapper") // 添加扫描mapper注解
  3. public class SpringbootApplication {}