Spring Boot 實用MyBatis做資料庫操作
阿新 • • 發佈:2019-01-21
前言:
本專案基於maven構建,使用mybatis-spring-boot作為spring-boot專案的持久層框架
spring-boot中使用mybatis持久層框架與原spring專案使用方式和註解都不相同,需要依賴mybatis-spring-boot包
1、引入mybatis和資料庫及其他專案依賴
1.1、引入mybatis依賴
[html] view plain copy print?- <!-- mybatis-spring-boot -->
-
<dependency>
- <groupId>org.mybatis.spring.boot</groupId>
- <artifactId>mybatis-spring-boot-starter</artifactId>
- <version>1.1.1</version>
- </dependency>
1.2、引入mysql 驅動
[html] view plain copy print?-
<!-- mysql-->
- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-java</artifactId>
- </dependency>
1.3、專案pom.xml一覽
[html] view plain copy print?-
<projectxmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <groupId>cn.eguid.carDeviceInfoSys</groupId>
- <artifactId>carSys-web</artifactId>
- <packaging>war</packaging>
- <version>1.4.0-SNAPSHOT</version>
- <name>carSys-web</name>
- <parent>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-parent</artifactId>
- <version>1.4.0.RELEASE</version>
- </parent>
- <dependencies>
- <!-- spring-boot web -->
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-web</artifactId>
- <!--<exclusions><exclusion><groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-tomcat</artifactId></exclusion></exclusions> -->
- </dependency>
- <!-- spring aop -->
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-aop</artifactId>
- </dependency>
- <!-- mysql-->
- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-java</artifactId>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-jdbc</artifactId>
- </dependency>
- <!-- https://mvnrepository.com/artifact/redis.clients/jedis -->
- <dependency>
- <groupId>redis.clients</groupId>
- <artifactId&g