Skip to content

Commit

Permalink
更新说明文件
Browse files Browse the repository at this point in the history
  • Loading branch information
dolyw committed Apr 4, 2019
1 parent 35cc656 commit 298455f
Show file tree
Hide file tree
Showing 18 changed files with 247 additions and 118 deletions.
67 changes: 51 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,76 @@
# SpringBootGenerator(SpringBoot1.5版)
# SpringBootGenerator(1.5版)

> SpringBoot1.5版(SpringBoot2.1版切换主分支(master))
> 参考:[https://github.com/lihengming/spring-boot-api-project-seed](https://github.com/lihengming/spring-boot-api-project-seed)
> SpringBoot1.5版(Test类生成代码)
### 项目相关
#### 项目相关

* JavaDoc:[https://apidoc.gitee.com/wang926454/SpringBootGenerator](https://apidoc.gitee.com/wang926454/SpringBootGenerator)
版本 | 操作 | 链接
----|------|----
SpringBoot1.5版 | Test类生成代码 | 当前
SpringBoot2.1版 | Test类生成代码 | [https://github.com/wang926454/SpringBootGenerator](https://github.com/wang926454/SpringBootGenerator)
SpringBoot1.5版 | 可视化界面操作生成代码 | [https://github.com/wang926454/SpringBootGenerator](https://github.com/wang926454/SpringBootGenerator)

#### 项目介绍

SpringBootGenerator是一个基于SpringBoot & MyBatis的种子项目,用于快速构建中小型API、RESTful API项目,稳定、简单、快速,使我们摆脱那些重复劳动,专注于业务代码的编写,能在短短几十秒钟内实现一套简单的API(自动生成Model、Mapper、MapperXML、Service、ServiceImpl、Controller基础代码),并运行提供服务
SpringBootGenerator是一个基于SpringBoot & MyBatis的种子项目,用于快速构建中小型项目,稳定、简单、快速,使我们摆脱那些重复劳动,专注于业务代码的编写,能在短短几十秒钟内实现一套简单的基础代码(自动生成Model、Mapper、MapperXML、Service、ServiceImpl、Controller、JS、Vue等自定义模板代码),并运行提供服务

1. 统一响应结果封装
2. 统一异常处理
3. 集成通用Mapper插件、PageHelper分页插件,实现单表业务零SQL
4. Controller模板提供POST和RESTful两套
4. 优化Controller方法
5. 通用BaseService

在原项目上修改

1. 改为SpringBoot的通用Mapper插件、PageHelper分页插件,配置更少
2. 提供更完整的通用BaseService
3. 优化Controller方法

#### 软件架构

SpringBoot + Mybatis + PageHelper + 通用Mapper

##### 组织结构

``` lua
src
├─main -- main运行主体代码
│ ├─java
│ └─resources
└─test -- test单元测试
├─java
│ └─com
│ ├─example
│ │ ├─base -- 通用单元测试基础类
│ │ ├─generator -- 代码生成器第一版,第二版执行Main函数
│ │ └─test -- test代码
│ └─uframe -- 代码生成器第二版核心代码
│ └─generator -- 代码生成器第二版核心代码
└─resources -- test resources
├─config -- 代码生成器第二版配置代码
├─sql -- SQL文件示例
└─template
├─one -- 代码生成器第一版模板
└─two -- 代码生成器第二版模板
├─LayUI -- 代码生成器第二版LayUI模板示例
└─RESTful -- 代码生成器第二版RESTful模板示例
```

#### 安装教程

##### 第一版

1. 解压后执行src\test\resources\sql\MySQL.sql脚本创建数据库和表
2. src\test\java\com\example\generator\CodeGeneratorOne.java运行Main方法生成代码
3. 可以自行修改src\test\resources\template\one下的模板
4. Controller模板提供POST和RESTful两套
5. 修改src\test\java\com\example\generator\CodeGenerator.java下的CONTROLLER_TYPE可以生成REST或者POST的Controller模板

##### 第二版

1. 解压后执行src\test\resources\sql\MySQL.sql脚本创建数据库和表
2. src\test\java\com\example\generator\CodeGenerator.java运行Main方法生成代码
2. src\test\java\com\example\generator\CodeGeneratorTwo.java运行Main方法生成代码
3. 可以自行修改src\test\resources\template\two下的模板
4. 模板提供两套示例LayUI和RESTful,可以自行添加模板
5. 修改src\test\java\com\example\generator\CodeGeneratorTwo.java下的模板路径即可

#### 使用说明

1. 可以自行修改src\test\resources\template下的模板
2. 修改src\test\java\com\example\generator\CodeGenerator.java下的CONTROLLER_TYPE可以生成REST或者POST的Controller模板
1. 数据库要配置好,且必须有帐号权限

#### 参与贡献

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/example/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @date 2018/11/16 19:29
*/
@SpringBootApplication
@tk.mybatis.spring.annotation.MapperScan("com.example.mapper")
@tk.mybatis.spring.annotation.MapperScan({ "com.example.mapper", "com.example.dao" })
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
Expand Down
12 changes: 6 additions & 6 deletions src/test/java/com/example/generator/CodeGeneratorTwo.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class CodeGeneratorTwo {
/**
* 生成代码模板位置
*/
private static final String TEMPLATE_FILE_PATH = PROJECT_PATH + "/src/test/resources/template/two/LayUI";
private static final String TEMPLATE_FILE_PATH = PROJECT_PATH + "/src/test/resources/template/two/RESTful";

/**
* 有三点需要引起特别的注意
Expand All @@ -28,21 +28,21 @@ public class CodeGeneratorTwo {
*/
public static void main(String[] args) throws Exception {
// 配置表名
genCode("user", "role", "permission");
genCode("user", "role");
}

/**
* 通过表名称生成代码,Model名称通过解析数据表名称获得,下划线转大驼峰的形式
* @param tableNames 表名称...
* 通过表名称生成代码
* @param tableNames
*/
public static void genCode(String... tableNames) {
// GeneratorFacade
GeneratorFacade generatorFacade = new GeneratorFacade();
// 开始执行
try {
// 删除旧文件
generatorFacade.deleteByAllTable(TEMPLATE_FILE_PATH);
for (String tableName : tableNames) {
// 删除旧文件
generatorFacade.deleteByTable(tableName, TEMPLATE_FILE_PATH);
// 生成新文件
generatorFacade.generateByTable(tableName, TEMPLATE_FILE_PATH);
}
Expand Down
8 changes: 4 additions & 4 deletions src/test/resources/config/generator.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# 代码生成的文件输出路径
# outRoot=E:/work/outRoot
outRoot=/src/main/java/outRoot
outRoot=/src/main

# 数据源配置
jdbc.url=jdbc:mysql://127.0.0.1:3306/dev?useUnicode=true&characterEncoding=UTF-8
Expand All @@ -16,13 +16,13 @@ jdbc.schema=
jdbc.catalog=

# basepackage属性,包路径
basepackage=com.yaic.app.pdms
basepackage=com.example
# commonspackage属性,包路径
commonspackage=com.yaic.fa
commonspackage=com.example
# namespace属性
namespace=jsp
# modulepackage属性,模块名称
modulepackage=pdms
modulepackage=generator

# 需要移除的表名前缀,使用逗号进行分隔多个前缀,示例值: t_,table_
tableRemovePrefixes=
Expand Down
58 changes: 0 additions & 58 deletions src/test/resources/config/generator.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import com.alibaba.fastjson.JSON;
import ${commonspackage}.dto.JsonRequest;
import com.yaic.fa.mybatis.pagehelper.PageInfo;
import com.mybatis.pagehelper.PageInfo;

import ${basepackage}.dto.custom.${className}Dto;
import ${basepackage}.service.${className}Service;
Expand All @@ -39,6 +39,8 @@ public class ${className}Controller {

/**
* 主页面
* @author Generator
* @date ${now?string('yyyy-MM-dd HH:mm:ss')}
*/
@RequestMapping
public String index(HttpServletRequest request) {
Expand All @@ -47,6 +49,8 @@ public String index(HttpServletRequest request) {

/**
* 列表
* @author Generator
* @date ${now?string('yyyy-MM-dd HH:mm:ss')}
*/
@ResponseBody
@RequestMapping(value = "list", method = RequestMethod.POST)
Expand All @@ -62,9 +66,11 @@ public Map<String, Object> list(@RequestBody ${className}Dto ${classNameLower}Dt

/**
* 预新增
* @author Generator
* @date ${now?string('yyyy-MM-dd HH:mm:ss')}
*/
@ResponseBody
@RequestMapping(value = "/prepareInsert")
@RequestMapping(value = "/prepareInsert", method = RequestMethod.POST)
public Map<String, Object> prepareInsert(@RequestBody ${className}Dto ${classNameLower}Dto) throws Exception {
Map<String, Object> resultMap = new HashMap<String, Object>(16);
${classNameLower}Dto = new ${className}Dto();
Expand All @@ -74,9 +80,11 @@ public Map<String, Object> prepareInsert(@RequestBody ${className}Dto ${classNam

/**
* 新增
* @author Generator
* @date ${now?string('yyyy-MM-dd HH:mm:ss')}
*/
@ResponseBody
@RequestMapping(value = "/insert")
@RequestMapping(value = "/insert", method = RequestMethod.POST)
public Map<String, Object> insert(@RequestBody ${className}Dto ${classNameLower}Dto) throws Exception {
Map<String, Object> resultMap = new HashMap<String, Object>(16);
${classNameLower}Service.insertNotNull(${classNameLower}Dto);
Expand All @@ -87,9 +95,11 @@ public Map<String, Object> insert(@RequestBody ${className}Dto ${classNameLower}

/**
* 预修改
* @author Generator
* @date ${now?string('yyyy-MM-dd HH:mm:ss')}
*/
@ResponseBody
@RequestMapping(value = "/prepareUpdate")
@RequestMapping(value = "/prepareUpdate", method = RequestMethod.POST)
public Map<String, Object> prepareUpdate(@RequestBody ${className}Dto ${classNameLower}Dto) throws Exception {
Map<String, Object> resultMap = new HashMap<String, Object>(16);
${classNameLower}Dto = ${classNameLower}Service.selectByPrimaryKey(${classNameLower}Dto);
Expand All @@ -99,9 +109,11 @@ public Map<String, Object> prepareUpdate(@RequestBody ${className}Dto ${classNam

/**
* 修改
* @author Generator
* @date ${now?string('yyyy-MM-dd HH:mm:ss')}
*/
@ResponseBody
@RequestMapping(value = "/update")
@RequestMapping(value = "/update", method = RequestMethod.POST)
public Map<String, Object> update(@RequestBody ${className}Dto ${classNameLower}Dto) throws Exception {
Map<String, Object> resultMap = new HashMap<String, Object>(16);
${classNameLower}Service.updateByPrimaryKey(${classNameLower}Dto);
Expand All @@ -112,10 +124,12 @@ public Map<String, Object> update(@RequestBody ${className}Dto ${classNameLower}
/**
* 删除
* @author Generator
* @date ${now?string('yyyy-MM-dd HH:mm:ss')}
*/
@ResponseBody
@Transactional
@RequestMapping(value = "/delete")
@RequestMapping(value = "/delete", method = RequestMethod.POST)
public Map<String, Object> delete(@RequestBody JsonRequest<${className}Dto> jsonRequest) throws Exception {
Map<String, Object> resultMap = new HashMap<String, Object>(16);
List<${className}Dto> ${classNameLower}List = JSON.parseArray((jsonRequest.getExtend().get("${classNameLower}List")), ${className}Dto.class);
Expand All @@ -126,5 +140,4 @@ public Map<String, Object> delete(@RequestBody JsonRequest<${className}Dto> json
resultMap.put("msg", "删除成功");
return resultMap;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,24 @@
import java.util.List;

import ${basepackage}.dto.custom.${className}Dto;
import org.springframework.stereotype.Repository;
import ${commonspackage}.dao.BaseDao;

/**
* ${className}Dao
* @author Generator
* @date ${now?string('yyyy-MM-dd HH:mm:ss')}
*/
@Repository
public interface ${className}Dao extends BaseDao<${className}Dto> {

/**
* 列表
* @param ${classNameLower}Dto
* @return java.util.List<${basepackage}.dto.custom.${className}Dto;>
* @author Generator
* @date ${now?string('yyyy-MM-dd HH:mm:ss')}
*/
public List<${className}Dto> findPageInfo(${className}Dto ${classNameLower}Dto);

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import java.io.Serializable;
import java.util.Date;

import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

import org.apache.commons.lang.builder.EqualsBuilder;
Expand Down Expand Up @@ -63,6 +65,7 @@ public String toString() {
<#else>
<#if column.pk>
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
</#if>
private ${column.javaType} ${column.columnNameLower};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
*/
public interface ${className}Service extends IBaseService<${className}Dto> {

/**
* 列表
* @param ${classNameLower}Dto
* @return java.util.List<${basepackage}.dto.custom.${className}Dto;>
* @author Generator
* @date ${now?string('yyyy-MM-dd HH:mm:ss')}
*/
public PageInfo<${className}Dto> findPageInfo(int page, int rows, ${className}Dto ${classNameLower}Dto, String orderBy);

}
Loading

0 comments on commit 298455f

Please sign in to comment.