Skip to content

Commit

Permalink
🐛 template文件添加
Browse files Browse the repository at this point in the history
  • Loading branch information
daiyi committed Jun 20, 2022
1 parent 4058599 commit f778c98
Show file tree
Hide file tree
Showing 13 changed files with 831 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ apply plugin: 'java'


group 'com.mininglamp.km.nebula.generator'
version '1.0.4'
version '1.0.5'

repositories {
mavenCentral()
Expand Down
39 changes: 39 additions & 0 deletions src/main/resources/template/controller.java.btl
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package ${package.Controller};


import org.springframework.web.bind.annotation.RequestMapping;

<% if(restControllerStyle){ %>
import org.springframework.web.bind.annotation.RestController;
<% }else{ %>
import org.springframework.stereotype.Controller;
<% } %>
<% if(isNotEmpty(superControllerClassPackage)){ %>
import ${superControllerClassPackage};
<% } %>

/**
* <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} {
<% } %>

}
<% } %>
58 changes: 58 additions & 0 deletions src/main/resources/template/entity.java.btl
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package ${package.Entity};
<% for(pkg in table.importPackages){ %>
import ${pkg};
<% } %>

<% if(entityLombokModel){ %>
import lombok.Data;
import lombok.EqualsAndHashCode;
<% if(chainModel){ %>
import lombok.experimental.Accessors;
<% } %>
<% } %>

/**
* <p>
* ${table.comment!}
* </p>
*
* @author ${author}
* @since ${date}
*/

@Data
@Accessors(chain = true)
public class ${entity} implements Serializable {

<% if(entitySerialVersionUID){ %>
private static final long serialVersionUID = 1L;
<% } %>

<% /** ----------点id---------- **/ %>
<% if(table.isTag){ %>
/**
* vid
*/
private ${table.idType} id;
<% } %>

<% /** ----------边id---------- **/ %>
<% if(table.isEdge){ %>
/**
* 起始点
*/
private ${table.idType} src;

/**
* 终止点
*/
private ${table.idType} dst;
<% } %>

<% /** -----------BEGIN 字段循环遍历----------- **/ %>
<% for(field in table.fields){ %>
private ${field.propertyType} ${field.propertyName};

<% } %>
<% /** -----------END 字段循环遍历----------- **/ %>
}
124 changes: 124 additions & 0 deletions src/main/resources/template/entity.kt.btl
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
package ${package.Entity}
<% for(pkg in table.importPackages){ %>
import ${pkg}
<% } %>
<% if(swagger2){ %>
import io.swagger.annotations.ApiModel
import io.swagger.annotations.ApiModelProperty
<% } %>
/**
* <p>
* ${table.comment!}
* </p>
*
* @author ${author}
* @since ${date}
*/
<% if(table.convert){ %>
@TableName("${table.name}")
<% } %>
<% if(swagger2){ %>
@ApiModel(value="${entity}对象", description="${table.comment!''}")
<% } %>
<% if(isNotEmpty(superEntityClass)){ %>
class ${entity} : ${superEntityClass}<% if(activeRecord){ %><${entity}><%}%>{
<% }else if(activeRecord){ %>
class ${entity} : Model<${entity}> {
<% }else{ %>
class ${entity} : Serializable {
<% } %>

<% /** -----------BEGIN 字段循环遍历----------- **/ %>
<% for(field in table.fields){ %>
<%
if(field.keyFlag){
var keyPropertyName = field.propertyName;
}
%>

<% if(isNotEmpty(field.comment)){ %>
<% if(swagger2){ %>
@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.columnName}")
<% } %>
<%
/*普通字段*/
%>
<% }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(versionFieldName!'' == field.name){ %>
@Version
<% } %>
<%
/*逻辑删除注解*/
%>
<% if(logicDeleteFieldName!'' == field.name){ %>
@TableLogic
<% } %>
<% if(field.propertyType == 'Integer'){ %>
var ${field.propertyName}: Int ? = null
<% }else{ %>
var ${field.propertyName}: ${field.propertyType} ? = null
<% } %>
<% } %>
<% /** -----------END 字段循环遍历----------- **/ %>

<% if(entityColumnConstant){ %>
companion object {
<% for(field in table.fields){ %>
const val ${strutil.toUpperCase(field.name)} : String = "${field.name}"
<% } %>
}
<% } %>
<% if(activeRecord){ %>
@Override
override fun pkVal(): Serializable? {
<% if(isNotEmpty(keyPropertyName)){ %>
return this.${keyPropertyName}
<% }else{ %>
return null;
<% } %>
}

<% } %>

<% if(!entityLombokModel){ %>
@Override
override fun toString(): String {
return "${entity}{" +
<% for(field in table.fields){ %>
<% if(fieldLP.index==0){ %>
"${field.propertyName}=" + ${field.propertyName} +
<% }else{ %>
", ${field.propertyName}=" + ${field.propertyName} +
<% } %>
<% } %>
"}"
}
<% } %>
}
105 changes: 105 additions & 0 deletions src/main/resources/template/mapper.java.btl
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package ${package.Mapper};

import ${package.Entity}.${entity};
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
* <p>
* ${table.comment!} Mapper 接口
* </p>
*
* @author ${author}
* @since ${date}
*/
@Repository
public interface ${table.mapperName} {

/**
* mapper 插入操作
* @param entity 插入实体
* @return 是否成功
*/
int insert(${entity} entity);

/**
* mapper 更新操作
* @param entity 更新实体
* @return 是否成功
*/
int update(${entity} entity);

/**
* 批量插入
* @param batch 实体列表
* @return i
*/
int insertBatch(List<${entity}> batch);

<% if(table.isTag) { %>
/**
* 根据id查询实体
* @param id 实体id
* @return entity
*/
${entity} select(${table.idType} id);

/**
* 根据id查询实体
* @param batch 实体id列表
* @return entity list
*/
List<${entity}> selectBatch(List<${table.idType}> batch);

/**
* 删除
* @param id 实体列表id
* @return i
*/
int delete(${table.idType} id);

/**
* 批量删除
* @param batch 实体列表id
* @return i
*/
int deleteBatch(List<${table.idType}> batch);

<% } %>

<% if(table.isEdge) { %>
/**
* 根据起始点查询边属性
* @param src 起始点id
* @param dst 终止点id
* @return entity
*/
${entity} select(${table.idType} src, ${table.idType} dst);

/**
* 根据起始点列表查询边属性
* @param batch 实体id列表
* @return entity list
*/
List<${entity}> selectBatch(List<${entity}> batch);

/**
* 批量删除
* @param src 边起点
* @param dst 边终点
* @return i
*/
int delete(${table.idType} src, ${table.idType} dst);

/**
* 批量删除
* @param batch 边列表
* @return i
*/
int deleteBatch(List<${entity}> batch);
<% } %>


}
Loading

0 comments on commit f778c98

Please sign in to comment.