- * ${entityName} Controller + * ${table.comment!} 前端控制器 *
* * @author ${author} - * @date ${date} + * @since ${date} */ -@Slf4j -@Validated +<% if(restControllerStyle){ %> @RestController -@RequestMapping("<% if(isNotEmpty(moduleName)){ %>/${moduleName}<% } %>/${entityVariableName}") -public class ${entityName}Controller <% if(isNotEmpty(superControllerName)){ %>extends ${superControllerName}<% } %> { - - /** - *- * ${entityName}Service - *
- */ - @Autowired - private ${entityName}Service ${entityVariableName}Service; - - /** - *- * Get ${entityName} by id - *
- * @param id id - * @return ${entityName} - */ - @GetMapping("/{id}") - public ${entityName} getById(@Valid @Range @PathVariable("id") Long id) { - return ${entityVariableName}Service.getById(id); - } - - /** - *- * Get ${entityName} page list by ${entityName} - *
- * @param page page - * @param ${entityVariableName} ${entityVariableName} - * @return IPage<${entityName}> - */ - @GetMapping - public IPage<${entityName}> getPage(IPage<${entityName}> page, @Valid ${entityName} ${entityVariableName}) { - return ${entityVariableName}Service.page(page, new QueryWrapper<>(${entityVariableName})); - } - - /** - *- * Add ${entityName} - *
- * @param ${entityVariableName} ${entityVariableName} - */ - @PostMapping - public void add(@Valid @RequestBody ${entityName} ${entityVariableName}) { - ${entityVariableName}Service.save(${entityVariableName}); - } - - /** - *- * Update ${entityName} - *
- * @param ${entityVariableName} ${entityVariableName} - */ - @PutMapping - public void update(@Valid @RequestBody ${entityName} ${entityVariableName}) { - ${entityVariableName}Service.updateById(${entityVariableName}); - } - - /** - *- * Delete ${entityName} by id - *
- * @param id id - */ - @DeleteMapping("/{id}") - public void delete(@Valid @Range @PathVariable("id") Long id) { - ${entityVariableName}Service.removeById(id); - } +<% }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} { + <% } %> } +<% } %> diff --git a/src/main/resources/templates/mybatis-plus/entity.java.btl b/src/main/resources/templates/mybatis-plus/entity.java.btl index 8bedf1af0030ff8ed6b92212182e9fac9a442608..a9616c4bc0ebd94d344ccd62f71f4b39fcd9facf 100644 --- a/src/main/resources/templates/mybatis-plus/entity.java.btl +++ b/src/main/resources/templates/mybatis-plus/entity.java.btl @@ -1,67 +1,162 @@ -package ${basePackage}.entity; - -import com.baomidou.mybatisplus.annotation.TableField; -<% if(isNotEmpty(superEntityClassPackage)){ %> -import ${superEntityClassPackage}; -<% }else{ %> -import java.io.Serializable; +package ${package.Entity}; +<% for(pkg in table.importPackages){ %> +import ${pkg}; <% } %> +<% if(swagger2){ %> +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +<% } %> +<% if(entityLombokModel){ %> import lombok.Data; import lombok.EqualsAndHashCode; import lombok.experimental.Accessors; -<% for(pkg in fieldImportPackages){ %> -import ${pkg}; <% } %> - /** ** ${table.comment!} *
* * @author ${author} - * @date ${date} + * @since ${date} */ +<% if(entityLombokModel){ %> @Data -@Accessors(chain = true) -<% if(isNotEmpty(superEntityName)){ %> + <% if(isNotEmpty(superEntityClass)){ %> @EqualsAndHashCode(callSuper = true) -<% }else{ %> + <% }else{ %> @EqualsAndHashCode(callSuper = false) + <% } %> +@Accessors(chain = true) +<% } %> +<% if(table.convert){ %> +@TableName("${table.name}") <% } %> -<% if(isNotEmpty(superEntityName)){ %> -public class ${entityName} extends ${superEntityName} { +<% if(swagger2){ %> +@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{ %> -public class ${entityName} implements Serializable { +public class ${entity} implements Serializable { <% } %> +<% if(entitySerialVersionUID){ %> private static final long serialVersionUID = 1L; +<% } %> <% /** -----------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!} + * ${field.comment} */ + <% } %> <% } %> <% if(field.keyFlag){ %> + <% + /*主键*/ + %> <% if(field.keyIdentityFlag){ %> @TableId(value = "${field.name}", type = IdType.AUTO) <% }else if(isNotEmpty(idType)){ %> @TableId(value = "${field.name}", type = IdType.${idType}) <% }else if(field.convert){ %> @TableId("${field.name}") - <% } %> + <% } %> + <% + /*普通字段*/ + %> <% }else if(isNotEmpty(field.fill)){ %> <% if(field.convert){ %> @TableField(value = "${field.name}", fill = FieldFill.${field.fill}) <% }else{ %> @TableField(fill = FieldFill.${field.fill}) <% } %> - <% }else{ %> + <% }else if(field.convert){ %> @TableField("${field.name}") <% } %> + <% + /*乐观锁注解*/ + %> + <% if(versionFieldName!'' == field.name){ %> + @Version + <% } %> + <% + /*逻辑删除注解*/ + %> + <% if(logicDeleteFieldName!'' == field.name){ %> + @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(entityBuilderModel){ %> + 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(entityBuilderModel){ %> + return this; + <% } %> + } + + <% } %> +<% } %> +<% if(entityColumnConstant){ %> + <% for(field in table.fields){ %> + public static final String ${strutil.toUpperCase(field.name)} = "${field.name}"; + + <% } %> +<% } %> +<% if(activeRecord){ %> + @Override + protected Serializable pkVal() { + <% if(isNotEmpty(keyPropertyName)){ %> + return this.${keyPropertyName}; + <% }else{ %> + return null; + <% } %> + } + +<% } %> +<% 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} + + <% } %> + <% } %> + "}"; + } +<% } %> } diff --git a/src/main/resources/templates/mybatis-plus/entity.kt.btl b/src/main/resources/templates/mybatis-plus/entity.kt.btl new file mode 100644 index 0000000000000000000000000000000000000000..5b6f3e9dc308a6281540f5e9db06cb7bf02fd2b9 --- /dev/null +++ b/src/main/resources/templates/mybatis-plus/entity.kt.btl @@ -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 +<% } %> +/** + *+ * ${table.comment!} + *
+ * + * @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.name}", type = IdType.AUTO) + <% }else if(isNotEmpty(idType)){ %> + @TableId(value = "${field.name}", type = IdType.${idType}) + <% }else if(field.convert){ %> + @TableId("${field.name}") + <% } %> + <% + /*普通字段*/ + %> + <% }else if(isNotEmpty(field.fill)){ %> + <% if(field.convert){ %> + @TableField(value = "${field.name}", fill = FieldFill.${field.fill}) + <% }else{ %> + @TableField(fill = FieldFill.${field.fill}) + <% } %> + <% }else if(field.convert){ %> + @TableField("${field.name}") + <% } %> + <% + /*乐观锁注解*/ + %> + <% 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} + + <% } %> + <% } %> + "}" + } +<% } %> +} diff --git a/src/main/resources/templates/mybatis-plus/mapper.java.btl b/src/main/resources/templates/mybatis-plus/mapper.java.btl index 345ac3d72feddffcf65fb94181ba37423e56b50d..95bf7ad918a2a415ec767afeb6e650feaa5e7c26 100644 --- a/src/main/resources/templates/mybatis-plus/mapper.java.btl +++ b/src/main/resources/templates/mybatis-plus/mapper.java.btl @@ -1,20 +1,20 @@ -package ${basePackage}.mapper; +package ${package.Mapper}; -import ${basePackage}.entity.${entityName}; -<% if(isNotEmpty(superDaoClassPackage)){ %> -import ${superDaoClassPackage}; -<% } %> -import org.apache.ibatis.annotations.Mapper; +import ${package.Entity}.${entity}; +import ${superMapperClassPackage}; /** *- * ${table.comment!} Mapper + * ${table.comment!} Mapper 接口 *
* * @author ${author} - * @date ${date} + * @since ${date} */ -@Mapper -public interface ${entityName}Mapper <% if(isNotEmpty(superDaoName)){ %>extends ${superDaoName}<${entityName}><% } %> { +<% if(kotlin){ %> +interface ${table.mapperName} : ${superMapperClass}<${entity}> +<% }else{ %> +public interface ${table.mapperName} extends ${superMapperClass}<${entity}> { } +<% } %> diff --git a/src/main/resources/templates/mybatis-plus/mapper.xml.btl b/src/main/resources/templates/mybatis-plus/mapper.xml.btl index 20cc5a3b57bec6ebf1b4be65288e08c9004926cc..4de8945b5a652effbb263cec455150cc477cf145 100644 --- a/src/main/resources/templates/mybatis-plus/mapper.xml.btl +++ b/src/main/resources/templates/mybatis-plus/mapper.xml.btl @@ -1,5 +1,41 @@ -@@ -18,7 +15,12 @@ import org.springframework.transaction.annotation.Transactional; * @since ${date} */ @Service -@Transactional(rollbackFor = Exception.class) -public class ${entityName}ServiceImpl <% if(isNotEmpty(superServiceImplName)){ %>extends ${superServiceImplName}<${entityName}Mapper, ${entityName}><% } %> implements ${entityName}Service { +<% if(kotlin){ %> +open class ${table.serviceImplName} : ${superServiceImplClass}<${table.mapperName}, ${entity}>(), ${table.serviceName} { + +} +<% }else{ %> +public class ${table.serviceImplName} extends ${superServiceImplClass}<${table.mapperName}, ${entity}> implements ${table.serviceName} { } +<% } %> diff --git a/src/main/resources/templates/mybatis-plus/service.java.btl b/src/main/resources/templates/mybatis-plus/service.java.btl index 13426613636c76e33a2d60b67789ec23ed2bff23..c3f6388287500afaa2f544fff74b3217c5d3f10e 100644 --- a/src/main/resources/templates/mybatis-plus/service.java.btl +++ b/src/main/resources/templates/mybatis-plus/service.java.btl @@ -1,6 +1,6 @@ -package ${basePackage}.service; +package ${package.Service}; -import ${basePackage}.entity.${entityName}; +import ${package.Entity}.${entity}; import ${superServiceClassPackage}; /** @@ -11,6 +11,10 @@ import ${superServiceClassPackage}; * @author ${author} * @since ${date} */ -public interface ${entityName}Service <% if(isNotEmpty(superServiceName)){ %>extends ${superServiceName}<${entityName}><% } %> { +<% if(kotlin){ %> +interface ${table.serviceName} : ${superServiceClass}<${entity}> +<% }else{ %> +public interface ${table.serviceName} extends ${superServiceClass}<${entity}> { } +<% } %>