# spring boot mybatis
以下服務已經在父工程中引入了spring-boot和spring-boot-starter-web
spring boot 2.2.*整合 mybatis,註解方式實現
案例模塊
spring-boot2-mybaits
1. 創建 spring-boot2-mybaits
在pom.xml中添加依賴
<dependency>
<groupid>org.mybatis.spring.boot/<groupid>
<artifactid>mybatis-spring-boot-starter/<artifactid>
<version>2.1.0/<version>
/<dependency>
<dependency>
<groupid>mysql/<groupid>
<artifactid>mysql-connector-java/<artifactid>
<scope>runtime/<scope>
/<dependency>
2、新增 application.yml 配置文件,配置數據源
server:
port: 10003
spring:
application:
name: spring-boot-mybatis
boot:
admin:
client:
url: http://localhost:10001
username: admin
password: admin
instance:
name: spring-boot-mybatis
datasource:
username: root
password: 123456
url: jdbc:mysql://127.0.0.1:3306/tttt?useUnicode=true&characterEncoding=utf8&serverTimezone=UTC
driver-class-name: com.mysql.jdbc.Driver
management:
endpoints:
web:
exposure:
include: '*' # spring boot admin 中顯示完整信息
info:
version: V1.1.0
mybatis:
mapper-locations: classpath:/mybaits/mapper/*.xml
到此spring-boot2-mybaits服務模塊就結束了
2、ok,瀏覽器輸入 http://localhost:10003/user/test進行數據測試
GIT地址:https://github.com/hy4101/spring-boot2.git
閱讀更多 mini科技 的文章