springboot 集成 mybatis

1,添加依赖

<!-- mybatis -->
<dependency>
    <groupId>org.mybatis.spring.boot</groupId>
    <artifactId>mybatis-spring-boot-starter</artifactId>
    <version>1.3.2</version>
</dependency>
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <scope>runtime</scope>
</dependency>

2,数据源和 mybatis 配置

spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8
spring.datasource.username=root
spring.datasource.password=111111
# mybatis xml 文件在资源文件夹下的 mapping 文件夹
mybatis.mapperLocations=classpath:mapping/*.xml
# 打印 sql 
logging.level.接口包路径=debug
# mybatis 实体类
mybatis.type-aliases-package=com.ictpaas.pojo

3,扫描接口,通过 @MapperScan 注解完成扫描

@SpringBootApplication
@MapperScan("com.ictpaas.Idao")
public class XNumServerApplication {

    public static void main(String[] args) {
        SpringApplication.run(XNumServerApplication.class, args);
    }
}
posted @ 2018-08-14 00:04  huanggy  阅读(135)  评论(0编辑  收藏  举报