spring boot整合使用mybatis

1)pom文件引入

<parent>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-starter-parent</artifactId>

            <version>1.3.2.RELEASE</version>

            <relativePath /> <!-- lookup parent from repository -->

      </parent>

      <dependencies>

            <dependency>

                  <groupId>org.springframework.boot</groupId>

                  <artifactId>spring-boot-starter</artifactId>

            </dependency>

            <dependency>

                  <groupId>org.springframework.boot</groupId>

                  <artifactId>spring-boot-starter-test</artifactId>

                  <scope>test</scope>

            </dependency>

            <dependency>

                  <groupId>org.mybatis.spring.boot</groupId>

                  <artifactId>mybatis-spring-boot-starter</artifactId>

                  <version>1.1.1</version>

            </dependency>

            <dependency>

                  <groupId>mysql</groupId>

                  <artifactId>mysql-connector-java</artifactId>

                  <version>5.1.21</version>

            </dependency>

            <dependency>

                  <groupId>org.springframework.boot</groupId>

                  <artifactId>spring-boot-starter-web</artifactId>

            </dependency>

      </dependencies>

2)application.properties配置文件

spring.datasource.url=jdbc:mysql://localhost:3306/test

spring.datasource.username=root

spring.datasource.password=root

spring.datasource.driver-class-name=com.mysql.jdbc.Driver

3)创建实体类,添加get和set方法

 

3)通过实体类,创建调用方法

4)创建访问路径

5)创建启动类

注意

使用@MapperScan可以指定要扫描的Mapper类的包的路径

posted @ 2017-12-11 16:18  逝意遨游  阅读(172)  评论(0)    收藏  举报