1.0版本完成
This commit is contained in:
12
yshop-api/src/test/java/co/yixiang/test/BaseTest.java
Normal file
12
yshop-api/src/test/java/co/yixiang/test/BaseTest.java
Normal file
@ -0,0 +1,12 @@
|
||||
|
||||
package co.yixiang.test;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
public class BaseTest {
|
||||
|
||||
}
|
198
yshop-api/src/test/java/co/yixiang/test/CodeGenerator.java
Normal file
198
yshop-api/src/test/java/co/yixiang/test/CodeGenerator.java
Normal file
@ -0,0 +1,198 @@
|
||||
|
||||
|
||||
package co.yixiang.test;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||
import com.baomidou.mybatisplus.generator.AutoGenerator;
|
||||
import com.baomidou.mybatisplus.generator.InjectionConfig;
|
||||
import com.baomidou.mybatisplus.generator.config.*;
|
||||
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
|
||||
import com.baomidou.mybatisplus.generator.config.rules.DateType;
|
||||
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 代码生成器入口类
|
||||
*/
|
||||
public class CodeGenerator {
|
||||
|
||||
private static final String USER_NAME = "root";
|
||||
private static final String PASSWORD = "root";
|
||||
private static final String DRIVER_NAME = "com.mysql.cj.jdbc.Driver";
|
||||
private static final String DRIVER_URL = "jdbc:mysql://127.0.0.1:3306/yxshop?autoReconnect=true&useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8";
|
||||
|
||||
private static final String PARENT_PACKAGE = "co.yixiang";
|
||||
private static final String SUPER_ENTITY = PARENT_PACKAGE + ".common.entity.BaseEntity";
|
||||
private static final String[] SUPER_ENTITY_COMMON_COLUMNS = new String[]{};
|
||||
private static final String SUPER_CONTROLLER = PARENT_PACKAGE + ".common.web.controller.BaseController";
|
||||
private static final String SUPER_SERVICE = PARENT_PACKAGE + ".common.service.BaseService";
|
||||
private static final String SUPER_SERVICE_IMPL = PARENT_PACKAGE + ".common.service.impl.BaseServiceImpl";
|
||||
|
||||
private static final String PROJECT_PACKAGE_PATH = "co/yixiang";
|
||||
|
||||
private static final String PARENT_PACKAGE2 = "co.yixiang.modules";
|
||||
|
||||
|
||||
// ############################ 配置部分 start ############################
|
||||
// 模块名称
|
||||
private static final String MODULE_NAME = "user";
|
||||
// 作者
|
||||
private static final String AUTHOR = "hupeng";
|
||||
// 生成的表名称
|
||||
private static final String TABLE_NAME = "yx_user_address";
|
||||
// 主键数据库列名称
|
||||
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) {
|
||||
// 代码生成器
|
||||
AutoGenerator mpg = new AutoGenerator();
|
||||
|
||||
// 全局配置
|
||||
GlobalConfig gc = new GlobalConfig();
|
||||
String projectPath = System.getProperty("user.dir");
|
||||
gc.setOutputDir(projectPath + "/yshop-api/src/main/java");
|
||||
gc.setAuthor(AUTHOR);
|
||||
gc.setOpen(false); // 是否打开输出目录
|
||||
gc.setSwagger2(true); // 启用swagger注解
|
||||
gc.setIdType(IdType.ID_WORKER); // 主键类型:ID_WORKER
|
||||
gc.setServiceName("%sService"); // 自定义文件命名,注意 %s 会自动填充表实体属性!
|
||||
gc.setFileOverride(true); // 是否覆盖已有文件
|
||||
gc.setDateType(DateType.ONLY_DATE); // 设置日期类型为Date
|
||||
|
||||
mpg.setGlobalConfig(gc);
|
||||
|
||||
// 数据源配置
|
||||
DataSourceConfig dsc = new DataSourceConfig();
|
||||
dsc.setUrl(DRIVER_URL);
|
||||
// dsc.setSchemaName("public");
|
||||
dsc.setDriverName(DRIVER_NAME);
|
||||
dsc.setUsername(USER_NAME);
|
||||
dsc.setPassword(PASSWORD);
|
||||
mpg.setDataSource(dsc);
|
||||
|
||||
// 包配置
|
||||
PackageConfig pc = new PackageConfig();
|
||||
pc.setModuleName(MODULE_NAME);
|
||||
pc.setParent("co.yixiang.modules");
|
||||
pc.setController("web.controller");
|
||||
|
||||
mpg.setPackageInfo(pc);
|
||||
|
||||
// 自定义配置
|
||||
InjectionConfig cfg = new InjectionConfig() {
|
||||
@Override
|
||||
public void initMap() {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("customField", "Hello " + this.getConfig().getGlobalConfig().getAuthor());
|
||||
// 查询参数包路径
|
||||
map.put("queryParamPath",PARENT_PACKAGE2 + StringPool.DOT + pc.getModuleName() + ".web.param." + underlineToPascal(TABLE_NAME) + "QueryParam");
|
||||
// 查询参数共公包路径
|
||||
map.put("queryParamCommonPath",PARENT_PACKAGE + StringPool.DOT + "common.web.param." + "QueryParam");
|
||||
// 查询参数共公包路径
|
||||
map.put("idParamPath",PARENT_PACKAGE + StringPool.DOT + "common.web.param." + "IdParam");
|
||||
// 响应结果包路径
|
||||
map.put("queryVoPath",PARENT_PACKAGE2 + StringPool.DOT + pc.getModuleName() + ".web.vo." + underlineToPascal(TABLE_NAME) + "QueryVo");
|
||||
// 实体对象名称
|
||||
map.put("entityObjectName",underlineToCamel(TABLE_NAME));
|
||||
// service对象名称
|
||||
map.put("serviceObjectName",underlineToCamel(TABLE_NAME) + "Service");
|
||||
// mapper对象名称
|
||||
map.put("mapperObjectName",underlineToCamel(TABLE_NAME) + "Mapper");
|
||||
// 主键ID列名
|
||||
map.put("pkIdColumnName",PK_ID_COLUMN_NAME);
|
||||
// 主键ID驼峰名称
|
||||
map.put("pkIdCamelName",underlineToCamel(PK_ID_COLUMN_NAME));
|
||||
// 导入分页类
|
||||
map.put("paging",PARENT_PACKAGE + ".common.web.vo.Paging");
|
||||
// 导入排序枚举
|
||||
map.put("orderEnum",PARENT_PACKAGE + ".common.enums.OrderEnum");
|
||||
// 分页列表查询是否排序
|
||||
map.put("pageListOrder",PAGE_LIST_ORDER);
|
||||
// 导入排序查询参数类
|
||||
map.put("orderQueryParamPath",PARENT_PACKAGE + StringPool.DOT + "common.web.param." + "OrderQueryParam");
|
||||
// 代码生成策略
|
||||
map.put("generatorStrategy",GENERATOR_STRATEGY);
|
||||
this.setMap(map);
|
||||
}
|
||||
};
|
||||
List<FileOutConfig> focList = new ArrayList<>();
|
||||
focList.add(new FileOutConfig("/templates/mapper.xml.vm") {
|
||||
@Override
|
||||
public String outputFile(TableInfo tableInfo) {
|
||||
// 自定义输入文件名称
|
||||
return projectPath + "/yshop-api/src/main/resources/mapper/" + pc.getModuleName()
|
||||
+ "/" + tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML;
|
||||
}
|
||||
});
|
||||
|
||||
// 自定义queryParam模板
|
||||
focList.add(new FileOutConfig("/templates/queryParam.java.vm") {
|
||||
@Override
|
||||
public String outputFile(TableInfo tableInfo) {
|
||||
return projectPath + "/yshop-api/src/main/java/"+ PROJECT_PACKAGE_PATH +"/modules/" + pc.getModuleName() + "/web/param/" + tableInfo.getEntityName() + "QueryParam" + StringPool.DOT_JAVA;
|
||||
}
|
||||
});
|
||||
|
||||
// 自定义queryVo模板
|
||||
focList.add(new FileOutConfig("/templates/queryVo.java.vm") {
|
||||
@Override
|
||||
public String outputFile(TableInfo tableInfo) {
|
||||
return projectPath + "/yshop-api/src/main/java/"+ PROJECT_PACKAGE_PATH +"/modules/" + pc.getModuleName() + "/web/vo/" + tableInfo.getEntityName() + "QueryVo" + StringPool.DOT_JAVA;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
cfg.setFileOutConfigList(focList);
|
||||
mpg.setCfg(cfg);
|
||||
mpg.setTemplate(new TemplateConfig().setXml(null));
|
||||
|
||||
// 策略配置
|
||||
StrategyConfig strategy = new StrategyConfig();
|
||||
strategy.setNaming(NamingStrategy.underline_to_camel);
|
||||
strategy.setColumnNaming(NamingStrategy.underline_to_camel);
|
||||
strategy.setSuperEntityClass(SUPER_ENTITY);
|
||||
strategy.setEntityLombokModel(true);
|
||||
strategy.setRestControllerStyle(true);
|
||||
strategy.setSuperControllerClass(SUPER_CONTROLLER);
|
||||
strategy.setSuperServiceClass(SUPER_SERVICE);
|
||||
strategy.setSuperServiceImplClass(SUPER_SERVICE_IMPL);
|
||||
strategy.setInclude(TABLE_NAME);
|
||||
strategy.setSuperEntityColumns(SUPER_ENTITY_COMMON_COLUMNS);
|
||||
strategy.setControllerMappingHyphenStyle(true);
|
||||
/**
|
||||
* 注意,根据实际情况,进行设置
|
||||
* 当表名称的前缀和模块名称一样时,会去掉表的前缀
|
||||
* 比如模块名称为user,表明为user_info,则生成的实体名称是Info.java,一定要注意
|
||||
*/
|
||||
//strategy.setTablePrefix(pc.getModuleName() + "_");
|
||||
mpg.setStrategy(strategy);
|
||||
mpg.execute();
|
||||
}
|
||||
|
||||
public static String underlineToCamel(String underline){
|
||||
if (StringUtils.isNotBlank(underline)){
|
||||
return NamingStrategy.underlineToCamel(underline);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String underlineToPascal(String underline){
|
||||
if (StringUtils.isNotBlank(underline)){
|
||||
return NamingStrategy.capitalFirst(NamingStrategy.underlineToCamel(underline));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
114
yshop-api/src/test/resources/templates/controller.java.vm
Normal file
114
yshop-api/src/test/resources/templates/controller.java.vm
Normal file
@ -0,0 +1,114 @@
|
||||
package ${package.Controller};
|
||||
|
||||
import ${package.Entity}.${entity};
|
||||
import ${package.Service}.${table.serviceName};
|
||||
import ${cfg.queryParamPath};
|
||||
import ${cfg.queryVoPath};
|
||||
#if(${superControllerClassPackage})
|
||||
import ${superControllerClassPackage};
|
||||
#end
|
||||
import co.yixiang.common.api.ApiResult;
|
||||
#if(${swagger2})
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
#end
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
#if(${restControllerStyle})
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
#else
|
||||
import org.springframework.stereotype.Controller;
|
||||
#end
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
import ${cfg.paging};
|
||||
import ${cfg.idParamPath};
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* $!{table.comment} 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Slf4j
|
||||
#if(${restControllerStyle})
|
||||
@RestController
|
||||
#else
|
||||
@Controller
|
||||
#end
|
||||
@RequestMapping("/${cfg.entityObjectName}")
|
||||
@Api("$!{table.comment} API")
|
||||
#if(${kotlin})
|
||||
class ${table.controllerName}#if(${superControllerClass}) : ${superControllerClass}()#end
|
||||
|
||||
#else
|
||||
#if(${superControllerClass})
|
||||
public class ${table.controllerName} extends ${superControllerClass} {
|
||||
#else
|
||||
public class ${table.controllerName} {
|
||||
#end
|
||||
|
||||
@Autowired
|
||||
private ${table.serviceName} ${cfg.serviceObjectName};
|
||||
|
||||
#if(${cfg.generatorStrategy})
|
||||
/**
|
||||
* 添加$!{table.comment}
|
||||
*/
|
||||
@PostMapping("/add")
|
||||
@ApiOperation(value = "添加${entity}对象",notes = "添加$!{table.comment}",response = ApiResult.class)
|
||||
public ApiResult<Boolean> add${entity}(@Valid @RequestBody ${entity} ${cfg.entityObjectName}) throws Exception{
|
||||
boolean flag = ${cfg.serviceObjectName}.save(${cfg.entityObjectName});
|
||||
return ApiResult.result(flag);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改$!{table.comment}
|
||||
*/
|
||||
@PostMapping("/update")
|
||||
@ApiOperation(value = "修改${entity}对象",notes = "修改$!{table.comment}",response = ApiResult.class)
|
||||
public ApiResult<Boolean> update${entity}(@Valid @RequestBody ${entity} ${cfg.entityObjectName}) throws Exception{
|
||||
boolean flag = ${cfg.serviceObjectName}.updateById(${cfg.entityObjectName});
|
||||
return ApiResult.result(flag);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除$!{table.comment}
|
||||
*/
|
||||
@PostMapping("/delete")
|
||||
@ApiOperation(value = "删除${entity}对象",notes = "删除$!{table.comment}",response = ApiResult.class)
|
||||
public ApiResult<Boolean> delete${entity}(@Valid @RequestBody IdParam idParam) throws Exception{
|
||||
boolean flag = ${cfg.serviceObjectName}.removeById(idParam.getId());
|
||||
return ApiResult.result(flag);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取$!{table.comment}
|
||||
*/
|
||||
@PostMapping("/info")
|
||||
@ApiOperation(value = "获取${entity}对象详情",notes = "查看$!{table.comment}",response = ${entity}QueryVo.class)
|
||||
public ApiResult<${entity}QueryVo> get${entity}(@Valid @RequestBody IdParam idParam) throws Exception{
|
||||
${entity}QueryVo ${cfg.entityObjectName}QueryVo = ${cfg.serviceObjectName}.get${entity}ById(idParam.getId());
|
||||
return ApiResult.ok(${cfg.entityObjectName}QueryVo);
|
||||
}
|
||||
|
||||
/**
|
||||
* $!{table.comment}分页列表
|
||||
*/
|
||||
@PostMapping("/getPageList")
|
||||
@ApiOperation(value = "获取${entity}分页列表",notes = "$!{table.comment}分页列表",response = ${entity}QueryVo.class)
|
||||
public ApiResult<Paging<${entity}QueryVo>> get${entity}PageList(@Valid @RequestBody(required = false) ${entity}QueryParam ${cfg.entityObjectName}QueryParam) throws Exception{
|
||||
Paging<${entity}QueryVo> paging = ${cfg.entityObjectName}Service.get${entity}PageList(${cfg.entityObjectName}QueryParam);
|
||||
return ApiResult.ok(paging);
|
||||
}
|
||||
#end
|
||||
|
||||
}
|
||||
|
||||
#end
|
161
yshop-api/src/test/resources/templates/entity.java.vm
Normal file
161
yshop-api/src/test/resources/templates/entity.java.vm
Normal file
@ -0,0 +1,161 @@
|
||||
package ${package.Entity};
|
||||
|
||||
#foreach($pkg in ${table.importPackages})
|
||||
import ${pkg};
|
||||
#end
|
||||
#if(${swagger2})
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
#end
|
||||
#if(${entityLombokModel})
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
## import lombok.experimental.Accessors;
|
||||
#end
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* $!{table.comment}
|
||||
* </p>
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
#if(${entityLombokModel})
|
||||
@Data
|
||||
#if(${superEntityClass})
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
#else
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
#end
|
||||
## @Accessors(chain = true)
|
||||
#end
|
||||
#if(${table.convert})
|
||||
@TableName("${table.name}")
|
||||
#end
|
||||
#if(${swagger2})
|
||||
@ApiModel(value="${entity}对象", description="$!{table.comment}")
|
||||
#end
|
||||
#if(${superEntityClass})
|
||||
public class ${entity} extends ${superEntityClass}#if(${activeRecord})<${entity}>#end {
|
||||
#elseif(${activeRecord})
|
||||
public class ${entity} extends Model<${entity}> {
|
||||
#else
|
||||
public class ${entity} implements Serializable {
|
||||
#end
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
## ---------- BEGIN 字段循环遍历 ----------
|
||||
#foreach($field in ${table.fields})
|
||||
## 自定义属性,是否是主键
|
||||
#set($custom_is_pk=false)
|
||||
|
||||
#if(${field.keyFlag})
|
||||
#set($keyPropertyName=${field.propertyName})
|
||||
#end
|
||||
#if("$!field.comment" != "")
|
||||
#if(${swagger2})
|
||||
@ApiModelProperty(value = "${field.comment}")
|
||||
#else
|
||||
/**
|
||||
* ${field.comment}
|
||||
*/
|
||||
#end
|
||||
#end
|
||||
#if(${field.keyFlag})
|
||||
## 主键
|
||||
#if(${field.keyIdentityFlag})
|
||||
@TableId(value = "${field.name}", type = IdType.AUTO)
|
||||
#elseif(!$null.isNull(${idType}) && "$!idType" != "")
|
||||
## 设置主键注解
|
||||
@TableId(value = "${field.name}", type = IdType.${idType})
|
||||
## 是主键类型
|
||||
#set($custom_is_pk=true)
|
||||
#elseif(${field.convert})
|
||||
@TableId("${field.name}")
|
||||
#end
|
||||
## 普通字段
|
||||
#elseif(${field.fill})
|
||||
## ----- 存在字段填充设置 -----
|
||||
#if(${field.convert})
|
||||
@TableField(value = "${field.name}", fill = FieldFill.${field.fill})
|
||||
#else
|
||||
@TableField(fill = FieldFill.${field.fill})
|
||||
#end
|
||||
#elseif(${field.convert})
|
||||
@TableField("${field.name}")
|
||||
#end
|
||||
## 乐观锁注解
|
||||
#if(${versionFieldName}==${field.name})
|
||||
@Version
|
||||
#end
|
||||
## 逻辑删除注解
|
||||
#if(${logicDeleteFieldName}==${field.name})
|
||||
@TableLogic
|
||||
#end
|
||||
#if(${custom_is_pk})
|
||||
private ${field.propertyType} ${field.propertyName};
|
||||
#else
|
||||
private ${field.propertyType} ${field.propertyName};
|
||||
#end
|
||||
#end
|
||||
## ---------- END 字段循环遍历 ----------
|
||||
#if(!${entityLombokModel})
|
||||
#foreach($field in ${table.fields})
|
||||
#if(${field.propertyType.equals("boolean")})
|
||||
#set($getprefix="is")
|
||||
#else
|
||||
#set($getprefix="get")
|
||||
#end
|
||||
|
||||
public ${field.propertyType} ${getprefix}${field.capitalName}() {
|
||||
return ${field.propertyName};
|
||||
}
|
||||
|
||||
#if(${entityBuilderModel})
|
||||
public ${entity} set${field.capitalName}(${field.propertyType} ${field.propertyName}) {
|
||||
#else
|
||||
public void set${field.capitalName}(${field.propertyType} ${field.propertyName}) {
|
||||
#end
|
||||
this.${field.propertyName} = ${field.propertyName};
|
||||
#if(${entityBuilderModel})
|
||||
return this;
|
||||
#end
|
||||
}
|
||||
#end
|
||||
#end
|
||||
|
||||
#if(${entityColumnConstant})
|
||||
#foreach($field in ${table.fields})
|
||||
public static final String ${field.name.toUpperCase()} = "${field.name}";
|
||||
|
||||
#end
|
||||
#end
|
||||
#if(${activeRecord})
|
||||
@Override
|
||||
protected Serializable pkVal() {
|
||||
#if(${keyPropertyName})
|
||||
return this.${keyPropertyName};
|
||||
#else
|
||||
return null;
|
||||
#end
|
||||
}
|
||||
|
||||
#end
|
||||
#if(!${entityLombokModel})
|
||||
@Override
|
||||
public String toString() {
|
||||
return "${entity}{" +
|
||||
#foreach($field in ${table.fields})
|
||||
#if($!{foreach.index}==0)
|
||||
"${field.propertyName}=" + ${field.propertyName} +
|
||||
#else
|
||||
", ${field.propertyName}=" + ${field.propertyName} +
|
||||
#end
|
||||
#end
|
||||
"}";
|
||||
}
|
||||
#end
|
||||
}
|
46
yshop-api/src/test/resources/templates/mapper.java.vm
Normal file
46
yshop-api/src/test/resources/templates/mapper.java.vm
Normal file
@ -0,0 +1,46 @@
|
||||
package ${package.Mapper};
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import ${superMapperClassPackage};
|
||||
import ${package.Entity}.${entity};
|
||||
import ${cfg.queryParamPath};
|
||||
import ${cfg.queryVoPath};
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* $!{table.comment} Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
#if(${kotlin})
|
||||
interface ${table.mapperName} : ${superMapperClass}<${entity}>
|
||||
#else
|
||||
@Repository
|
||||
public interface ${table.mapperName} extends ${superMapperClass}<${entity}> {
|
||||
#if(${cfg.generatorStrategy})
|
||||
|
||||
/**
|
||||
* 根据ID获取查询对象
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
${entity}QueryVo get${entity}ById(Serializable id);
|
||||
|
||||
/**
|
||||
* 获取分页对象
|
||||
* @param page
|
||||
* @param ${cfg.entityObjectName}QueryParam
|
||||
* @return
|
||||
*/
|
||||
IPage<${entity}QueryVo> get${entity}PageList(@Param("page") Page page, @Param("param") ${entity}QueryParam ${cfg.entityObjectName}QueryParam);
|
||||
#end
|
||||
|
||||
}
|
||||
#end
|
47
yshop-api/src/test/resources/templates/mapper.xml.vm
Normal file
47
yshop-api/src/test/resources/templates/mapper.xml.vm
Normal file
@ -0,0 +1,47 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="${package.Mapper}.${table.mapperName}">
|
||||
|
||||
#if(${enableCache})
|
||||
<!-- 开启二级缓存 -->
|
||||
<cache type="org.mybatis.caches.ehcache.LoggingEhcache"/>
|
||||
|
||||
#end
|
||||
#if(${baseResultMap})
|
||||
<!-- 通用查询映射结果 -->
|
||||
<resultMap id="BaseResultMap" type="${package.Entity}.${entity}">
|
||||
#foreach($field in ${table.fields})
|
||||
#if(${field.keyFlag})##生成主键排在第一位
|
||||
<id column="${field.name}" property="${field.propertyName}" />
|
||||
#end
|
||||
#end
|
||||
#foreach($field in ${table.commonFields})##生成公共字段
|
||||
<result column="${field.name}" property="${field.propertyName}" />
|
||||
#end
|
||||
#foreach($field in ${table.fields})
|
||||
#if(!${field.keyFlag})##生成普通字段
|
||||
<result column="${field.name}" property="${field.propertyName}" />
|
||||
#end
|
||||
#end
|
||||
</resultMap>
|
||||
|
||||
#end
|
||||
<!-- 通用查询结果列 -->
|
||||
<sql id="Base_Column_List">
|
||||
#foreach($field in ${table.commonFields})
|
||||
${field.name},
|
||||
#end
|
||||
${table.fieldNames}
|
||||
</sql>
|
||||
#if(${cfg.generatorStrategy})
|
||||
|
||||
<select id="get${entity}ById" resultType="${cfg.queryVoPath}">
|
||||
select <include refid="Base_Column_List"/> from ${table.name} where ${cfg.pkIdColumnName} = #{id}
|
||||
</select>
|
||||
|
||||
<select id="get${entity}PageList" resultType="${cfg.queryVoPath}">
|
||||
select <include refid="Base_Column_List"/> from ${table.name}
|
||||
</select>
|
||||
|
||||
#end
|
||||
</mapper>
|
30
yshop-api/src/test/resources/templates/queryParam.java.vm
Normal file
30
yshop-api/src/test/resources/templates/queryParam.java.vm
Normal file
@ -0,0 +1,30 @@
|
||||
package co.yixiang.modules.${package.ModuleName}.web.param;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
#if(${cfg.pageListOrder})
|
||||
import ${cfg.orderQueryParamPath};
|
||||
#else
|
||||
import ${cfg.queryParamCommonPath};
|
||||
#end
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* $!{table.comment} 查询参数对象
|
||||
* </p>
|
||||
*
|
||||
* @author ${author}
|
||||
* @date ${date}
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ApiModel(value="${entity}QueryParam对象", description="$!{table.comment}查询参数")
|
||||
#if(${cfg.pageListOrder})
|
||||
public class ${entity}QueryParam extends OrderQueryParam {
|
||||
#else
|
||||
public class ${entity}QueryParam extends QueryParam {
|
||||
#end
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
124
yshop-api/src/test/resources/templates/queryVo.java.vm
Normal file
124
yshop-api/src/test/resources/templates/queryVo.java.vm
Normal file
@ -0,0 +1,124 @@
|
||||
package co.yixiang.modules.${package.ModuleName}.web.vo;
|
||||
|
||||
#if(${swagger2})
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
#end
|
||||
#if(${entityLombokModel})
|
||||
import lombok.Data;
|
||||
#end
|
||||
import java.io.Serializable;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* $!{table.comment} 查询结果对象
|
||||
* </p>
|
||||
*
|
||||
* @author ${author}
|
||||
* @date ${date}
|
||||
*/
|
||||
#if(${entityLombokModel})
|
||||
@Data
|
||||
#end
|
||||
#if(${table.convert})
|
||||
@TableName("${table.name}")
|
||||
#end
|
||||
@ApiModel(value="${entity}QueryVo对象", description="$!{table.comment}查询参数")
|
||||
public class ${entity}QueryVo implements Serializable{
|
||||
private static final long serialVersionUID = 1L;
|
||||
## ---------- BEGIN 字段循环遍历 ----------
|
||||
#foreach($field in ${table.fields})
|
||||
|
||||
#if(${field.keyFlag})
|
||||
#set($keyPropertyName=${field.propertyName})
|
||||
#end
|
||||
#if("$!field.comment" != "")
|
||||
#if(${swagger2})
|
||||
@ApiModelProperty(value = "${field.comment}")
|
||||
#else
|
||||
/**
|
||||
* ${field.comment}
|
||||
*/
|
||||
#end
|
||||
#end
|
||||
#if(${field.keyFlag})
|
||||
## 普通字段
|
||||
#elseif(${field.fill})
|
||||
## ----- 存在字段填充设置 -----
|
||||
#if(${field.convert})
|
||||
@TableField(value = "${field.name}", fill = FieldFill.${field.fill})
|
||||
#else
|
||||
@TableField(fill = FieldFill.${field.fill})
|
||||
#end
|
||||
#elseif(${field.convert})
|
||||
@TableField("${field.name}")
|
||||
#end
|
||||
## 乐观锁注解
|
||||
#if(${versionFieldName}==${field.name})
|
||||
@Version
|
||||
#end
|
||||
## 逻辑删除注解
|
||||
#if(${logicDeleteFieldName}==${field.name})
|
||||
@TableLogic
|
||||
#end
|
||||
private ${field.propertyType} ${field.propertyName};
|
||||
#end
|
||||
## ---------- END 字段循环遍历 ----------
|
||||
#if(!${entityLombokModel})
|
||||
#foreach($field in ${table.fields})
|
||||
#if(${field.propertyType.equals("boolean")})
|
||||
#set($getprefix="is")
|
||||
#else
|
||||
#set($getprefix="get")
|
||||
#end
|
||||
|
||||
public ${field.propertyType} ${getprefix}${field.capitalName}() {
|
||||
return ${field.propertyName};
|
||||
}
|
||||
|
||||
#if(${entityBuilderModel})
|
||||
public ${entity} set${field.capitalName}(${field.propertyType} ${field.propertyName}) {
|
||||
#else
|
||||
public void set${field.capitalName}(${field.propertyType} ${field.propertyName}) {
|
||||
#end
|
||||
this.${field.propertyName} = ${field.propertyName};
|
||||
#if(${entityBuilderModel})
|
||||
return this;
|
||||
#end
|
||||
}
|
||||
#end
|
||||
#end
|
||||
|
||||
#if(${entityColumnConstant})
|
||||
#foreach($field in ${table.fields})
|
||||
public static final String ${field.name.toUpperCase()} = "${field.name}";
|
||||
|
||||
#end
|
||||
#end
|
||||
#if(${activeRecord})
|
||||
@Override
|
||||
protected Serializable pkVal() {
|
||||
#if(${keyPropertyName})
|
||||
return this.${keyPropertyName};
|
||||
#else
|
||||
return null;
|
||||
#end
|
||||
}
|
||||
#end
|
||||
#if(!${entityLombokModel})
|
||||
@Override
|
||||
public String toString() {
|
||||
return "${entity}{" +
|
||||
#foreach($field in ${table.fields})
|
||||
#if($!{foreach.index}==0)
|
||||
"${field.propertyName}=" + ${field.propertyName} +
|
||||
#else
|
||||
", ${field.propertyName}=" + ${field.propertyName} +
|
||||
#end
|
||||
#end
|
||||
"}";
|
||||
}
|
||||
#end
|
||||
}
|
41
yshop-api/src/test/resources/templates/service.java.vm
Normal file
41
yshop-api/src/test/resources/templates/service.java.vm
Normal file
@ -0,0 +1,41 @@
|
||||
package ${package.Service};
|
||||
|
||||
import ${package.Entity}.${entity};
|
||||
import ${superServiceClassPackage};
|
||||
import ${cfg.queryParamPath};
|
||||
import ${cfg.queryVoPath};
|
||||
import ${cfg.paging};
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* $!{table.comment} 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
#if(${kotlin})
|
||||
interface ${table.serviceName} : ${superServiceClass}<${entity}>
|
||||
#else
|
||||
public interface ${table.serviceName} extends ${superServiceClass}<${entity}> {
|
||||
#if(${cfg.generatorStrategy})
|
||||
|
||||
/**
|
||||
* 根据ID获取查询对象
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
${entity}QueryVo get${entity}ById(Serializable id) throws Exception;
|
||||
|
||||
/**
|
||||
* 获取分页对象
|
||||
* @param ${cfg.entityObjectName}QueryParam
|
||||
* @return
|
||||
*/
|
||||
Paging<${entity}QueryVo> get${entity}PageList(${entity}QueryParam ${cfg.entityObjectName}QueryParam) throws Exception;
|
||||
#end
|
||||
|
||||
}
|
||||
#end
|
57
yshop-api/src/test/resources/templates/serviceImpl.java.vm
Normal file
57
yshop-api/src/test/resources/templates/serviceImpl.java.vm
Normal file
@ -0,0 +1,57 @@
|
||||
package ${package.ServiceImpl};
|
||||
|
||||
import ${package.Entity}.${entity};
|
||||
import ${package.Mapper}.${table.mapperName};
|
||||
import ${package.Service}.${table.serviceName};
|
||||
import ${cfg.queryParamPath};
|
||||
import ${cfg.queryVoPath};
|
||||
import ${superServiceImplClassPackage};
|
||||
import ${cfg.paging};
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.metadata.OrderItem;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import java.io.Serializable;
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* $!{table.comment} 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
#if(${kotlin})
|
||||
open class ${table.serviceImplName} : ${superServiceImplClass}<${table.mapperName}, ${entity}>(), ${table.serviceName} {
|
||||
|
||||
}
|
||||
#else
|
||||
public class ${table.serviceImplName} extends BaseServiceImpl<${table.mapperName}, ${entity}> implements ${table.serviceName} {
|
||||
|
||||
@Autowired
|
||||
private ${table.mapperName} ${cfg.mapperObjectName};
|
||||
#if(${cfg.generatorStrategy})
|
||||
|
||||
@Override
|
||||
public ${entity}QueryVo get${entity}ById(Serializable id) throws Exception{
|
||||
return ${cfg.mapperObjectName}.get${entity}ById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Paging<${entity}QueryVo> get${entity}PageList(${entity}QueryParam ${cfg.entityObjectName}QueryParam) throws Exception{
|
||||
Page page = setPageParam(${cfg.entityObjectName}QueryParam,OrderItem.desc("create_time"));
|
||||
IPage<${entity}QueryVo> iPage = ${cfg.mapperObjectName}.get${entity}PageList(page,${cfg.entityObjectName}QueryParam);
|
||||
return new Paging(iPage);
|
||||
}
|
||||
#end
|
||||
|
||||
}
|
||||
#end
|
Reference in New Issue
Block a user