按项目分模块,避免配置冲突
This commit is contained in:
12
cemis/pom.xml
Normal file
12
cemis/pom.xml
Normal file
@@ -0,0 +1,12 @@
|
||||
<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/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.hncy.generator</groupId>
|
||||
<artifactId>code-generator</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>cemis</artifactId>
|
||||
<name>cemis-code-generator</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
</project>
|
||||
@@ -0,0 +1,351 @@
|
||||
package com.hncy.generator.zgf.base.bean;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* 全局通用返回数据结构,支持链式写法
|
||||
*
|
||||
* <pre>
|
||||
* 不带数据的返回:
|
||||
* <example>
|
||||
* CommonResult.None none = CommonResult.None.init().success();
|
||||
* </example>
|
||||
* 带单个数据对象的返回(带泛型初始化方式一):
|
||||
* <example>
|
||||
* CommonResult.Single<String> single = CommonResult.Single.init(String.class).data("我是一个字符串");
|
||||
* </example>
|
||||
* 带列表数据对象的返回(带泛型初始化方法二):
|
||||
* <example>
|
||||
* List<String> data = new ArrayList<>();
|
||||
* data.add("你");
|
||||
* data.add("我");
|
||||
* data.add("他");
|
||||
* CommonResult.Multiple<String> multiple = new CommonResult.Multiple<>()
|
||||
* multiple.data(data);
|
||||
* </example>
|
||||
* </pre>
|
||||
*/
|
||||
public class CommonResult {
|
||||
/**
|
||||
* 状态枚举
|
||||
*/
|
||||
public enum Status {
|
||||
SUCCESS("success", 200),
|
||||
ERROR("error", 500);
|
||||
|
||||
@JsonValue
|
||||
private final String name;
|
||||
private final Integer code;
|
||||
|
||||
Status(String name, Integer code) {
|
||||
this.name = name;
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public Integer code() {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.name;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据结构基类
|
||||
*
|
||||
* @param <D> 数据类型
|
||||
* @param <T> 继承此基类的类
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Getter()
|
||||
@ToString
|
||||
private static abstract class Base<D, T extends Base<D, T>> {
|
||||
/**
|
||||
* 接口调用结果,默认为success
|
||||
*/
|
||||
@ApiModelProperty(value = "接口调用结果,默认成功为success,失败为error", required = true, example = "error")
|
||||
protected Status status = Status.SUCCESS;
|
||||
|
||||
/**
|
||||
* 接口返回状态码,默认status为success时为200,status为error时为500
|
||||
*/
|
||||
@ApiModelProperty(value = "接口返回状态码,默认成功为200,失败为500", required = true, example = "200")
|
||||
protected Integer code = Status.SUCCESS.code();
|
||||
|
||||
/**
|
||||
* 接口返回简略信息,默认为空字符串
|
||||
*/
|
||||
@ApiModelProperty(value = "接口返回简略信息,默认为空字符串", example = "登录失败")
|
||||
protected String message = "";
|
||||
|
||||
/**
|
||||
* 接口返回详细信息,默认为空字符串
|
||||
*/
|
||||
@ApiModelProperty(value = "接口返回详细信息,默认为空字符串", example = "用户名不能为空")
|
||||
protected String detail = "";
|
||||
|
||||
public Status status() {
|
||||
return this.status;
|
||||
}
|
||||
|
||||
public T status(Status status) {
|
||||
this.status = status;
|
||||
this.code = status.code;
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public Integer code() {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
public T code(Integer code) {
|
||||
this.code = code;
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public String message() {
|
||||
return this.message;
|
||||
}
|
||||
|
||||
public T message(String message) {
|
||||
this.message = message;
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public String detail() {
|
||||
return this.detail;
|
||||
}
|
||||
|
||||
public T detail(String detail) {
|
||||
this.detail = detail;
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public T success() {
|
||||
this.status = Status.SUCCESS;
|
||||
this.code = this.status.code();
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public T success(String message) {
|
||||
return this.success().message(message);
|
||||
}
|
||||
|
||||
public T success(Integer code, String message) {
|
||||
return (T) this.success(message).code(code);
|
||||
}
|
||||
|
||||
public T success(String message, String detail) {
|
||||
return this.success(message).detail(detail);
|
||||
}
|
||||
|
||||
public T success(Integer code, String message, String detail) {
|
||||
return this.success(message, detail).code(code);
|
||||
}
|
||||
|
||||
public T error() {
|
||||
this.status = Status.ERROR;
|
||||
this.code = this.status.code();
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public T error(String message) {
|
||||
return this.error().message(message);
|
||||
}
|
||||
|
||||
public T error(Integer code, String message) {
|
||||
return this.error(message).code(code);
|
||||
}
|
||||
|
||||
public T error(String message, String detail) {
|
||||
return this.error(message).detail(detail);
|
||||
}
|
||||
|
||||
public T error(Integer code, String message, String detail) {
|
||||
return this.error(message, detail).code(code);
|
||||
}
|
||||
|
||||
@ApiModelProperty(hidden = true)
|
||||
@JsonIgnore
|
||||
public Boolean isSuccess() {
|
||||
return this.status == Status.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 无返回数据时的返回结构
|
||||
*/
|
||||
@Getter
|
||||
@ToString(callSuper = true)
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ApiModel(value = "返回结果")
|
||||
public static class None extends Base<Serializable, None> {
|
||||
public static None init() {
|
||||
return new None();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 有单个类型返回数据时的返回结构,基于无返回数据时的结构,多一个data字段
|
||||
*/
|
||||
@Getter
|
||||
@ToString(callSuper = true)
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ApiModel(value = "返回结果", description = "接口单个数据")
|
||||
public static class Single<D> extends Base<D, Single<D>> {
|
||||
/**
|
||||
* 接口返回数据,默认为空对象
|
||||
*/
|
||||
@ApiModelProperty(value = "接口返回数据,没有数据则为空对象", allowEmptyValue = true)
|
||||
private D data;
|
||||
|
||||
public D data() {
|
||||
return this.data;
|
||||
}
|
||||
|
||||
public Single<D> data(D data) {
|
||||
this.data = data;
|
||||
return this;
|
||||
}
|
||||
|
||||
public static <D> Single<D> init() {
|
||||
return new Single<>();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 有多个同类型返回数据时的返回结构基类
|
||||
*
|
||||
* @param <D>
|
||||
* @param <T>
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Getter
|
||||
@ToString(callSuper = true)
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
private static class MultipleBase<D, T extends MultipleBase<D, T>> extends Base<D, T> {
|
||||
/**
|
||||
* 接口返回数据,默认为空列表
|
||||
*/
|
||||
@ApiModelProperty(value = "接口返回数据列表,没有数据则为空列表", allowEmptyValue = true)
|
||||
protected Collection<D> data;
|
||||
|
||||
public Collection<D> data() {
|
||||
return this.data;
|
||||
}
|
||||
|
||||
public T data(Collection<D> data) {
|
||||
this.data = data;
|
||||
return (T) this;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 有多个同类型返回数据时的返回结构,基于无返回数据时的结构,多一个data字段
|
||||
*/
|
||||
@Getter
|
||||
@ToString(callSuper = true)
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ApiModel(value = "返回结果", description = "接口返回列表数据")
|
||||
public static class Multiple<D> extends MultipleBase<D, Multiple<D>> {
|
||||
public static <D> Multiple<D> init() {
|
||||
return new Multiple<>();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义分页对象,继承于Multiple对象
|
||||
*/
|
||||
@Getter
|
||||
@ToString(callSuper = true)
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ApiModel(value = "返回结果", description = "接口返回分页列表数据")
|
||||
public static class Pagination<D> extends MultipleBase<D, Pagination<D>> {
|
||||
/**
|
||||
* 当前页数,仅用于分页
|
||||
*/
|
||||
@ApiModelProperty(value = "当前页数")
|
||||
private Long current = 1L;
|
||||
|
||||
/**
|
||||
* 每页记录数,仅用于分页
|
||||
*/
|
||||
@ApiModelProperty(value = "每页记录数")
|
||||
private Long size = 10L;
|
||||
|
||||
/**
|
||||
* 总记录数,仅用于分页
|
||||
*/
|
||||
@ApiModelProperty(value = "总记录数")
|
||||
private Long count = 0L;
|
||||
|
||||
public Long current() {
|
||||
return this.current;
|
||||
}
|
||||
|
||||
public Pagination<D> current(Long current) {
|
||||
this.current = current;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Pagination<D> current(Integer current) {
|
||||
this.current = current.longValue();
|
||||
return this;
|
||||
}
|
||||
|
||||
public Long size() {
|
||||
return this.size;
|
||||
}
|
||||
|
||||
public Pagination<D> size(Long size) {
|
||||
this.size = size;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Pagination<D> size(Integer size) {
|
||||
this.size = size.longValue();
|
||||
return this;
|
||||
}
|
||||
|
||||
public Long count() {
|
||||
return this.count;
|
||||
}
|
||||
|
||||
public Pagination<D> count(Long count) {
|
||||
this.count = count;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Pagination<D> count(Integer count) {
|
||||
this.count = count.longValue();
|
||||
return this;
|
||||
}
|
||||
|
||||
public static <D> Pagination<D> init() {
|
||||
return new Pagination<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据分页数据转换
|
||||
* @param page
|
||||
* @return
|
||||
*/
|
||||
public Pagination<D> ofPage(Page<D> page) {
|
||||
return this.data(page.getRecords())
|
||||
.count(page.getCount())
|
||||
.size(page.getSize())
|
||||
.current(page.getCurrent());
|
||||
}
|
||||
}
|
||||
}
|
||||
120
cemis/src/main/java/com/hncy/generator/zgf/base/bean/Page.java
Normal file
120
cemis/src/main/java/com/hncy/generator/zgf/base/bean/Page.java
Normal file
@@ -0,0 +1,120 @@
|
||||
package com.hncy.generator.zgf.base.bean;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.core.metadata.OrderItem;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import com.hncy.generator.zgf.base.entity.BaseEntity;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 自定义的基于MybatisPlus的分页组件的类,用于增加一些字段
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: yanghuanglin
|
||||
* Date: 2021/4/30
|
||||
*/
|
||||
public class Page<T> extends com.baomidou.mybatisplus.extension.plugins.pagination.Page<T> {
|
||||
private static final long serialVersionUID = 526167319704940805L;
|
||||
|
||||
/**
|
||||
* 是否自动拼接分页参数、排序参数
|
||||
*/
|
||||
private boolean autoConcat = true;
|
||||
|
||||
public Page() {
|
||||
super();
|
||||
}
|
||||
|
||||
public Page(long current, long size) {
|
||||
super(current, size);
|
||||
}
|
||||
|
||||
public Page(long current, long size, long total) {
|
||||
super(current, size, total);
|
||||
}
|
||||
|
||||
public Page(long current, long size, boolean isSearchCount) {
|
||||
super(current, size, isSearchCount);
|
||||
}
|
||||
|
||||
public Page(long current, long size, long total, boolean isSearchCount) {
|
||||
super(current, size, total, isSearchCount);
|
||||
}
|
||||
|
||||
public boolean getAutoConcat() {
|
||||
return autoConcat;
|
||||
}
|
||||
|
||||
public void setAutoConcat(boolean autoConcat) {
|
||||
this.autoConcat = autoConcat;
|
||||
}
|
||||
|
||||
public long getCount() {
|
||||
return this.total;
|
||||
}
|
||||
|
||||
public Page<T> setCount(long count) {
|
||||
this.total = count;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取到BaseEntity为止的所有基类列表
|
||||
*
|
||||
* @param clazz 需要获取基类列表的类
|
||||
* @param list 基类列表
|
||||
*/
|
||||
private static List<Class<?>> getSupers(Class<?> clazz, List<Class<?>> list) {
|
||||
Class<?> superClass = clazz.getSuperclass();
|
||||
if (superClass.isAssignableFrom(BaseEntity.class))
|
||||
list.add(superClass);
|
||||
if (superClass.equals(BaseEntity.class)) {
|
||||
return list;
|
||||
}
|
||||
return getSupers(superClass, list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从所有基类列表中查找某个名称的字段
|
||||
*
|
||||
* @param list 基类列表
|
||||
* @param name 需要查找的字段名
|
||||
* @return 查找到的字段,未找到则为null
|
||||
*/
|
||||
private static Field getField(List<Class<?>> list, String name) {
|
||||
Field field = null;
|
||||
for (Class<?> supperClass : list) {
|
||||
try {
|
||||
field = supperClass.getDeclaredField(name);
|
||||
break;
|
||||
} catch (NoSuchFieldException ignored) {
|
||||
}
|
||||
}
|
||||
return field;
|
||||
}
|
||||
|
||||
/**
|
||||
* 排序字段名称转换,将驼峰命名转为下划线形式:如果实体中字段没有@TableField注解,则userId转为user_id,否则转为该注解中的数据库字段名。主要用于搜索时转换参数名
|
||||
*
|
||||
* @param entityClass 字段所在实体的类
|
||||
*/
|
||||
public void transferOrderField(Class<T> entityClass) {
|
||||
List<Class<?>> classList = getSupers(entityClass, new ArrayList<>());
|
||||
//将本身放入
|
||||
classList.add(entityClass);
|
||||
List<OrderItem> orderItems = orders();
|
||||
for (OrderItem orderItem : orderItems) {
|
||||
String fieldName = orderItem.getColumn();
|
||||
Field declaredField = getField(classList, fieldName);
|
||||
if (declaredField != null) {
|
||||
TableField annotation = declaredField.getAnnotation(TableField.class);
|
||||
if (annotation != null)
|
||||
orderItem.setColumn(annotation.value());
|
||||
else
|
||||
orderItem.setColumn(StringUtils.camelToUnderline(fieldName));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.hncy.generator.zgf.base.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.extension.activerecord.Model;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 仅仅是一个基类,各个项目中可能不同,此项目中,只是用于避免因类不存在而报错
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Accessors(chain = true)
|
||||
@Data
|
||||
public class BaseEntity<T> extends Model<BaseEntity<T>> {
|
||||
|
||||
@TableId("id")
|
||||
private Serializable id;
|
||||
|
||||
@Override
|
||||
public Serializable pkVal() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
55
cemis/src/test/java/GeberatorUIServer.java
Normal file
55
cemis/src/test/java/GeberatorUIServer.java
Normal file
@@ -0,0 +1,55 @@
|
||||
import com.baomidou.mybatisplus.generator.config.rules.DateType;
|
||||
import com.github.davidfantasy.mybatisplus.generatorui.GeneratorConfig;
|
||||
import com.github.davidfantasy.mybatisplus.generatorui.MybatisPlusToolsApplication;
|
||||
import com.github.davidfantasy.mybatisplus.generatorui.mbp.NameConverter;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class GeberatorUIServer {
|
||||
/**
|
||||
* 数据库相关配置
|
||||
*/
|
||||
private static final String dbName = "cemis-qujing";
|
||||
private static final String url = "jdbc:mysql://localhost:3306/" + dbName + "?useUnicode=true&useSSL=false&characterEncoding=utf8";
|
||||
private static final String username = "root";
|
||||
private static final String password = "root";
|
||||
private static final String driverClassName = "com.mysql.cj.jdbc.Driver";
|
||||
|
||||
//项目父包名,service、controller等包会建在这个包下
|
||||
private static final String parent = "com.optima.cemis.free";
|
||||
//表名前缀,生成表时会删除
|
||||
private static final String tablePrefix = "sys_";
|
||||
|
||||
public static void main(String[] args) {
|
||||
GeneratorConfig config = GeneratorConfig.builder()
|
||||
.jdbcUrl(url)
|
||||
.userName(username)
|
||||
.password(password)
|
||||
.driverClassName(driverClassName)
|
||||
.dateType(DateType.TIME_PACK)
|
||||
//数据库schema,MSSQL,PGSQL,ORACLE,DB2类型的数据库需要指定
|
||||
//.schemaName("myBusiness")
|
||||
//数据库表前缀,生成entity名称时会去掉(v2.0.3新增)
|
||||
.tablePrefix(tablePrefix)
|
||||
.nameConverter(new NameConverter() {
|
||||
/**
|
||||
* 自定义Service类文件的名称规则
|
||||
*/
|
||||
@Override
|
||||
public String serviceNameConvert(String entityName) {
|
||||
return entityName + "Service";
|
||||
}
|
||||
})
|
||||
.templateVaribleInjecter(tableInfo -> {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("mapperAnnotationClass", org.apache.ibatis.annotations.Mapper.class);
|
||||
return map;
|
||||
})
|
||||
//所有生成的java文件的父包名,后续也可单独在界面上设置
|
||||
.basePackage(parent)
|
||||
.port(8068)
|
||||
.build();
|
||||
MybatisPlusToolsApplication.run(config);
|
||||
}
|
||||
}
|
||||
3
cemis/src/test/resources/application.yml
Normal file
3
cemis/src/test/resources/application.yml
Normal file
@@ -0,0 +1,3 @@
|
||||
spring:
|
||||
mvc:
|
||||
static-path-pattern: /**
|
||||
112
cemis/src/test/resources/codetpls/controller.java.btl
Normal file
112
cemis/src/test/resources/codetpls/controller.java.btl
Normal file
@@ -0,0 +1,112 @@
|
||||
<% var entityInstanceName = @cn.hutool.core.util.StrUtil.lowerFirst(table.entityName); %>
|
||||
<% var serviceInstanceName = @cn.hutool.core.util.StrUtil.lowerFirst(table.serviceName); %>
|
||||
package ${package.Controller};
|
||||
|
||||
import bean.com.hncy.generator.zgf.base.CommonResult;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
<% if(!restControllerStyle){ %>
|
||||
import org.springframework.stereotype.Controller;
|
||||
<% } %>
|
||||
<% if(isNotEmpty(superControllerClassPackage)){ %>
|
||||
import ${superControllerClassPackage};
|
||||
<% } %>
|
||||
<% if(isNotEmpty(controllerMethods.list)){ %>
|
||||
import bean.com.hncy.generator.zgf.base.Page;
|
||||
<% } %>
|
||||
<% if(isNotEmpty(controllerMethods.hasMethod)){ %>
|
||||
import ${package.Service}.${table.serviceName};
|
||||
import ${package.Entity}.${table.entityName};
|
||||
|
||||
import javax.annotation.Resource;
|
||||
<% } %>
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* ${table.comment!} 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
<% if(restControllerStyle){ %>
|
||||
@RestController
|
||||
<% }else{ %>
|
||||
@Controller
|
||||
<% } %>
|
||||
@RequestMapping("<% if(isNotEmpty(package.ModuleName)){ %>/${package.ModuleName}<% } %>/<% if(isNotEmpty(controllerMappingHyphenStyle)){ %>${controllerMappingHyphen}<% }else{ %>${table.entityPath}<% } %>")
|
||||
<% if(kotlin){ %>
|
||||
class ${table.controllerName}<% if(isNotEmpty(superControllerClass)){ %> : ${superControllerClass}()<% } %>
|
||||
<% }else{ %>
|
||||
<% if(isNotEmpty(superControllerClass)){ %>
|
||||
public class ${table.controllerName} extends ${superControllerClass} {
|
||||
<% }else{ %>
|
||||
public class ${table.controllerName} {
|
||||
<% } %>
|
||||
|
||||
<% if(isNotEmpty(controllerMethods.hasMethod)){ %>
|
||||
@Resource
|
||||
private ${table.serviceName} ${serviceInstanceName};
|
||||
<% } %>
|
||||
|
||||
<% if(isNotEmpty(controllerMethods.list)){ %>
|
||||
@GetMapping(value = "/list")
|
||||
<% if(!restControllerStyle){ %>
|
||||
@ResponseBody
|
||||
<% } %>
|
||||
public CommonResult.Pagination<${table.entityName}> list(Page<${table.entityName}> page) {
|
||||
CommonResult.Pagination<${table.entityName}> pagination = CommonResult.Pagination.init();
|
||||
page.transferOrderField(${table.entityName}.class);
|
||||
${serviceInstanceName}.page(page);
|
||||
return pagination.ofPage(page).message("查询成功");
|
||||
}
|
||||
<% } %>
|
||||
|
||||
<% if(isNotEmpty(controllerMethods.getById)){ %>
|
||||
@GetMapping(value = "/{id}")
|
||||
<% if(!restControllerStyle){ %>
|
||||
@ResponseBody
|
||||
<% } %>
|
||||
public CommonResult.Single<${table.entityName}> detail(@PathVariable("id") Serializable id) {
|
||||
CommonResult.Single<${table.entityName}> single = CommonResult.Single.init();
|
||||
return single.data(${serviceInstanceName}.getById(id)).message("查询成功");
|
||||
}
|
||||
<% } %>
|
||||
|
||||
<% if(isNotEmpty(controllerMethods.create)){ %>
|
||||
<% if(!restControllerStyle){ %>
|
||||
@ResponseBody
|
||||
<% } %>
|
||||
@PostMapping(value = "/insert")
|
||||
public CommonResult.Single<${table.entityName}> insert(${table.entityName} ${entityInstanceName}) {
|
||||
CommonResult.Single<${table.entityName}> single = CommonResult.Single.init();
|
||||
${serviceInstanceName}.save(${entityInstanceName});
|
||||
return single.data(${entityInstanceName}).message("保存成功");
|
||||
}
|
||||
<% } %>
|
||||
|
||||
<% if(isNotEmpty(controllerMethods.delete)){ %>
|
||||
@GetMapping(value = "/delete/{id}")
|
||||
<% if(!restControllerStyle){ %>
|
||||
@ResponseBody
|
||||
<% } %>
|
||||
public CommonResult.Single<Serializable> delete(@PathVariable("id") Serializable id) {
|
||||
CommonResult.Single<Serializable> single = CommonResult.Single.init();
|
||||
${serviceInstanceName}.removeById(id);
|
||||
return single.data(id).message("删除成功");
|
||||
}
|
||||
<% } %>
|
||||
|
||||
<% if(isNotEmpty(controllerMethods.update)){ %>
|
||||
@PostMapping(value = "/update")
|
||||
<% if(!restControllerStyle){ %>
|
||||
@ResponseBody
|
||||
<% } %>
|
||||
public CommonResult.Single<${table.entityName}> update(${table.entityName} ${entityInstanceName}) {
|
||||
CommonResult.Single<${table.entityName}> single = CommonResult.Single.init();
|
||||
${serviceInstanceName}.updateById(${entityInstanceName});
|
||||
return single.data(${serviceInstanceName}.getById(${entityInstanceName}.getId())).message("更新成功");
|
||||
}
|
||||
<% } %>
|
||||
}
|
||||
<% } %>
|
||||
53
cemis/src/test/resources/codetpls/dto.btl
Normal file
53
cemis/src/test/resources/codetpls/dto.btl
Normal file
@@ -0,0 +1,53 @@
|
||||
package ${config.pkg};
|
||||
<% for(pkg in config.importPackages){ %>
|
||||
import ${pkg};
|
||||
<% } %>
|
||||
<% if(config.enableLombok){ %>
|
||||
import lombok.Data;
|
||||
<% } %>
|
||||
/**
|
||||
* ${config.comment!}
|
||||
*
|
||||
* @author ${config.author}
|
||||
* @since ${config.createDate}
|
||||
*/
|
||||
<% if(config.enableLombok){ %>
|
||||
@Data
|
||||
<% } %>
|
||||
public class ${config.dtoName} {
|
||||
|
||||
<% /** -----------BEGIN 字段循环遍历----------- **/ %>
|
||||
<% for(field in config.fields){ %>
|
||||
<%/*字段定义*/%>
|
||||
private ${field.shortJavaType} ${field.propertyName};
|
||||
|
||||
<% } %>
|
||||
<% /** -----------END 字段循环遍历----------- **/ %>
|
||||
<% if(!config.enableLombok){ %>
|
||||
<% for(field in config.fields){ %>
|
||||
public ${field.shortJavaType} ${field.getMethodName}() {
|
||||
return ${field.propertyName};
|
||||
}
|
||||
|
||||
public void ${field.setMethodName}(${field.shortJavaType} ${field.propertyName}) {
|
||||
this.${field.propertyName} = ${field.propertyName};
|
||||
}
|
||||
|
||||
<% } %>
|
||||
<% } %>
|
||||
<% if(!config.enableLombok){ %>
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "${config.dtoName}{" +
|
||||
<% for(field in config.fields){ %>
|
||||
<% if(fieldLP.index==0){ %>
|
||||
"${field.propertyName}=" + ${field.propertyName} +
|
||||
<% }else{ %>
|
||||
", ${field.propertyName}=" + ${field.propertyName} +
|
||||
<% } %>
|
||||
<% } %>
|
||||
"}";
|
||||
}
|
||||
<% } %>
|
||||
}
|
||||
173
cemis/src/test/resources/codetpls/entity.java.btl
Normal file
173
cemis/src/test/resources/codetpls/entity.java.btl
Normal file
@@ -0,0 +1,173 @@
|
||||
package ${package.Entity};
|
||||
|
||||
<% for(pkg in table.importPackages){ %>
|
||||
import ${pkg};
|
||||
<% } %>
|
||||
<% if(springdoc){ %>
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
<% }else if(swagger){ %>
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
<% } %>
|
||||
<% if(entityLombokModel){ %>
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
<% if(chainModel){ %>
|
||||
import lombok.experimental.Accessors;
|
||||
<% } %>
|
||||
<% } %>
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* ${table.comment!}
|
||||
* </p>
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
<% if(entityLombokModel){ %>
|
||||
@Getter
|
||||
@Setter
|
||||
<% if(chainModel){ %>
|
||||
@Accessors(chain = true)
|
||||
<% } %>
|
||||
<% } %>
|
||||
<% if(table.convert){ %>
|
||||
@TableName("${schemaName}${table.name}")
|
||||
<% } %>
|
||||
<% if(springdoc){ %>
|
||||
@Schema(name = "${entity}", description = "$!{table.comment}")
|
||||
<% }else if(swagger){ %>
|
||||
@ApiModel(value = "${entity}对象", description = "${table.comment!''}")
|
||||
<% } %>
|
||||
<% if(isNotEmpty(superEntityClass)){ %>
|
||||
public class ${entity} extends ${superEntityClass}<% if(activeRecord){ %><${entity}><%}%> {
|
||||
<% }else if(activeRecord){ %>
|
||||
public class ${entity} extends Model<${entity}> {
|
||||
<% }else if(entitySerialVersionUID){ %>
|
||||
public class ${entity} implements Serializable {
|
||||
<% }else{ %>
|
||||
public class ${entity} {
|
||||
<% } %>
|
||||
<% if(entitySerialVersionUID){ %>
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
<% } %>
|
||||
<% var keyPropertyName; %>
|
||||
<% /** -----------BEGIN 字段循环遍历----------- **/ %>
|
||||
<% for(field in table.fields){ %>
|
||||
<%
|
||||
if(field.keyFlag){
|
||||
keyPropertyName = field.propertyName;
|
||||
}
|
||||
%>
|
||||
<% if(isNotEmpty(field.comment)){ %>
|
||||
|
||||
<% if(springdoc){ %>
|
||||
@Schema(description = "${field.comment}")
|
||||
<% }else if(swagger){ %>
|
||||
@ApiModelProperty(value = "${field.comment}")
|
||||
<% }else{ %>
|
||||
/**
|
||||
* ${field.comment}
|
||||
*/
|
||||
<% } %>
|
||||
<% } %>
|
||||
<% if(field.keyFlag){ %>
|
||||
<%
|
||||
/*主键*/
|
||||
%>
|
||||
<% if(field.keyIdentityFlag){ %>
|
||||
@TableId(value = "${field.annotationColumnName}", type = IdType.AUTO)
|
||||
<% }else if(isNotEmpty(idType)){ %>
|
||||
@TableId(value = "${field.annotationColumnName}", type = IdType.${idType})
|
||||
<% }else if(field.convert){ %>
|
||||
@TableId("${field.annotationColumnName}")
|
||||
<% } %>
|
||||
<%
|
||||
/*普通字段*/
|
||||
%>
|
||||
<% }else if(isNotEmpty(field.fill)){ %>
|
||||
<% if(field.convert){ %>
|
||||
@TableField(value = "${field.annotationColumnName}", fill = FieldFill.${field.fill})
|
||||
<% }else{ %>
|
||||
@TableField(fill = FieldFill.${field.fill})
|
||||
<% } %>
|
||||
<% }else if(field.convert){ %>
|
||||
@TableField("${field.annotationColumnName}")
|
||||
<% } %>
|
||||
<%
|
||||
/*乐观锁注解*/
|
||||
%>
|
||||
<% if(field.versionField){ %>
|
||||
@Version
|
||||
<% } %>
|
||||
<%
|
||||
/*逻辑删除注解*/
|
||||
%>
|
||||
<% if(field.logicDeleteField){ %>
|
||||
@TableLogic
|
||||
<% } %>
|
||||
private ${field.propertyType} ${field.propertyName};
|
||||
<% } %>
|
||||
<% /** -----------END 字段循环遍历----------- **/ %>
|
||||
<% if(!entityLombokModel){ %>
|
||||
<% for(field in table.fields){ %>
|
||||
<%
|
||||
var getprefix ='';
|
||||
if(field.propertyType=='boolean'){
|
||||
getprefix='is';
|
||||
}else{
|
||||
getprefix='get';
|
||||
}
|
||||
%>
|
||||
|
||||
public ${field.propertyType} ${getprefix}${field.capitalName}() {
|
||||
return ${field.propertyName};
|
||||
}
|
||||
|
||||
<% if(chainModel){ %>
|
||||
public ${entity} set${field.capitalName}(${field.propertyType} ${field.propertyName}) {
|
||||
<% }else{ %>
|
||||
public void set${field.capitalName}(${field.propertyType} ${field.propertyName}) {
|
||||
<% } %>
|
||||
this.${field.propertyName} = ${field.propertyName};
|
||||
<% if(chainModel){ %>
|
||||
return this;
|
||||
<% } %>
|
||||
}
|
||||
<% } %>
|
||||
<% } %>
|
||||
<% if(entityColumnConstant){ %>
|
||||
<% for(field in table.fields){ %>
|
||||
|
||||
public static final String ${strutil.toUpperCase(field.name)} = "${field.name}";
|
||||
<% } %>
|
||||
<% } %>
|
||||
<% if(activeRecord){ %>
|
||||
|
||||
@Override
|
||||
public Serializable pkVal() {
|
||||
<% if(isNotEmpty(keyPropertyName)){ %>
|
||||
return this.${keyPropertyName};
|
||||
<% }else{ %>
|
||||
return super.pkVal();
|
||||
<% } %>
|
||||
}
|
||||
<% } %>
|
||||
<% if(!entityLombokModel){ %>
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "${entity}{" +
|
||||
<% for(field in table.fields){ %>
|
||||
<% if(fieldLP.index==0){ %>
|
||||
"${field.propertyName} = " + ${field.propertyName} +
|
||||
<% }else{ %>
|
||||
", ${field.propertyName} = " + ${field.propertyName} +
|
||||
<% } %>
|
||||
<% } %>
|
||||
"}";
|
||||
}
|
||||
<% } %>
|
||||
}
|
||||
26
cemis/src/test/resources/codetpls/mapper.java.btl
Normal file
26
cemis/src/test/resources/codetpls/mapper.java.btl
Normal file
@@ -0,0 +1,26 @@
|
||||
package ${package.Mapper};
|
||||
|
||||
import ${package.Entity}.${entity};
|
||||
import ${superMapperClassPackage};
|
||||
<% if(mapperAnnotationClass!=null){ %>
|
||||
import ${mapperAnnotationClass.name};
|
||||
<% } %>
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* ${table.comment!} Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
<% if(mapperAnnotationClass!=null){ %>
|
||||
@${mapperAnnotationClass.simpleName}
|
||||
<% } %>
|
||||
<% if(kotlin){ %>
|
||||
interface ${table.mapperName} : ${superMapperClass}<${entity}>
|
||||
<% }else{ %>
|
||||
public interface ${table.mapperName} extends ${superMapperClass}<${entity}> {
|
||||
|
||||
}
|
||||
<% } %>
|
||||
41
cemis/src/test/resources/codetpls/mapper.xml.btl
Normal file
41
cemis/src/test/resources/codetpls/mapper.xml.btl
Normal file
@@ -0,0 +1,41 @@
|
||||
<?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="${cacheClassName}"/>
|
||||
|
||||
<% } %>
|
||||
<% if(baseResultMap){ %>
|
||||
<!-- 通用查询映射结果 -->
|
||||
<resultMap id="BaseResultMap" type="${package.Entity}.${entity}">
|
||||
<% for(field in table.fields){ %>
|
||||
<% /** 生成主键排在第一位 **/ %>
|
||||
<% if(field.keyFlag){ %>
|
||||
<id column="${field.name}" property="${field.propertyName}" />
|
||||
<% } %>
|
||||
<% } %>
|
||||
<% for(field in table.commonFields){ %>
|
||||
<% /** 生成公共字段 **/ %>
|
||||
<result column="${field.name}" property="${field.propertyName}" />
|
||||
<% } %>
|
||||
<% for(field in table.fields){ %>
|
||||
<% /** 生成普通字段 **/ %>
|
||||
<% if(!field.keyFlag){ %>
|
||||
<result column="${field.name}" property="${field.propertyName}" />
|
||||
<% } %>
|
||||
<% } %>
|
||||
</resultMap>
|
||||
<% } %>
|
||||
<% if(baseColumnList){ %>
|
||||
<!-- 通用查询结果列 -->
|
||||
<sql id="Base_Column_List">
|
||||
<% for(field in table.commonFields){ %>
|
||||
${field.columnName},
|
||||
<% } %>
|
||||
${table.fieldNames}
|
||||
</sql>
|
||||
|
||||
<% } %>
|
||||
</mapper>
|
||||
10
cemis/src/test/resources/codetpls/mapperMethods.btl
Normal file
10
cemis/src/test/resources/codetpls/mapperMethods.btl
Normal file
@@ -0,0 +1,10 @@
|
||||
<% if(elementType == 'select'){ %>
|
||||
<% if(config.resultMap != null){ %>
|
||||
<select id="${config.mapperElementId}" resultMap="${config.resultMap}">
|
||||
<% }%>
|
||||
<% if(config.resultMap == null){ %>
|
||||
<select id="${config.mapperElementId}" resultType="${config.resultType}">
|
||||
<% }%>
|
||||
${sql}
|
||||
</select>
|
||||
<% } %>
|
||||
3
cemis/src/test/resources/codetpls/resultMap.btl
Normal file
3
cemis/src/test/resources/codetpls/resultMap.btl
Normal file
@@ -0,0 +1,3 @@
|
||||
<resultMap id="${config.dtoName}Map" type="${config.fullPackage}">
|
||||
<% for(field in config.fields){ %><result column="${field.columnName}" property="${field.propertyName}" /><% } %>
|
||||
</resultMap>
|
||||
20
cemis/src/test/resources/codetpls/service.java.btl
Normal file
20
cemis/src/test/resources/codetpls/service.java.btl
Normal file
@@ -0,0 +1,20 @@
|
||||
package ${package.Service};
|
||||
|
||||
import ${package.Entity}.${entity};
|
||||
import ${superServiceClassPackage};
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* ${table.comment!} 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
<% if(kotlin){ %>
|
||||
interface ${table.serviceName} : ${superServiceClass}<${entity}>
|
||||
<% }else{ %>
|
||||
public interface ${table.serviceName} extends ${superServiceClass}<${entity}> {
|
||||
|
||||
}
|
||||
<% } %>
|
||||
28
cemis/src/test/resources/codetpls/serviceImpl.java.btl
Normal file
28
cemis/src/test/resources/codetpls/serviceImpl.java.btl
Normal file
@@ -0,0 +1,28 @@
|
||||
package ${package.ServiceImpl};
|
||||
|
||||
import ${package.Entity}.${entity};
|
||||
import ${package.Mapper}.${table.mapperName};
|
||||
<% if(table.serviceInterface){ %>
|
||||
import ${package.Service}.${table.serviceName};
|
||||
<% } %>
|
||||
import ${superServiceImplClassPackage};
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* ${table.comment!} 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Service
|
||||
<% if(kotlin){ %>
|
||||
open class ${table.serviceImplName} : ${superServiceImplClass}<${table.mapperName}, ${entity}>()<% if(table.serviceInterface){ %>, ${table.serviceName}<% } %> {
|
||||
|
||||
}
|
||||
<% }else{ %>
|
||||
public class ${table.serviceImplName} extends ${superServiceImplClass}<${table.mapperName}, ${entity}><% if(table.serviceInterface){ %> implements ${table.serviceName}<% } %> {
|
||||
|
||||
}
|
||||
<% } %>
|
||||
Reference in New Issue
Block a user