步骤
1.添加关键依赖包
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.3</version>
</dependency>
注意需要将MySQL驱动包版本降为5.x版本,否则在idea中运行会报错
3.application.properties配置相关信息:
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
//数据库链接解决时间戳不同的问题
spring.datasource.url=jdbc:mysql://localhost:3306/appinfodb?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
spring.datasource.username=root
spring.datasource.password=123456
//在控制台输出sql语句
spring.jpa.properties.hibernate.format_sql=true
//输出日志级别
logging.level.org.hibernate=DEBUG
//配置映射 链接到实体类包
mybatis.type-aliases-package=com.example.pulls2.pojo
//mybatis配置 locations链接到dao包
mybatis.mapper-locations=classpath:com/example/pulls2/dao/*.xml