spring boot配置Mybatis

先在pom.xml中加上mybatis的依赖:


	org.mybatis.spring.boot
	mybatis-spring-boot-starter
	1.3.0


	mysql
	mysql-connector-java
	8.0.11



还有也需要加到pom.xml里的下:
见https://blog.csdn.net/tonghuawanli/article/details/76999282

然后在application.properties中,加上数据库的配置:

# MySQL配置
spring.datasource.url=jdbc:mysql://***:3306/**?useUnicode=true&characterEncoding=utf-8&useSSL=false
spring.datasource.username=
spring.datasource.password=
# spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.initialSize=5
spring.datasource.minIdle=5
spring.datasource.maxActive=20
spring.datasource.maxWait=60000
spring.datasource.timeBetweenEvictionRunsMillis=60000
spring.datasource.minEvictableIdleTimeMillis=300000
spring.datasource.validationQuery=SELECT 1 FROM DUAL
spring.datasource.testWhileIdle=true
spring.datasource.testOnBorrow=false
spring.datasource.testOnReturn=false
spring.datasource.poolPreparedStatements=true
spring.datasource.maxPoolPreparedStatementPerConnectionSize=20
spring.datasource.filters=stat,log4j
spring.datasource.connectionProperties="druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000"

mybatis.mapper-locations=classpath:/mappers/*.xml

在resources下新建generatorConfig.xml,内容见:https://blog.csdn.net/tonghuawanli/article/details/76999282,
在generatorConfig.xml中配置生成的文件位置之类的。

之后通过Mybatis插件就可以生成对应的类、Mapper等等。

你可能感兴趣的:(MyBatis)