第一步:相关依赖
org.springframework.boot
spring-boot-starter-web
org.mybatis.spring.boot
mybatis-spring-boot-starter
2.0.1
mysql
mysql-connector-java
runtime
org.projectlombok
lombok
true
org.springframework.boot
spring-boot-starter-test
test
com.github.pagehelper
pagehelper-spring-boot-starter
1.2.3
第二部:application.yml中的配置
#数据库的配置 spring: datasource: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://localhost:3306/mytest?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT username: root password: root #mybatis的配置 mybatis: configuration: # sql日志显示,这里使用标准显示 log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 数据库中如果有类似 如 user_name 等命名,会将 _后的字母大写,这里是为了和实体类对应 map-underscore-to-camel-case: true # 配置mapper文件的路径 mapper-locations: classpath:com/example/boot_mybatis_two/*/mapper/*.xml #pageHelper配置(官网推荐配置) pagehelper: helperDialect: mysql reasonable: true supportMethodsArguments: true params: count=countSql
第三部:入口文件中的设置
package com.example.boot_mybatis_two; import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; //配置dao文件所在的包 @MapperScan("com.example.boot_mybatis_two.*.dao") @SpringBootApplication public class BootMybatisTwoApplication { public static void main(String[] args) { SpringApplication.run(BootMybatisTwoApplication.class, args); } }
第四部:项目创建(包目录截图,分层结构)

第五步:(取user和dept中的一个来说这里取user模块)
到此完成 springboot整合mybatis+mybatis分页插件。并成功运行
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/178247.html原文链接:https://javaforall.net
