提交 50b57661 编写于 作者: 冯文议

MyBatis-Plus升级到 3.2.0

上级 d6b31209
# Learn MyBatis Plus
# MyBatis-Plus-Example
学习 MyBatis Plus
[代码生成器](https://github.com/fengwenyi/mybatis-plus-code-generator)
## 工程概要
#### 版本
| 名称 | 版本 | 上一个版本 | 更新时间 |
| --- | --- | --- | --- |
| Spring Boot | 2.1.7.RELEASE | 2.1.5.RELEASE | 2019.08.27 |
| MyBatis-Plus | 3.2.0 | 3.0.1 | 2019.08.27 |
| fastjson | 1.2.59 | - | 2019.08.27 |
| api-result | 2.0.0 | - | 2019.08.27 |
| swagger | 2.9.2 | - | 2019.08.27 |
## 引言
两点:
......@@ -485,6 +499,8 @@ mybatis-plus:
logic-not-delete-value: 0
```
## 逻辑删除
## MyBatis-Plus-Example
MyBatis-Plus的代码都会上传到github上
......
<?xml version="1.0" encoding="UTF-8"?>
<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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.5.RELEASE</version>
<version>2.1.7.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.fengwenyi</groupId>
<artifactId>learn-mybatis-plus</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>3.2.0</version>
<name>learn-mybatis-plus</name>
<description>学习MyBatis Plus</description>
<description>Demo MyBatis Plus</description>
<properties>
<java.version>1.8</java.version>
<swagger2.version>2.9.2</swagger2.version>
<JavaLib.version>1.0.4.RELEASE</JavaLib.version>
<mp.version>3.0.1</mp.version>
<mybatis-plus.version>3.2.0</mybatis-plus.version>
<fastjson.version>1.2.59</fastjson.version>
<api-result.version>2.0.0</api-result.version>
</properties>
<dependencies>
<!-- Spring Boot : Web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- MySQL -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<!-- lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<!-- Spring Boot : Test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.baomidou/mybatis-plus-boot-starter -->
<!-- mybatis-plus-boot-starter -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>${mp.version}</version>
<version>${mybatis-plus.version}</version>
</dependency>
<!-- Swagger -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${swagger2.version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${swagger2.version}</version>
</dependency>
<!-- JavaLib -->
<dependency>
<groupId>com.fengwenyi</groupId>
<artifactId>JavaLib</artifactId>
<version>${JavaLib.version}</version>
</dependency>
<dependency>
<!-- JSON -->
<!--<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>${gson.version}</version>
</dependency>
</dependency>-->
<!-- 2019.08.27 移除gson,改用fastjson -->
<dependency>
<groupId>com.github.iutil</groupId>
<artifactId>app-boot-starter</artifactId>
<version>1.0.0.BUILD</version>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>${fastjson.version}</version>
</dependency>
<!-- 添加 Api Result 支持 -->
<dependency>
<groupId>com.github.iutil</groupId>
<groupId>com.fengwenyi</groupId>
<artifactId>api-result</artifactId>
<version>1.0.0.BUILD</version>
<version>${api-result.version}</version>
</dependency>
</dependencies>
......@@ -97,11 +110,4 @@
</plugins>
</build>
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
</project>
package com.fengwenyi.learnmybatisplus.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fengwenyi.api_result.helper.ResultHelper;
import com.fengwenyi.api_result.model.ResultModel;
import com.fengwenyi.javalib.util.StringUtil;
import com.fengwenyi.learnmybatisplus.business.AppBusiness;
import com.fengwenyi.learnmybatisplus.enums.GenderEnum;
......@@ -10,7 +12,6 @@ import com.fengwenyi.learnmybatisplus.model.Student;
import com.fengwenyi.learnmybatisplus.service.MPCityService;
import com.fengwenyi.learnmybatisplus.service.MPStudentService;
import io.swagger.annotations.Api;
import net.iutil.ApiResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
......@@ -39,26 +40,26 @@ public class AppController {
// 查询所有城市
@GetMapping("/queryCityAll")
public ApiResult queryCityAll() {
public ResultModel queryCityAll() {
List<City> cities = mpCityService.queryCityAll();
return ApiResult.success(cities);
return ResultHelper.success("Success", cities);
}
// 添加城市
@PostMapping("/addCity")
public ApiResult addCity(String name) {
public ResultModel addCity(String name) {
if (StringUtil.isEmpty(name))
return ApiResult.error();
return ResultHelper.error("名称不能为空");
boolean rs = mpCityService.addCity(new City().setName(name));
if (rs)
return ApiResult.success();
return ApiResult.error();
return ResultHelper.success("Success", null);
return ResultHelper.error("添加失败");
}
// 添加学生
@PostMapping("/addStudent")
public ApiResult addStudent(String name, Integer age, String gender, String info, String idCardCode, String cityName) {
public ResultModel addStudent(String name, Integer age, String gender, String info, String idCardCode, String cityName) {
// 检验参数
if (StringUtil.isEmpty(name)
......@@ -67,7 +68,7 @@ public class AppController {
|| StringUtil.isEmpty(info)
|| StringUtil.isEmpty(idCardCode)
|| StringUtil.isEmpty(cityName))
return ApiResult.error();
return ResultHelper.error("参数不合法");
// 获取GenderEnum
GenderEnum genderEnum = GenderEnum.getEnumByDesc(gender);
......@@ -88,16 +89,16 @@ public class AppController {
// service
boolean rs = appBusiness.addStudent(student, city, idcard);
if (rs)
return ApiResult.success();
return ApiResult.error();
return ResultHelper.success("Success", null);
return ResultHelper.error("添加失败");
}
// 分页查询学生
@GetMapping("/queryStudentByPage/{currentPage}")
public ApiResult queryStudentByPage(@PathVariable("currentPage") Long currentPage) {
public ResultModel queryStudentByPage(@PathVariable("currentPage") Long currentPage) {
if (currentPage == null)
return ApiResult.error();
return ResultHelper.error("当前页不能为空");
IPage<Student> studentIPage = mpStudentService.queryStudentByPage(currentPage);
return ApiResult.success(studentIPage);
return ResultHelper.success("Success", studentIPage);
}
}
package com.fengwenyi.learnmybatisplus.service.impl;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
......@@ -10,7 +11,6 @@ import com.fengwenyi.learnmybatisplus.model.Student;
import com.fengwenyi.learnmybatisplus.dao.StudentDao;
import com.fengwenyi.learnmybatisplus.service.MPStudentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.gson.Gson;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
......@@ -71,7 +71,7 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, Student> impleme
// queryWrapper.lambda().like(Student::getName, "文");
List<Student> studentList = list(queryWrapper);
for (Student student : studentList)
Console.info(new Gson().toJson(student));
Console.info(JSON.toJSONString(student));
}
@Override
......@@ -81,7 +81,7 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, Student> impleme
new Page<>(1, 2),
null);
Console.info(new Gson().toJson(page));
Console.info(JSON.toJSONString(page));
}
......@@ -94,7 +94,7 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, Student> impleme
.eq(Student::getAge, 25);
List<Student> studentList = list(queryWrapper);
for (Student student : studentList)
Console.info(new Gson().toJson(student));
Console.info(JSON.toJSONString(student));
}
@Override
......@@ -107,7 +107,7 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, Student> impleme
List<Student> studentList = list(queryWrapper);
for (Student student : studentList)
Console.info(new Gson().toJson(student));
Console.info(JSON.toJSONString(student));
}
@Override
......@@ -118,7 +118,7 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, Student> impleme
.or(obj2 -> obj2.eq(Student::getName, "1"));
List<Student> studentList = list(queryWrapper);
for (Student student : studentList)
Console.info(new Gson().toJson(student));
Console.info(JSON.toJSONString(student));
}
@Override
......@@ -130,7 +130,7 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, Student> impleme
.eq(Student::getName, "1");
List<Student> studentList = list(queryWrapper);
for (Student student : studentList)
Console.info(new Gson().toJson(student));
Console.info(JSON.toJSONString(student));
}
@Resource
......@@ -140,7 +140,7 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, Student> impleme
public void test7() {
List<Student> studentList = studentDao.selectAll();
for (Student student : studentList)
Console.info(new Gson().toJson(student));
Console.info(JSON.toJSONString(student));
}
@Override
......
#app
server:
port: 9104
port: 8080
spring:
application:
name: demo-mybatis-plus
profiles:
active: dev
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册