diff --git a/README.md b/README.md index 2147be28bcf9c6731bc321c7870a8f1d47d6c967..7ad0166c9493adbb9ad5cc070b678e649bea4b6c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # code-generator-maven-plugin -Language: [中文](README.zh.md) +Language: [English](README.md)
@@ -20,124 +20,81 @@ Language: [中文](README.zh.md)
-## Description -code-generator-maven-plugin is based on baomidou's mybatis-plus-generator,a Maven plugin that generates code in a Maven project。Key features: -- code-generator:**MyBatis**:Generate Controller.java, Service.java, Mapper.java, mapper.xml, Entity.java under MyBatis based on database tables; -- code-generator:**MyBatis-Plus**:Generate Controller.java, Service.java, Mapper.java, mapper.xml, Entity.java under MyBatis-Plus based on database tables; -- code-generator:**JPA**:Generate Controller.java, Service.java, Repository.java, Entity.java under JPA based on database tables; -- code-generator:**Customer**:Generate CRUD code based on database tables and specify custom template locations; -- code-generator:**Dockerfile**:Generate the Dockerfile file for the current project, along with the associated scripts: DockerImageBuild.bat, DockerImageBuildRun.bat, DockerImageDelete.bat -- code-generator:**Docker-Build**:Build Docker Image based on the locally installed Docker -- code-generator:**Docker-Deploy**:Build Docker image and deploy Docker container based on locally installed Docker -- code-generator:**Docker-Delete**:Delete deployed Docker containers and Docker images based on the locally installed Docker -- Theory can be extended to any background and front database table related technology: such as: vue.js. -- The theory supports all databases that support JDBC connection: for example: DB2, DM, H2, Mariadb, MySQL, Oracle, Postgre, Sqlite, SQLServer, etc. +## 简介 +code-generator-maven-plugin 在 Maven 项目中生成代码的 Maven 插件。主要包括: +- code-generator:**code**:基于数据库表,自定义 velocity 代码模板,生成 CRUD 或前端代码; +- code-generator:**mybatis**:基于数据库表,使用插件默认 MyBatis 模板生成 CRUD 代码; +- code-generator:**mybatis-plus**:基于数据库表,使用插件默认 MyBatis-Plus 模板生成 CRUD 代码; +- code-generator:**jpa**:基于数据库表,使用插件默认 JPA 模板生成 CRUD 代码; +- code-generator:**script**:生成脚本。包括:Dockerfile, app.sh, app.bat 等脚本。 -### SpringBoot Code Generator -[generator-spring-boot-starter](https://gitee.com/mengweijin/vitality) +备注: +- code-generator:**code** 插件理论可以生成任意前后台跟数据库表有关系的代码:如:Vue, Element-UI 代码等。 +- 理论支持所有支持JDBC连接的数据库:例如:DB2, DM, H2, Mariadb, MySQL, Oracle, Postgre, Sqlite, SQLServer -## how to use? -Locate the code-generator-maven-plugin in the Intellij IDEA Maven module shown below and double-click the corresponding plug-in command. +## 如何使用? - - -**Notes** -* The default Java code generation is under the target/code-generator/ directory of the current project. -* The default package path is com.github.mengweijin. -* The default Dockerfile and other files are generated in the target directory of the current project. -* The Customer plug-in must be configured with templateLocation parameters. By default, the templateType parameter is beetl. - -## Generating Java Code -### 1. General Use -In the standard SpringBoot project, take Intellij IDEA, a development tool, as an example: the code-generator-maven-plugin was introduced into Maven +在标准 SpringBoot 项目,以开发工具 Intellij IDEA 为例:在 Maven 中引入 code-generator-maven-plugin 插件 ~~~~xml
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ * $!{table.comment} + *
+ * + * @author ${author} + * @since ${date} + */ +@Data +#if("$!{baseEntity}" != "") +@EqualsAndHashCode(callSuper = true) +#else +@EqualsAndHashCode(callSuper = false) +#end +@Accessors(chain = true) +@Entity +@Table(name = "${table.name}") +#if("$!{baseEntityName}" != "") +public class ${entityName} extends ${baseEntityName} { +#else +public class ${entityName} implements Serializable { + + private static final long serialVersionUID = 1L; +#end +#foreach($field in ${entityFields}) + +#if("$!field.comment" != "") + /** + * ${field.comment} + */ +#end +#if(${field.keyFlag}) + @Id +#else + @Column(name= "${field.name}") +#end + private ${field.propertyType} ${field.propertyName}; +#end +} diff --git a/src/main/resources/templates/jpa/${entityName}Controller.java.vm b/src/main/resources/templates/jpa/${entityName}Controller.java.vm new file mode 100644 index 0000000000000000000000000000000000000000..098d993c064a9e2181095770512db1b3b1a1896c --- /dev/null +++ b/src/main/resources/templates/jpa/${entityName}Controller.java.vm @@ -0,0 +1,81 @@ +package ${package}; + +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import jakarta.validation.Valid; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.RequestParam; +import java.util.Optional; + +/** + *+ * $!{table.comment} Controller + *
+ * + * @author ${author} + * @since ${date} + */ +@Slf4j +@Validated +@RestController +@RequestMapping("${requestMapping}") +public class ${entityName}Controller { + + private ${entityName}Service ${entityPropertyName}Service; + + private ${entityName}Repository ${entityPropertyName}Repository; + + /** + *+ * Get ${entityName} by id + *
+ * @param id id + * @return ${entityName} + */ + @GetMapping("/{id}") + public Optional<${entityName}> getById(@PathVariable("id") ${idField.columnType.type} id) { + return ${entityPropertyName}Repository.findById(id); + } + + /** + *+ * Add ${entityName} + *
+ * @param ${entityPropertyName} {@link ${entityName}} + */ + @PostMapping + public void add(@Valid @RequestBody ${entityName} ${entityPropertyName}) { + ${entityPropertyName}Repository.save(${entityPropertyName}); + } + + /** + *+ * Update ${entityName} + *
+ * @param ${entityPropertyName} {@link ${entityName}} + */ + @PutMapping + public void update(@Valid @RequestBody ${entityName} ${entityPropertyName}) { + ${entityPropertyName}Repository.save(${entityPropertyName}); + } + + /** + *+ * Delete ${entityName} by id + *
+ * @param id id + */ + @DeleteMapping("/{id}") + public void delete(@Valid @PathVariable("id") ${idField.columnType.type} id) { + ${entityPropertyName}Repository.deleteById(id); + } + +} diff --git a/src/main/resources/templates/jpa/${entityName}DTO.java.vm b/src/main/resources/templates/jpa/${entityName}DTO.java.vm new file mode 100644 index 0000000000000000000000000000000000000000..145c510ff1a6b5db12e44657cb72c6d4a88cc24b --- /dev/null +++ b/src/main/resources/templates/jpa/${entityName}DTO.java.vm @@ -0,0 +1,25 @@ +package ${package}; + +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; +import java.io.Serial; +import java.io.Serializable; + +/** + *+ * ${entityName} DTO + *
+ * + * @author ${author} + * @since ${date} + */ +@Data +@EqualsAndHashCode(callSuper = true) +@Accessors(chain = true) +public class ${entityName}DTO extends ${entityName} implements Serializable { + + @Serial + private static final long serialVersionUID = 1L; + +} diff --git a/src/main/resources/templates/jpa/${entityName}Repository.java.vm b/src/main/resources/templates/jpa/${entityName}Repository.java.vm new file mode 100644 index 0000000000000000000000000000000000000000..ce0bf42cfddd98daefd538a753240eca78eb902d --- /dev/null +++ b/src/main/resources/templates/jpa/${entityName}Repository.java.vm @@ -0,0 +1,17 @@ +package ${package}; + +import org.springframework.stereotype.Repository; + +/** + *+ * $!{table.comment} ${entityName} Repository + *
+ * + * @author ${author} + * @since ${date} + */ +@Repository +public interface ${entityName}Repository { + +} + diff --git a/src/main/resources/templates/jpa/${entityName}Service.java.vm b/src/main/resources/templates/jpa/${entityName}Service.java.vm new file mode 100644 index 0000000000000000000000000000000000000000..b51f9f1d1c37dcde23cf8807bc56c473901533b0 --- /dev/null +++ b/src/main/resources/templates/jpa/${entityName}Service.java.vm @@ -0,0 +1,25 @@ +package ${package}; + +import java.util.List; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +/** + *+ * $!{table.comment} ${entityName} Service + * Add @Transactional(rollbackFor = Exception.class) if you need. + *
+ * + * @author ${author} + * @since ${date} + */ +@Slf4j +@AllArgsConstructor +@Service +public class ${entityName}Service { + + private ${entityName}Repository ${entityPropertyName}Repository; + +} + diff --git a/src/main/resources/templates/jpa/controller.java.btl b/src/main/resources/templates/jpa/controller.java.btl deleted file mode 100644 index 03b3ff8162fcdf2c002964a1d3d5154b207e0426..0000000000000000000000000000000000000000 --- a/src/main/resources/templates/jpa/controller.java.btl +++ /dev/null @@ -1,114 +0,0 @@ -package ${parameters.outputPackage}.controller; - -<% if(entityLombokModel){ %> -import lombok.extern.slf4j.Slf4j; -<% } %> -import javax.validation.Valid; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; -<% if(restControllerStyle){ %> -import org.springframework.web.bind.annotation.RestController; -<% }else{ %> -import org.springframework.stereotype.Controller; -<% } %> -<% if(isNotEmpty(superControllerClassPackage)){ %> -import ${superControllerClassPackage}; -<% } %> -import ${parameters.outputPackage}.entity.${entity}; -import ${parameters.outputPackage}.repository.${entity}Repository; -import ${parameters.outputPackage}.service.${entity}Service; -import java.util.Optional; - -/** - *- * ${table.comment!} Controller - *
- * - * @author ${author} - * @since ${date} - */ -<% if(entityLombokModel){ %> -@Slf4j -<% } %> -@Validated -<% if(restControllerStyle){ %> -@RestController -<% }else{ %> -@Controller -<% } %> -@RequestMapping("<% if(isNotEmpty(package.ModuleName)){ %>/${package.ModuleName}<% } %>/<% if(isNotEmpty(controllerMappingHyphenStyle)){ %>${controllerMappingHyphen}<% }else{ %>${table.entityPath}<% } %>") -<% if(isNotEmpty(superControllerClass)){ %> -public class ${entity}Controller extends ${superControllerClass} { -<% }else{ %> -public class ${entity}Controller { -<% } %> - - /** - *- * ${entity}Service - *
- */ - @Autowired - private ${entity}Service ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)}Service; - - /** - *- * ${entity}Repository - *
- */ - @Autowired - private ${entity}Repository ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)}Repository; - - /** - *- * Get ${entity} by id - *
- * @param id id - * @return ${entity} - */ - @GetMapping("/{id}") - public Optional<${entity}> getById(@PathVariable("id") ${idField.propertyType} id) { - return ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)}Repository.findById(id); - } - - /** - *- * Add ${entity} - *
- * @param ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)} ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)} - */ - @PostMapping - public void add(@Valid @RequestBody ${entity} ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)}) { - ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)}Repository.save(${@cn.hutool.core.util.StrUtil.lowerFirst(entity)}); - } - - /** - *- * Update ${entity} - *
- * @param ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)} ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)} - */ - @PutMapping - public void update(@Valid @RequestBody ${entity} ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)}) { - ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)}Repository.save(${@cn.hutool.core.util.StrUtil.lowerFirst(entity)}); - } - - /** - *- * Delete ${entity} by id - *
- * @param id id - */ - @DeleteMapping("/{id}") - public void delete(@Valid @PathVariable("id") ${idField.propertyType} id) { - ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)}Repository.deleteById(id); - } - -} diff --git a/src/main/resources/templates/jpa/entity.java.btl b/src/main/resources/templates/jpa/entity.java.btl deleted file mode 100644 index 5748441e0cd942c2a95ddc8e494e0ced4d457560..0000000000000000000000000000000000000000 --- a/src/main/resources/templates/jpa/entity.java.btl +++ /dev/null @@ -1,117 +0,0 @@ -package ${parameters.outputPackage}.entity; - -<% if(hasLongField){ %> -import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; -<% } %> -<% if(isNotEmpty(superEntityClassPackage)){ %> -import ${superEntityClassPackage}; -<% }else{ %> -import java.io.Serializable; -<% } %> -<% if(entityLombokModel){ %> -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.experimental.Accessors; -<% } %> -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; - -/** - *- * ${table.comment!} - *
- * - * @author ${author} - * @since ${date} - */ -<% if(entityLombokModel){ %> -@Data - <% if(isNotEmpty(superEntityClass)){ %> -@EqualsAndHashCode(callSuper = true) - <% }else{ %> -@EqualsAndHashCode(callSuper = false) - <% } %> -@Accessors(chain = true) -<% } %> -@Entity -@Table(name = "${table.name}") -<% if(isNotEmpty(superEntityClass)){ %> -public class ${entity} extends ${superEntityClass} { -<% }else{ %> -public class ${entity} implements Serializable { -<% } %> - -<% if(entitySerialVersionUID){ %> - private static final long serialVersionUID = 1L; -<% } %> -<% /** -----------BEGIN 字段循环遍历----------- **/ %> -<% for(field in table.fields){ %> - - <% if(isNotEmpty(field.comment)){ %> - /** - * ${field.comment!} - */ - <% } %> - <% if(field.keyFlag){ %> - @Id - <% } else { %> - @Column(name= "${field.name}") - <% } %> - <% if('Long' == field.propertyType){ %> - @JsonSerialize(using = ToStringSerializer.class) - <% } %> - 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(!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/jpa/repository.java.btl b/src/main/resources/templates/jpa/repository.java.btl deleted file mode 100644 index 2ab5316d81a722532ee2287bf57ee38aec32198a..0000000000000000000000000000000000000000 --- a/src/main/resources/templates/jpa/repository.java.btl +++ /dev/null @@ -1,21 +0,0 @@ -package ${parameters.outputPackage}.repository; - -import ${parameters.outputPackage}.entity.${entity}; -<% if(isNotEmpty(superMapperClassPackage)){ %> -import ${superMapperClassPackage}; -<% } %> -import org.springframework.stereotype.Repository; -import java.io.Serializable; - -/** - *- * ${entity} Repository Interface - *
- * - * @author ${author} - * @since ${date} - */ -@Repository -public interface ${entity}Repository extends ${superMapperClass}<${entity}, Serializable> { - -} diff --git a/src/main/resources/templates/jpa/service.java.btl b/src/main/resources/templates/jpa/service.java.btl deleted file mode 100644 index 9047d83b2da21fd2df611ffd5415bf829cbc7e0d..0000000000000000000000000000000000000000 --- a/src/main/resources/templates/jpa/service.java.btl +++ /dev/null @@ -1,33 +0,0 @@ -package ${parameters.outputPackage}.service; - -<% if(entityLombokModel){ %> -import lombok.extern.slf4j.Slf4j; -<% } %> -import ${parameters.outputPackage}.entity.${entity}; -import ${parameters.outputPackage}.repository.${entity}Repository; -import ${parameters.outputPackage}.service.${entity}Service; -<% if(isNotEmpty(superServiceImplClassPackage)){ %> -import ${superServiceImplClassPackage}; -<% } %> -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -/** - *- * ${table.comment!} implement - * Add @Transactional(rollbackFor = Exception.class) if you need. - *
- * - * @author ${author} - * @since ${date} - */ -<% if(entityLombokModel){ %> -@Slf4j -<% } %> -@Service -public class ${entity}Service { - - @Autowired - private ${entity}Repository ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)}Repository; - -} diff --git a/src/main/resources/templates/mybatis-plus/${entityName}.java.vm b/src/main/resources/templates/mybatis-plus/${entityName}.java.vm new file mode 100644 index 0000000000000000000000000000000000000000..f6f2a99c97341d2f6575b441c670f4f9e194cd4b --- /dev/null +++ b/src/main/resources/templates/mybatis-plus/${entityName}.java.vm @@ -0,0 +1,57 @@ +package ${package}; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.annotation.TableField; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; +#if("$!{baseEntity}" != "") +import ${baseEntity}; +#else +import java.io.Serializable; +#end + +/** + *+ * $!{table.comment} + *
+ * + * @author ${author} + * @since ${date} + */ +@Data +#if("$!{baseEntity}" != "") +@EqualsAndHashCode(callSuper = true) +#else +@EqualsAndHashCode(callSuper = false) +#end +@Accessors(chain = true) +@TableName("${table.name}") +#if("$!{baseEntityName}" != "") +public class ${entityName} extends ${baseEntityName} { +#else +public class ${entityName} implements Serializable { + + private static final long serialVersionUID = 1L; +#end +#foreach($field in ${entityFields}) + +#if("$!field.comment" != "") + /** + * ${field.comment} + */ +#end +#if(${field.keyFlag}) + @TableId("${field.annotationColumnName}") +#end +## 乐观锁注解 +#if(${field.versionField}) + @Version +#end +## 逻辑删除注解 +#if(${field.logicDeleteField}) + @TableLogic +#end + private ${field.propertyType} ${field.propertyName}; +#end +} diff --git a/src/main/resources/templates/mybatis/controller.java.btl b/src/main/resources/templates/mybatis-plus/${entityName}Controller.java.vm similarity index 33% rename from src/main/resources/templates/mybatis/controller.java.btl rename to src/main/resources/templates/mybatis-plus/${entityName}Controller.java.vm index 72d0eb6d01a66b15a2344753d91050c42d7469f2..dc6a1ae84bcc78c307c0c2602d4493c401ac05f3 100644 --- a/src/main/resources/templates/mybatis/controller.java.btl +++ b/src/main/resources/templates/mybatis-plus/${entityName}Controller.java.vm @@ -1,100 +1,100 @@ -package ${parameters.outputPackage}.controller; +package ${package}; -<% if(entityLombokModel){ %> +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.github.mengweijin.vitality.framework.domain.R; +import jakarta.validation.Valid; +import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; -<% } %> -import javax.validation.Valid; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; -<% if(restControllerStyle){ %> +import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -<% }else{ %> -import org.springframework.stereotype.Controller; -<% } %> -<% if(isNotEmpty(superControllerClassPackage)){ %> -import ${superControllerClassPackage}; -<% } %> -import ${parameters.outputPackage}.entity.${entity}; -import ${parameters.outputPackage}.service.${entity}Service; +import org.springframework.web.bind.annotation.RequestParam; /** *- * ${table.comment!} Controller + * $!{table.comment} ${entityName} Controller *
* * @author ${author} * @since ${date} */ -<% if(entityLombokModel){ %> @Slf4j -<% } %> +@AllArgsConstructor @Validated -<% if(restControllerStyle){ %> @RestController -<% }else{ %> -@Controller -<% } %> -@RequestMapping("<% if(isNotEmpty(moduleName)){ %>/${moduleName}<% } %>/${@cn.hutool.core.util.StrUtil.lowerFirst(entity)}") -public class ${entity}Controller <% if(isNotEmpty(superControllerName)){ %>extends ${superControllerName}<% } %> { +@RequestMapping("${requestMapping}") +public class ${entityName}Controller { + + private ${entityName}Service ${entityPropertyName}Service; /** *- * ${entity}Service + * Get ${entityName} page by ${entityName} *
+ * @param page page + * @param ${entityPropertyName} {@link ${entityName}} + * @return Page<${entityName}> */ - @Autowired - private ${entity}Service ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)}Service; + @GetMapping("/page") + public Page<${entityName}> page(Page<${entityName}> page, ${entityName} ${entityPropertyName}) { + return ${entityPropertyName}Service.page(page, new QueryWrapper<>(${entityPropertyName})); + } /** *- * Get ${entity} by id + * Get ${entityName} by id *
* @param id id - * @return ${entity} + * @return ${entityName} */ @GetMapping("/{id}") - public ${entity} getById(@PathVariable("id") ${idField.propertyType} id) { - return ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)}Service.getById(id); + public ${entityName} getById(@PathVariable("id") ${idField.columnType.type} id) { + return ${entityPropertyName}Service.getById(id); } /** *- * Add ${entity} + * Add ${entityName} *
- * @param ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)} ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)} + * @param ${entityPropertyName} {@link ${entityName}} */ @PostMapping - public void add(@Valid @RequestBody ${entity} ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)}) { - ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)}Service.save(${@cn.hutool.core.util.StrUtil.lowerFirst(entity)}); + public R- * Update ${entity} + * Update ${entityName} *
- * @param ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)} ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)} + * @param ${entityPropertyName} {@link ${entityName}} */ @PutMapping - public void update(@Valid @RequestBody ${entity} ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)}) { - ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)}Service.updateById(${@cn.hutool.core.util.StrUtil.lowerFirst(entity)}); + public R- * Delete ${entity} by id + * Delete ${entityName} by id(s), Multiple ids can be separated by commas ",". *
- * @param id id + * @param ids id */ - @DeleteMapping("/{id}") - public void delete(@PathVariable("id") ${idField.propertyType} id) { - ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)}Service.removeById(id); + @DeleteMapping("/{ids}") + public R+ * ${entityName} DTO + *
+ * + * @author ${author} + * @since ${date} + */ +@Data +@EqualsAndHashCode(callSuper = true) +@Accessors(chain = true) +public class ${entityName}DTO extends ${entityName} implements Serializable { + + @Serial + private static final long serialVersionUID = 1L; + +} diff --git a/src/main/resources/templates/mybatis-plus/${entityName}Mapper.java.vm b/src/main/resources/templates/mybatis-plus/${entityName}Mapper.java.vm new file mode 100644 index 0000000000000000000000000000000000000000..47131e085e10c48d4bf5115bf6de017f7e68f304 --- /dev/null +++ b/src/main/resources/templates/mybatis-plus/${entityName}Mapper.java.vm @@ -0,0 +1,28 @@ +package ${package}; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +/** + *+ * $!{table.comment} ${entityName} Mapper + *
+ * + * @author ${author} + * @since ${date} + */ +@Mapper +public interface ${entityName}Mapper extends BaseMapper<${entityName}> { + + /** + * Custom paging query + * @param page page + * @param ${entityPropertyName} {@link ${entityName}} + * @return IPage + */ + IPage<${entityName}> page(IPage<${entityName}> page, @Param("p") ${entityName} ${entityPropertyName}); + +} + diff --git a/src/main/resources/templates/mybatis-plus/${entityName}Mapper.xml.vm b/src/main/resources/templates/mybatis-plus/${entityName}Mapper.xml.vm new file mode 100644 index 0000000000000000000000000000000000000000..645cfe983049a0bfd395e72e1c1c76645f41bb71 --- /dev/null +++ b/src/main/resources/templates/mybatis-plus/${entityName}Mapper.xml.vm @@ -0,0 +1,46 @@ + + ++ * $!{table.comment} ${entityName} Service + * Add @Transactional(rollbackFor = Exception.class) if you need. + *
+ * + * @author ${author} + * @since ${date} + */ +@Slf4j +@Service +public class ${entityName}Service extends ServiceImpl<${entityName}Mapper, ${entityName}> { + + /** + * Custom paging query + * @param page page + * @param ${entityPropertyName} {@link ${entityName}} + * @return IPage + */ + public IPage<${entityName}> page(IPage<${entityName}> page, ${entityName} ${entityPropertyName}){ + return this.getBaseMapper().page(page, ${entityPropertyName}); + } +} + diff --git a/src/main/resources/templates/mybatis-plus/controller.java.btl b/src/main/resources/templates/mybatis-plus/controller.java.btl deleted file mode 100644 index 5db3f90337ed0fea2d36c86405890ef3448e37cc..0000000000000000000000000000000000000000 --- a/src/main/resources/templates/mybatis-plus/controller.java.btl +++ /dev/null @@ -1,117 +0,0 @@ -package ${parameters.outputPackage}.controller; - -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO; -<% if(entityLombokModel){ %> -import lombok.extern.slf4j.Slf4j; -<% } %> -import javax.validation.Valid; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestParam; -<% if(restControllerStyle){ %> -import org.springframework.web.bind.annotation.RestController; -<% }else{ %> -import org.springframework.stereotype.Controller; -<% } %> -<% if(isNotEmpty(superControllerClassPackage)){ %> -import ${superControllerClassPackage}; -<% } %> -import ${parameters.outputPackage}.entity.${entity}; -import ${parameters.outputPackage}.service.${entity}Service; - -/** - *- * ${table.comment!} Controller - *
- * - * @author ${author} - * @since ${date} - */ -<% if(entityLombokModel){ %> -@Slf4j -<% } %> -@Validated -<% if(restControllerStyle){ %> -@RestController -<% }else{ %> -@Controller -<% } %> -@RequestMapping("<% if(isNotEmpty(package.ModuleName)){ %>/${package.ModuleName}<% } %>/<% if(isNotEmpty(controllerMappingHyphenStyle)){ %>${controllerMappingHyphen}<% }else{ %>${table.entityPath}<% } %>") -public class ${entity}Controller <% if(isNotEmpty(superControllerClass)){ %>extends ${superControllerClass}<% } %> { - - /** - *- * ${entity}Service - *
- */ - @Autowired - private ${entity}Service ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)}Service; - - /** - *- * Get ${entity} page list by ${entity} - *
- * @param page page - * @param ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)} ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)} - * @return PageDTO<${entity}> - */ - @GetMapping("/page") - public PageDTO<${entity}> page(PageDTO<${entity}> page, ${entity} ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)}) { - return ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)}Service.page(page, new QueryWrapper<>(${@cn.hutool.core.util.StrUtil.lowerFirst(entity)})); - } - - /** - *- * Get ${entity} by id - *
- * @param id id - * @return ${entity} - */ - @GetMapping("/{id}") - public ${entity} getById(@PathVariable("id") ${idField.propertyType} id) { - return ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)}Service.getById(id); - } - - /** - *- * Add ${entity} - *
- * @param ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)} ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)} - */ - @PostMapping - public void add(@Valid @RequestBody ${entity} ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)}) { - ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)}Service.save(${@cn.hutool.core.util.StrUtil.lowerFirst(entity)}); - } - - /** - *- * Update ${entity} - *
- * @param ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)} ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)} - */ - @PutMapping - public void update(@Valid @RequestBody ${entity} ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)}) { - ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)}Service.updateById(${@cn.hutool.core.util.StrUtil.lowerFirst(entity)}); - } - - /** - *- * Delete ${entity} by id - *
- * @param id id - */ - @DeleteMapping("/{id}") - public void delete(@PathVariable("id") ${idField.propertyType} id) { - ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)}Service.removeById(id); - } - -} - diff --git a/src/main/resources/templates/mybatis-plus/entity.java.btl b/src/main/resources/templates/mybatis-plus/entity.java.btl deleted file mode 100644 index 407a12fba592742a63b6fa492ec45e28ee96141d..0000000000000000000000000000000000000000 --- a/src/main/resources/templates/mybatis-plus/entity.java.btl +++ /dev/null @@ -1,151 +0,0 @@ -package ${parameters.outputPackage}.entity; - -import com.baomidou.mybatisplus.annotation.TableName; -import com.baomidou.mybatisplus.annotation.TableField; -<% if(hasLongField){ %> -import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; -<% } %> -<% if(isNotEmpty(superEntityClassPackage)){ %> -import ${superEntityClassPackage}; -<% }else{ %> -import java.io.Serializable; -<% } %> -<% if(entityLombokModel){ %> -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.experimental.Accessors; -<% } %> - -/** - *- * ${table.comment!} - *
- * - * @author ${author} - * @since ${date} - */ -<% if(entityLombokModel){ %> -@Data - <% if(isNotEmpty(superEntityClass)){ %> -@EqualsAndHashCode(callSuper = true) - <% }else{ %> -@EqualsAndHashCode(callSuper = false) - <% } %> -@Accessors(chain = true) -<% } %> -<% if(table.convert){ %> -@TableName("${table.name}") -<% } %> -<% if(isNotEmpty(superEntityClass)){ %> -public class ${entity} extends ${superEntityClass} { -<% }else{ %> -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)){ %> - /** - * ${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('Long' == field.propertyType){ %> - @JsonSerialize(using = ToStringSerializer.class) - <% } %> - 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(!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/mapper.java.btl b/src/main/resources/templates/mybatis-plus/mapper.java.btl deleted file mode 100644 index 903fd2f4072ff0269568d3eef01f257e2e6e584a..0000000000000000000000000000000000000000 --- a/src/main/resources/templates/mybatis-plus/mapper.java.btl +++ /dev/null @@ -1,21 +0,0 @@ -package ${parameters.outputPackage}.mapper; - -import ${parameters.outputPackage}.entity.${entity}; -<% if(isNotEmpty(superMapperClassPackage)){ %> -import ${superMapperClassPackage}; -<% } %> -import org.apache.ibatis.annotations.Mapper; - -/** - *- * ${table.comment!} Mapper Interface - *
- * - * @author ${author} - * @since ${date} - */ -@Mapper -public interface ${entity}Mapper 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 deleted file mode 100644 index da9a6a5607ec2f644cb23a664ebdbd6ba77e746d..0000000000000000000000000000000000000000 --- a/src/main/resources/templates/mybatis-plus/mapper.xml.btl +++ /dev/null @@ -1,44 +0,0 @@ - - -- * ${table.comment!} implement - * Add @Transactional(rollbackFor = Exception.class) if you need. - *
- * - * @author ${author} - * @since ${date} - */ -<% if(entityLombokModel){ %> -@Slf4j -<% } %> -@Service -public class ${entity}Service extends ${superServiceImplClass}<${entity}Mapper, ${entity}> implements ${superServiceClass}<${entity}> { - - /** - *- * ${entity}Mapper - *
- */ - @Autowired - private ${entity}Mapper ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)}Mapper; -} - diff --git a/src/main/resources/templates/mybatis/${entityName}.java.vm b/src/main/resources/templates/mybatis/${entityName}.java.vm new file mode 100644 index 0000000000000000000000000000000000000000..db2a01f5bad7324f331bdf4165eff70062bec444 --- /dev/null +++ b/src/main/resources/templates/mybatis/${entityName}.java.vm @@ -0,0 +1,43 @@ +package ${package}; + +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; +#if("$!{baseEntity}" != "") +import ${baseEntity}; +#else +import java.io.Serializable; +#end + +/** + *+ * $!{table.comment} + *
+ * + * @author ${author} + * @since ${date} + */ +@Data +#if("$!{baseEntity}" != "") +@EqualsAndHashCode(callSuper = true) +#else +@EqualsAndHashCode(callSuper = false) +#end +@Accessors(chain = true) +#if("$!{baseEntityName}" != "") +public class ${entityName} extends ${baseEntityName} { +#else +public class ${entityName} implements Serializable { + + private static final long serialVersionUID = 1L; +#end +#foreach($field in ${entityFields}) + +#if("$!field.comment" != "") + /** + * ${field.comment} + */ +#end + private ${field.propertyType} ${field.propertyName}; +#end +} diff --git a/src/main/resources/templates/mybatis/${entityName}Controller.java.vm b/src/main/resources/templates/mybatis/${entityName}Controller.java.vm new file mode 100644 index 0000000000000000000000000000000000000000..0f15a2d3f6b1b5c1c49a71c773ea4c58a9a06cf6 --- /dev/null +++ b/src/main/resources/templates/mybatis/${entityName}Controller.java.vm @@ -0,0 +1,98 @@ +package ${package}; + +import com.github.mengweijin.vitality.framework.domain.R; +import jakarta.validation.Valid; +import java.util.Arrays; +import java.util.List; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.RequestParam; + +/** + *+ * $!{table.comment} ${entityName} Controller + *
+ * + * @author ${author} + * @since ${date} + */ +@Slf4j +@AllArgsConstructor +@Validated +@RestController +@RequestMapping("${requestMapping}") +public class ${entityName}Controller { + + private ${entityName}Service ${entityPropertyName}Service; + + /** + *+ * Get ${entityName} list by ${entityName} + *
+ * @param ${entityPropertyName} {@link ${entityName}} + * @return List<${entityName}> + */ + @GetMapping("/list") + public List<${entityName}> list(${entityName} ${entityPropertyName}) { + return ${entityPropertyName}Service.list(${entityPropertyName}); + } + + /** + *+ * Get ${entityName} by id + *
+ * @param id id + * @return ${entityName} + */ + @GetMapping("/{id}") + public ${entityName} getById(@PathVariable("id") ${idField.columnType.type} id) { + return ${entityPropertyName}Service.getById(id); + } + + /** + *+ * Add ${entityName} + *
+ * @param ${entityPropertyName} {@link ${entityName}} + */ + @PostMapping + public R+ * Update ${entityName} + *
+ * @param ${entityPropertyName} {@link ${entityName}} + */ + @PutMapping + public R+ * Delete ${entityName} by id(s), Multiple ids can be separated by commas ",". + *
+ * @param ids id + */ + @DeleteMapping("/{ids}") + public R+ * ${entityName} DTO + *
+ * + * @author ${author} + * @since ${date} + */ +@Data +@EqualsAndHashCode(callSuper = true) +@Accessors(chain = true) +public class ${entityName}DTO extends ${entityName} implements Serializable { + + @Serial + private static final long serialVersionUID = 1L; + +} diff --git a/src/main/resources/templates/mybatis/${entityName}Mapper.java.vm b/src/main/resources/templates/mybatis/${entityName}Mapper.java.vm new file mode 100644 index 0000000000000000000000000000000000000000..44e626b07aa5ca1ceed1df00f63ec378746fc669 --- /dev/null +++ b/src/main/resources/templates/mybatis/${entityName}Mapper.java.vm @@ -0,0 +1,67 @@ +package ${package}; + +import java.util.List; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +/** + *+ * $!{table.comment} ${entityName} Mapper + *
+ * + * @author ${author} + * @since ${date} + */ +@Mapper +public interface ${entityName}Mapper { + + /** + * select ${entityName} by id + * + * @param id id + * @return ${entityName} + */ + ${entityName} getById(${idField.columnType.type} id); + + /** + * select ${entityName} List + * + * @param ${entityPropertyName} {@link ${entityName}} + * @return ${entityName} + */ + List<${entityName}> selectList(${entityName} ${entityPropertyName}); + + /** + * insert ${entityName} + * + * @param ${entityPropertyName} {@link ${entityName}} + * @return int + */ + int save(${entityName} ${entityPropertyName}); + + /** + * update ${entityName} + * + * @param ${entityPropertyName} {@link ${entityName}} + * @return int + */ + int updateById(${entityName} ${entityPropertyName}); + + /** + * delete ${entityName} by id + * + * @param id id + * @return int + */ + int deleteById(${idField.columnType.type} id); + + /** + * delete batch by ids + * + * @param ids ids + * @return int + */ + int deleteBatchIds(List<${idField.columnType.type}> ids); + +} + diff --git a/src/main/resources/templates/mybatis/${entityName}Mapper.xml.vm b/src/main/resources/templates/mybatis/${entityName}Mapper.xml.vm new file mode 100644 index 0000000000000000000000000000000000000000..f24abe6bc5a53c3c6153867a62696af191158daa --- /dev/null +++ b/src/main/resources/templates/mybatis/${entityName}Mapper.xml.vm @@ -0,0 +1,88 @@ + + ++ * $!{table.comment} ${entityName} Service + * Add @Transactional(rollbackFor = Exception.class) if you need. + *
+ * + * @author ${author} + * @since ${date} + */ +@Slf4j +@AllArgsConstructor +@Service +public class ${entityName}Service { + + private ${entityName}Mapper ${entityPropertyName}Mapper; + + /** + *+ * Select ${entityName} by id + *
+ * @param id id + */ + public ${entityName} getById(${idField.columnType.type} id) { + return ${entityPropertyName}Mapper.getById(id); + } + + /** + *+ * Select List<${entityName}> + *
+ * @param ${entityPropertyName} {@link ${entityName}} + */ + public List<${entityName}> list(${entityName} ${entityPropertyName}) { + return ${entityPropertyName}Mapper.selectList(${entityPropertyName}); + } + + /** + *+ * Add ${entityName} + *
+ * @param ${entityPropertyName} {@link ${entityName}} + */ + public int save(${entityName} ${entityPropertyName}) { + return ${entityPropertyName}Mapper.save(${entityPropertyName}); + } + + /** + *+ * Update ${entityName} + *
+ * @param ${entityPropertyName} {@link ${entityName}} + */ + public int updateById(${entityName} ${entityPropertyName}) { + return ${entityPropertyName}Mapper.updateById(${entityPropertyName}); + } + + /** + *+ * Delete ${entityName} by id + *
+ * @param id id + */ + public int deleteById(${idField.columnType.type} id) { + return ${entityPropertyName}Mapper.deleteById(id); + } + + /** + *+ * Delete ${entityName} batch by ids + *
+ * @param ids id + */ + public int deleteBatchIds(List<${idField.columnType.type}> ids) { + return ${entityPropertyName}Mapper.deleteBatchIds(ids); + } +} + diff --git a/src/main/resources/templates/mybatis/entity.java.btl b/src/main/resources/templates/mybatis/entity.java.btl deleted file mode 100644 index a91253d3434830ef25b2b985d078bdbc335da3ce..0000000000000000000000000000000000000000 --- a/src/main/resources/templates/mybatis/entity.java.btl +++ /dev/null @@ -1,106 +0,0 @@ -package ${parameters.outputPackage}.entity; - -<% if(hasLongField){ %> -import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; -<% } %> -<% if(isNotEmpty(superEntityClassPackage)){ %> -import ${superEntityClassPackage}; -<% }else{ %> -import java.io.Serializable; -<% } %> -<% if(entityLombokModel){ %> -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.experimental.Accessors; -<% } %> - -/** - *- * ${table.comment!} - *
- * - * @author ${author} - * @since ${date} - */ -<% if(entityLombokModel){ %> -@Data - <% if(isNotEmpty(superEntityClass)){ %> -@EqualsAndHashCode(callSuper = true) - <% }else{ %> -@EqualsAndHashCode(callSuper = false) - <% } %> -@Accessors(chain = true) -<% } %> -<% if(isNotEmpty(superEntityClass)){ %> -public class ${entity} extends ${superEntityClass} { -<% }else{ %> -public class ${entity} implements Serializable { -<% } %> - -<% if(entitySerialVersionUID){ %> - private static final long serialVersionUID = 1L; -<% } %> -<% /** -----------BEGIN 字段循环遍历----------- **/ %> -<% for(field in table.fields){ %> - - <% if(isNotEmpty(field.comment)){ %> - /** - * ${field.comment!} - */ - <% } %> - <% if('Long' == field.propertyType){ %> - @JsonSerialize(using = ToStringSerializer.class) - <% } %> - 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(!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/mapper.java.btl b/src/main/resources/templates/mybatis/mapper.java.btl deleted file mode 100644 index dff2ac4a83257973f9ba98528bac9b6db0a4d70b..0000000000000000000000000000000000000000 --- a/src/main/resources/templates/mybatis/mapper.java.btl +++ /dev/null @@ -1,67 +0,0 @@ -package ${parameters.outputPackage}.mapper; - -import ${parameters.outputPackage}.entity.${entity}; -import org.apache.ibatis.annotations.Mapper; -import java.util.List; - -/** - *- * ${table.comment!} Mapper Interface - *
- * - * @author ${author} - * @since ${date} - */ -@Mapper -public interface ${entity}Mapper { - - /** - * select ${entity} by id - * - * @param id id - * @return ${entity} - */ - ${entity} getById(${idField.propertyType} id); - - /** - * select ${entity} List - * - * @param ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)} ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)} - * @return ${entity} - */ - List<${entity}> selectList(${entity} ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)}); - - /** - * insert ${entity} - * - * @param ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)} ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)} - * @return int - */ - int save(${entity} ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)}); - - /** - * update ${entity} - * - * @param ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)} ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)} - * @return int - */ - int updateById(${entity} ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)}); - - /** - * delete ${entity} by id - * - * @param id id - * @return int - */ - int removeById(${idField.propertyType} id); - - /** - * delete batch by ids - * - * @param ids ids - * @return int - */ - int deleteBatchByIds(${idField.propertyType}[] ids); - -} - diff --git a/src/main/resources/templates/mybatis/mapper.xml.btl b/src/main/resources/templates/mybatis/mapper.xml.btl deleted file mode 100644 index 908bcb64affc4f912efa14e0a71a6b079e19cf60..0000000000000000000000000000000000000000 --- a/src/main/resources/templates/mybatis/mapper.xml.btl +++ /dev/null @@ -1,116 +0,0 @@ - - -- * ${entity} Service implement - * Add @Transactional(rollbackFor = Exception.class) if you need. - *
- * - * @author ${author} - * @since ${date} - */ -<% if(entityLombokModel){ %> -@Slf4j -<% } %> -@Service -public class ${entity}Service <% if(isNotEmpty(superServiceClass)){ %>implements ${superServiceClass}<% } %> { - - /** - *- * ${entity}Mapper - *
- */ - @Autowired - private ${entity}Mapper ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)}Mapper; - - /** - *- * Select ${entity} by id - *
- * @param id id - */ - <% if(isNotEmpty(superServiceClass)){ %> - @Override - <% } %> - public ${entity} getById(${idField.propertyType} id) { - return ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)}Mapper.getById(id); - } - - /** - *- * Select List<${entity}> - *
- * @param ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)} ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)} - */ - <% if(isNotEmpty(superServiceClass)){ %> - @Override - <% } %> - public List<${entity}> list(${entity} ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)}) { - return ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)}Mapper.selectList(${@cn.hutool.core.util.StrUtil.lowerFirst(entity)}); - } - - /** - *- * Add ${entity} - *
- * @param ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)} ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)} - */ - <% if(isNotEmpty(superServiceClass)){ %> - @Override - <% } %> - public void save(${entity} ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)}) { - ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)}Mapper.save(${@cn.hutool.core.util.StrUtil.lowerFirst(entity)}); - } - - /** - *- * Update ${entity} - *
- * @param ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)} ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)} - */ - <% if(isNotEmpty(superServiceClass)){ %> - @Override - <% } %> - public void updateById(${entity} ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)}) { - ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)}Mapper.updateById(${@cn.hutool.core.util.StrUtil.lowerFirst(entity)}); - } - - /** - *- * Delete ${entity} by id - *
- * @param id id - */ - <% if(isNotEmpty(superServiceClass)){ %> - @Override - <% } %> - public void removeById(${idField.propertyType} id) { - ${@cn.hutool.core.util.StrUtil.lowerFirst(entity)}Mapper.removeById(id); - } -} diff --git a/src/test/java/com/github/mengweijin/generator/mojo/DockerDeployMojoTest.java b/src/test/java/com/github/mengweijin/generator/mojo/DockerDeployMojoTest.java index ba284bca485cc411898c6104cfa4c6942197d599..262ce56c2c5e6d6b6a060eaf3da5e7df43f02ffc 100644 --- a/src/test/java/com/github/mengweijin/generator/mojo/DockerDeployMojoTest.java +++ b/src/test/java/com/github/mengweijin/generator/mojo/DockerDeployMojoTest.java @@ -1,8 +1,8 @@ package com.github.mengweijin.generator.mojo; -import cn.hutool.core.io.FileUtil; -import cn.hutool.core.util.RuntimeUtil; -import cn.hutool.core.util.StrUtil; +import org.dromara.hutool.core.io.file.FileUtil; +import org.dromara.hutool.core.text.StrUtil; +import org.dromara.hutool.core.util.RuntimeUtil; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test;