springboot集成mybatis

工程为maven工程

pom.xml内容如下

<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>cn.ffcs.tsp</groupId>
<artifactId>springboot</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<groupId>cn.ffcs.tsp.msa</groupId>
<artifactId>springbootMybatis</artifactId>
<version>1.0.0-SNAPSHOT</version>

<name>springbootMybatis</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- mysql驱动包 start-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.0.8</version>
</dependency>

<!--阿里云数据源连接jar包-->

<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.0</version>
</dependency>

<!--springboot集成mybatis的jar,里面引入了spring-mybatis,mybatis等等,mybatis-spring.version为2.01-->
<!-- https://mvnrepository.com/artifact/org.mybatis.spring.boot/mybatis-spring-boot-starter -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>${mybatis-spring.version}</version>
</dependency>
<!-- 分页插件 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.10</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.2</version>
</dependency>
<!-- 开发工具:修改java代码无须重新运行 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
<build>
      <plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
   </build>

</project>

项目目录结构

application.properties配置

配置启动后名称,端口号

配置mybatis的mapper映射文件位置,和实体类路径,以及sql打印

配置数据源

 

控制类

服务层

服务层实现类

 

实体类

分页查询dto

 

mapper类

 标红处需要对应好

 

配置springboot启动类

 分页目前存在一个问题,统计的条数与list查询对不上,看源码是因为list instanceof page ,为true,原因目前不知。

posted @ 2019-08-11 22:18  每天进步一点点_hejj  阅读(301)  评论(0编辑  收藏  举报