diff --git a/CHANGELOG.md b/CHANGELOG.md index 4cd9615f..a89d3817 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ - Add `DownloadHandler` `DefaultDownloadHandler` 文件下载回调自定义处理器 - Modify `config/WebMvcConfig` --> `core/SpringBootPlusWebMvcConfig` - Modify `ImageController` --> `ResouceController`,请求路径 `/api/resource` +- Add `SysUser` CRUD ### 🐞 Bug Fixes - Fix 文件下载路径潜在安全漏洞,过滤 `../` 非法路径参数 @@ -25,6 +26,7 @@ ### 📔 Documentation - [spring-boot-plus-architecture](https://raw.githubusercontent.com/geekidea/spring-boot-plus/master/docs/img/spring-boot-plus-architecture.jpg) +- [5 Minutes Finish CRUD](https://github.com/geekidea/spring-boot-plus#5-minutes-finish-crud) ### 🔨 Dependency Upgrades - `pom.xml` 使用 `spring-boot-starter-validation` 替换 `hibernate-validator` 依赖 diff --git a/README-zh.md b/README-zh.md index 9fef29cf..4457d0e0 100644 --- a/README-zh.md +++ b/README-zh.md @@ -88,7 +88,82 @@ cd spring-boot-plus mvn clean package -Plocal ``` -### 项目入口类 + +## 5分钟完成增删改查 + +### 创建数据库表 +```sql +-- ---------------------------- +-- Table structure for sys_user +-- ---------------------------- +drop table if exists `sys_user`; +create table sys_user( + id bigint not null comment '主键', + name varchar(20) null comment '用户名称', + account varchar(20) not null comment '账号', + pwd varchar(20) not null comment '密码', + remark varchar(200) null comment '备注', + create_time timestamp default CURRENT_TIMESTAMP null comment '创建时间', + update_time timestamp null comment '修改时间', + primary key (`id`), + constraint sys_user_account_uindex + unique (account) +) comment '系统用户'; +-- ---------------------------- +-- Records of sys_user +-- ---------------------------- +INSERT INTO sys_user (id, name, account, pwd, remark, create_time, update_time) VALUES (1, 'Administrator', 'admin', '123456', 'Administrator Account', '2019-08-26 00:52:01', null); + +``` + +### CodeGenerator CRUD +> 修改数据库信息 + +>修改组件名称/作者/数据库表名称/主键id + +```text +/src/test/java/io/geekidea/springbootplus/test/CodeGenerator.java +``` + +```java +/** + * spring-boot-plus代码生成器入口类 + * @author geekidea + * @date 2018-11-08 + */ +public class CodeGenerator { + private static final String USER_NAME = "root"; + private static final String PASSWORD = "root"; + private static final String DRIVER_NAME = "com.mysql.jdbc.Driver"; + private static final String DRIVER_URL = "jdbc:mysql://localhost:3306/spring_boot_plus?useUnicode=true&characterEncoding=UTF-8&useSSL=false"; + // CODE... + // ############################ 配置部分 start ############################ + // 模块名称 + private static final String MODULE_NAME = "system"; + // 作者 + private static final String AUTHOR = "geekidea"; + // 生成的表名称 + private static final String TABLE_NAME = "sys_user"; + // 主键数据库列名称 + private static final String PK_ID_COLUMN_NAME = "id"; + // 代码生成策略 true:All/false:SIMPLE + private static final boolean GENERATOR_STRATEGY = true; + // 分页列表查询是否排序 true:有排序参数/false:无 + private static final boolean PAGE_LIST_ORDER = false; + // ############################ 配置部分 end ############################ + + public static void main(String[] args) { + // Run... + } +} +``` + +### 启动项目 +> 项目入口类 +```text +/src/main/java/io/geekidea/springbootplus/SpringBootPlusApplication.java +``` + ```java /** * spring-boot-plus 项目启动入口 @@ -114,6 +189,12 @@ public class SpringBootPlusApplication { } ``` +### 访问项目swagger文档 +[http://127.0.0.1:8888/swagger-ui.html](http://127.0.0.1:8888/swagger-ui.html) + +### 系统用户 增删改查分页Swagger +![sys_user_swagger-zh.png](https://raw.githubusercontent.com/geekidea/spring-boot-plus/master/docs/img/sys_user_swagger-zh.png) + ## 快速开始 [快速开始](https://springboot.plus/guide/quick-start.html) diff --git a/README.md b/README.md index a607e2d0..ee2a4de5 100644 --- a/README.md +++ b/README.md @@ -27,15 +27,15 @@ ## Purpose > Everyone can develop projects independently, quickly and efficiently! -## Docs +## Repository #### [GITHUB](https://github.com/geekidea/spring-boot-plus) | [GITEE](https://gitee.com/geekidea/spring-boot-plus) -#### Website:[springboot.plus](http://springboot.plus "springboot.plus") +#### Website +#### [springboot.plus](http://springboot.plus "springboot.plus") # Architecture ![spring-boot-plus-architecture.jpg](https://raw.githubusercontent.com/geekidea/spring-boot-plus/master/docs/img/spring-boot-plus-architecture.jpg) - ## Features - Integrated spring boot common development component set, common configuration, AOP log, etc - Integrated mybatis-plus fast dao operation @@ -48,7 +48,6 @@ - Integrated Spring Boot Admin, real-time detection of project operation - Integrate maven-assembly-plugin for different environment package deployment, including startup and restart commands, and extract configuration files to external config directory - ### Project Environment Middleware | Version | Remark -|-|- @@ -88,7 +87,82 @@ cd spring-boot-plus mvn clean package -Plocal ``` -### Project Main Class + +## 5 Minutes Finish CRUD + +### 1. Create Table +```sql +-- ---------------------------- +-- Table structure for sys_user +-- ---------------------------- +drop table if exists `sys_user`; +create table sys_user( + id bigint not null comment 'id', + name varchar(20) null comment 'name', + account varchar(20) not null comment 'account', + pwd varchar(20) not null comment 'password', + remark varchar(200) null comment 'remark', + create_time timestamp default CURRENT_TIMESTAMP null comment 'create time', + update_time timestamp null comment 'update time', + primary key (`id`), + constraint sys_user_account_uindex + unique (account) +) comment 'SystemUser'; +-- ---------------------------- +-- Records of sys_user +-- ---------------------------- +INSERT INTO sys_user (id, name, account, pwd, remark, create_time, update_time) VALUES (1, 'Administrator', 'admin', '123456', 'Administrator Account', '2019-08-26 00:52:01', null); + +``` + +### 2. Generator CRUD CODE +> Modify database info + +> Modify module name / author / table name / primary key id + +```text +/src/test/java/io/geekidea/springbootplus/test/CodeGenerator.java +``` + +```java +/** + * spring-boot-plus Code Generator + * @author geekidea + * @date 2018-11-08 + */ +public class CodeGenerator { + private static final String USER_NAME = "root"; + private static final String PASSWORD = "root"; + private static final String DRIVER_NAME = "com.mysql.jdbc.Driver"; + private static final String DRIVER_URL = "jdbc:mysql://localhost:3306/spring_boot_plus?useUnicode=true&characterEncoding=UTF-8&useSSL=false"; + // CODE... + // ############################ Config start ############################ + // Module name + private static final String MODULE_NAME = "system"; + // Author + private static final String AUTHOR = "geekidea"; + // Table name + private static final String TABLE_NAME = "sys_user"; + // Primary key id + private static final String PK_ID_COLUMN_NAME = "id"; + // Generator strategy. true:All / false:SIMPLE + private static final boolean GENERATOR_STRATEGY = true; + // Pagination list query Whether to sort. true:sort/false:non + private static final boolean PAGE_LIST_ORDER = false; + // ############################ Config end ############################ + + public static void main(String[] args) { + // Run... + } +} +``` + +### 3. Startup Project +> Project Main Class +```text +/src/main/java/io/geekidea/springbootplus/SpringBootPlusApplication.java +``` + ```java /** * spring-boot-plus Project Main Class @@ -114,6 +188,13 @@ public class SpringBootPlusApplication { } ``` +### 4. Access project swagger docs +[http://127.0.0.1:8888/swagger-ui.html](http://127.0.0.1:8888/swagger-ui.html) + +### 5. SysUser CRUD Swagger +![sys_user_swagger.png](https://raw.githubusercontent.com/geekidea/spring-boot-plus/master/docs/img/sys_user_swagger.png) + + ## Quick Start [Quick Start](https://springboot.plus/guide/quick-start.html) diff --git a/docs/img/sys_user_swagger-zh.png b/docs/img/sys_user_swagger-zh.png new file mode 100644 index 00000000..26981943 Binary files /dev/null and b/docs/img/sys_user_swagger-zh.png differ diff --git a/docs/img/sys_user_swagger.png b/docs/img/sys_user_swagger.png new file mode 100644 index 00000000..e1565d96 Binary files /dev/null and b/docs/img/sys_user_swagger.png differ diff --git a/src/main/java/io/geekidea/springbootplus/system/entity/SysUser.java b/src/main/java/io/geekidea/springbootplus/system/entity/SysUser.java new file mode 100644 index 00000000..6e411c64 --- /dev/null +++ b/src/main/java/io/geekidea/springbootplus/system/entity/SysUser.java @@ -0,0 +1,51 @@ +package io.geekidea.springbootplus.system.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import java.util.Date; +import com.baomidou.mybatisplus.annotation.TableId; +import io.geekidea.springbootplus.common.entity.BaseEntity; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.Date; + +/** + *
+ * SystemUser + *
+ * + * @author geekidea + * @since 2019-08-26 + */ +@Data +@EqualsAndHashCode(callSuper = true) +@ApiModel(value="SysUser对象", description="SystemUser") +public class SysUser extends BaseEntity { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "id") + @TableId(value = "id", type = IdType.ID_WORKER) + private Long id; + + @ApiModelProperty(value = "name") + private String name; + + @ApiModelProperty(value = "account") + private String account; + + @ApiModelProperty(value = "password") + private String pwd; + + @ApiModelProperty(value = "remark") + private String remark; + + @ApiModelProperty(value = "create time") + private Date createTime; + + @ApiModelProperty(value = "update time") + private Date updateTime; + +} diff --git a/src/main/java/io/geekidea/springbootplus/system/mapper/SysUserMapper.java b/src/main/java/io/geekidea/springbootplus/system/mapper/SysUserMapper.java new file mode 100644 index 00000000..42cce5ba --- /dev/null +++ b/src/main/java/io/geekidea/springbootplus/system/mapper/SysUserMapper.java @@ -0,0 +1,40 @@ +package io.geekidea.springbootplus.system.mapper; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import io.geekidea.springbootplus.system.entity.SysUser; +import io.geekidea.springbootplus.system.web.param.SysUserQueryParam; +import io.geekidea.springbootplus.system.web.vo.SysUserQueryVo; +import org.apache.ibatis.annotations.Param; +import org.springframework.stereotype.Repository; + +import java.io.Serializable; + +/** + *+ * SystemUser Mapper 接口 + *
+ * + * @author geekidea + * @since 2019-08-26 + */ +@Repository +public interface SysUserMapper extends BaseMapper+ * SystemUser 服务类 + *
+ * + * @author geekidea + * @since 2019-08-26 + */ +public interface SysUserService extends BaseService+ * SystemUser 服务实现类 + *
+ * + * @author geekidea + * @since 2019-08-26 + */ +@Slf4j +@Service +@Transactional(rollbackFor = Exception.class) +public class SysUserServiceImpl extends BaseServiceImpl+ * SystemUser 前端控制器 + *
+ * + * @author geekidea + * @since 2019-08-26 + */ +@Slf4j +@RestController +@RequestMapping("/sysUser") +@Api("SystemUser API") +public class SysUserController extends BaseController { + + @Autowired + private SysUserService sysUserService; + + /** + * Save SystemUser + */ + @PostMapping("/add") + @ApiOperation(value = "Save SysUser",notes = "Save SystemUser",response = ApiResult.class) + public ApiResult+ * SystemUser 查询参数对象 + *
+ * + * @author geekidea + * @date 2019-08-26 + */ +@Data +@EqualsAndHashCode(callSuper = true) +@ApiModel(value="SysUserQueryParam对象", description="SystemUser查询参数") +public class SysUserQueryParam extends QueryParam { + private static final long serialVersionUID = 1L; +} diff --git a/src/main/java/io/geekidea/springbootplus/system/web/vo/SysUserQueryVo.java b/src/main/java/io/geekidea/springbootplus/system/web/vo/SysUserQueryVo.java new file mode 100644 index 00000000..d04063ec --- /dev/null +++ b/src/main/java/io/geekidea/springbootplus/system/web/vo/SysUserQueryVo.java @@ -0,0 +1,44 @@ +package io.geekidea.springbootplus.system.web.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import java.io.Serializable; + +import java.util.Date; + +/** + *+ * SystemUser 查询结果对象 + *
+ * + * @author geekidea + * @date 2019-08-26 + */ +@Data +@ApiModel(value="SysUserQueryVo对象", description="SystemUser查询参数") +public class SysUserQueryVo implements Serializable{ + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "id") + private Long id; + + @ApiModelProperty(value = "name") + private String name; + + @ApiModelProperty(value = "account") + private String account; + + @ApiModelProperty(value = "password") + private String pwd; + + @ApiModelProperty(value = "remark") + private String remark; + + @ApiModelProperty(value = "create time") + private Date createTime; + + @ApiModelProperty(value = "update time") + private Date updateTime; + +} \ No newline at end of file diff --git a/src/main/resources/config/application-local.yml b/src/main/resources/config/application-local.yml index 37c7bbf2..32df230e 100644 --- a/src/main/resources/config/application-local.yml +++ b/src/main/resources/config/application-local.yml @@ -31,7 +31,7 @@ spring: datasource: url: jdbc:mysql://localhost:3306/spring_boot_plus?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false&allowPublicKeyRetrieval=true username: root - password: rootroot + password: root # Redis配置 redis: diff --git a/src/main/resources/mapper/system/SysUserMapper.xml b/src/main/resources/mapper/system/SysUserMapper.xml new file mode 100644 index 00000000..100c3e7c --- /dev/null +++ b/src/main/resources/mapper/system/SysUserMapper.xml @@ -0,0 +1,18 @@ + + +