springboot整合mybatis

1、引入jar包

<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.4</version>
</dependency>

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
View Code

2、编写application.properties配置文件

mybatis.type-aliases-package=com.example.demo.model

spring.datasource.url=jdbc:mysql://localhost:3306/day13?useUnicode=true&characterEncoding=utf-8
spring.datasource.username=root
spring.datasource.password=
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
View Code

3、在application类上加@MapperScan扫描mapper类文件

@MapperScan("com.example.demo.model.mapper")
View Code

4、在pom.xml中放行mapper.xml

        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
                <filtering>false</filtering>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
                <filtering>false</filtering>
            </resource>
        </resources>
View Code

 

posted @ 2019-04-23 13:53  一天到晚想名字  阅读(214)  评论(0编辑  收藏  举报