# springboot-mybatis-plus-generator
**Repository Path**: misterchaos/springboot-mybatis-plus-generator
## Basic Information
- **Project Name**: springboot-mybatis-plus-generator
- **Description**: 基于mybatis-plus的springboot代码生成器,实现controller restful风格CURD接口,service层CURD对IService的方法再次封装,方便添加业务逻辑,serviceImpl中方法实现执行debug日志打印,mapper模板在官方模板基础上加入@mapper注解,各模板方法添加Javadoc注释,实现分页查询,关键词模糊查询
- **Primary Language**: Java
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 2
- **Created**: 2020-06-24
- **Last Updated**: 2021-06-21
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# 基于mybatis-plus的springboot代码生成器
[](https://github.com/misterchaos/springboot-mybatis-plus-generator)
[](https://github.com/misterchaos/springboot-mybatis-plus-generator/releases)
[](https://github.com/misterchaos/springboot-mybatis-plus-generator/releases)

## :droplet:Overview
这是一个基于mybatis-plus官方的AutoGenerator代码生成器+定制代码模板的[springboot代码生成器](https://github.com/misterchaos/springboot-mybatis-plus-generator)。
**使用这个生成器你可以在1分钟之内生成数据库表对应的实体类,以及Mapper,Service,Controller层的基本CURD代码,并可以立即运行测试接口。**
如果你不了解什么是mybatis-plus,请参考[官方文档](https://mp.baomidou.com/)
本代码生成器具有以下优点:
- 只需三步,即可开始测试CURD接口
- 生成的代码风格良好,注释详细(遵循阿里巴巴开发规范)
- 带有程序执行日志打印和错误日志打印
## :star:Features
- 实现controller restful风格CURD接口
- service层CURD对IService的方法再次封装,方便添加业务逻辑
- serviceImpl中方法实现执行日志打印
- mapper模板在官方模板基础上加入@mapper注解
- 各模板方法添加Javadoc注释
- 实现分页查询,关键词模糊查询(需自定义字段)
## :point_right:Quick Start
**动画演示**:

**使用步骤:**
- 修改application.properties配置文件,设置数据库信息
```
#DataSource Config
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/flower?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT
spring.datasource.username=root
spring.datasource.password=
```
- 运行CodeGenerator类,输入Author,输入数据库表名
- 运行SpringbootMybatisPlusGeneratorApplication,测试接口
> 注意:数据库表必须符合以下规范
> 每张表的主键命名为 表名_id 如: user_id
## :bulb:Examples
### 1.Controller模板代码示例
```java
package cn.hellochaos.generator.controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import cn.hellochaos.generator.entity.dto.ResultBean;
import cn.hellochaos.generator.service.UserService;
import cn.hellochaos.generator.entity.User;
import org.springframework.web.bind.annotation.RestController;
/**
*
* 用户 前端控制器 *
* * @author chaos * @since 2020-05-02 * @version v1.0 */ @RestController @RequestMapping("/generator/api/v1/user") public class UserController { @Autowired private UserService userService; /** * 查询分页数据 */ @RequestMapping(method = RequestMethod.GET) public ResultBean> listByPage(@RequestParam(name = "page", defaultValue = "1") int page, @RequestParam(name = "pageSize", defaultValue = "10") int pageSize, @RequestParam String keyword) { return new ResultBean<>(userService.listUsersByPage(page, pageSize,keyword)); } /** * 根据id查询 */ @RequestMapping(method = RequestMethod.GET, value = "/{id}") public ResultBean> getById(@PathVariable("id") Integer id) { return new ResultBean<>(userService.getUserById(id)); } /** * 新增 */ @RequestMapping(method = RequestMethod.POST) public ResultBean> insert(@RequestBody User user) { return new ResultBean<>(userService.insertUser(user)); } /** * 删除 */ @RequestMapping(method = RequestMethod.DELETE, value = "/{id}") public ResultBean> deleteById(@PathVariable("id") Integer id) { return new ResultBean<>(userService.deleteUserById(id)); } /** * 修改 */ @RequestMapping(method = RequestMethod.PUT) public ResultBean> updateById(@RequestBody User user) { return new ResultBean<>(userService.updateUser(user)); } } ``` ### 2.Service模板代码示例 ```java package cn.hellochaos.generator.service; import cn.hellochaos.generator.entity.User; import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; /** ** 用户 服务类 *
* * @author chaos * @since 2020-05-02 */ public interface UserService { /** * 分页查询User * * @param page 当前页数 * @param pageSize 页的大小 * @param keyword 搜索关键词 * @return 返回mybatis-plus的Page对象,其中records字段为符合条件的查询结果 * @author chaos * @since 2020-05-02 */ Page* 用户 服务实现类 *
* * @author chaos * @since 2020-05-02 */ @Slf4j @Service public class UserServiceImpl extends ServiceImpl