概述
这段时间接触很多知识,也逐渐深入到项目整个流程开发,对Linux也有逐步地认识。虽然有去探索,但感觉能力还不足以写出来跟大家分享。撰写本文是了解到有些读者反馈,对于MP(MybatisPlus缩写)不太了解以及如何去使用,但更多还是笔者用完觉得非常强大,有必要share。文章还会主讲Redis配置使用,篇幅有点长,因此分为两节讲解。
构建
- 开发环境:Spring Tool Suite(Version: 3.8.2.RELEASE当然,譬如Eclipse、MyEclipse等其他IDE工具也行)
- 数据库:MySQL
项目结构
新建Maven项目,导入相关依赖包,pom.xml(根据个人需求可以去掉不必要的包)
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.jekin.example</groupId>
<artifactId>redis-example</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<spring.boot.version>1.5.3.RELEASE</spring.boot.version>
<java.version>1.8</java.version>
<redis.version>1.4.7.RELEASE</redis.version>
<druid.version>1.0.0</druid.version>
<mybatisplus-spring-boot-starter.version>1.0.1</mybatisplus-spring-boot-starter.version>
<fastjson.version>1.2.31</fastjson.version>
<mysql.version>5.1.42</mysql.version>
<commons.lang3.version>3.5</commons.lang3.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring.boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-redis</artifactId>
<version>${redis.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>${fastjson.version}</version>
</dependency>
<!-- 数据库连接池 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>${druid.version}</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatisplus-spring-boot-starter</artifactId>
<version>${mybatisplus-spring-boot-starter.version}</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons.lang3.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<!-- Maven编译版本 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<executable>true</executable>
<source>1.8</source>
<target