diff --git a/README.md b/README.md index 63bc912..da7de4a 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,7 @@ Thanks for `JetBrains` providing us the `Licenses for Open Source Development` # Update Logs | 更新日期 | 更新内容 | |:-----------|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| 2023.01.02 | 新增TkMybatis模板(感谢@sgj666的建议)。 | | 2023.01.01 | 新增GCP BigQuery/Dataflow JJS/QlikSense BI模板。 | | 2022.09.28 | MySQL to Java type conversion 数据库类型转换优化(感谢@jadelike得贡献) | | 2022.07.02 | add the script to install and run,添加批处理以便直接构建或运行项目。 | diff --git a/generator-web/src/main/resources/template.json b/generator-web/src/main/resources/template.json index 89f0f5f..54ff69e 100644 --- a/generator-web/src/main/resources/template.json +++ b/generator-web/src/main/resources/template.json @@ -271,5 +271,25 @@ "description": "GCP Dataflow JJS" } ] + }, + { + "group": "tk-mybatis", + "templates": [ + { + "id": "401", + "name": "tk-entity", + "description": "tk-entity" + }, + { + "id": "402", + "name": "tk-mapper", + "description": "tk-mapper" + }, + { + "id": "403", + "name": "tk-controller", + "description": "tk-controller" + } + ] } ] \ No newline at end of file diff --git a/generator-web/src/main/resources/templates/code-generator/tk-mybatis/tk-controller.ftl b/generator-web/src/main/resources/templates/code-generator/tk-mybatis/tk-controller.ftl new file mode 100644 index 0000000..628b47a --- /dev/null +++ b/generator-web/src/main/resources/templates/code-generator/tk-mybatis/tk-controller.ftl @@ -0,0 +1,79 @@ +<#if isWithPackage?exists && isWithPackage==true>package ${packageName}.controller; +<#if isAutoImport?exists && isAutoImport==true> +import ${packageName}.entity.${classInfo.className}; +import ${packageName}.mapper.${classInfo.className}Mapper; +import org.springframework.data.domain.Example; +import org.springframework.data.domain.Pageable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RestController; +import java.util.List; +import java.util.Map; +import java.util.Optional; + + +/** + * @description ${classInfo.classComment} + * @author ${authorName} + * @date ${.now?string('yyyy-MM-dd')} + */ +@RestController +@RequestMapping("/${classInfo.className?uncap_first}") +public class ${classInfo.className}Controller { + + @Autowired + private ${classInfo.className}Mapper ${classInfo.className?uncap_first}Mapper; + + /** + * 新增或编辑 + */ + @PostMapping("/save") + public Object save(${classInfo.className} ${classInfo.className?uncap_first}){ + if(${classInfo.className?uncap_first}Mapper.selectCount(${classInfo.className?uncap_first})>0){ + ${classInfo.className?uncap_first}Mapper.insert(${classInfo.className?uncap_first}); + }else{ + ${classInfo.className?uncap_first}Mapper.updateByPrimaryKeySelective(${classInfo.className?uncap_first}); + } + return ${returnUtilSuccess}("新增或编辑成功"); + } + + /** + * 删除 + */ + @PostMapping("/delete") + public Object delete(int id){ + if(${classInfo.className?uncap_first}Mapper.selectCount(${classInfo.className?uncap_first})>0){ + ${classInfo.className?uncap_first}Mapper.deleteByPrimaryKey(id); + return ${returnUtilSuccess}("删除成功"); + }else{ + return ${returnUtilFailure}("没有找到该对象"); + } + } + + /** + * 查询 + */ + @PostMapping("/find") + public Object find(int id){ + Optional<${classInfo.className}> ${classInfo.className?uncap_first}=${classInfo.className?uncap_first}Mapper.selectOne(id); + if(${classInfo.className?uncap_first}.isPresent()){ + return ${returnUtilSuccess}(${classInfo.className?uncap_first}.get()); + }else{ + return ${returnUtilFailure}("没有找到该对象"); + } + } + + /** + * 分页查询 + */ + @PostMapping("/list") + public Object list(${classInfo.className} ${classInfo.className?uncap_first}, + @RequestParam(required = false, defaultValue = "0") int pageNumber, + @RequestParam(required = false, defaultValue = "10") int pageSize) { + //TBC + return ${classInfo.className?uncap_first}Mapper.selectList(${classInfo.className?uncap_first}); + } + +} diff --git a/generator-web/src/main/resources/templates/code-generator/tk-mybatis/tk-entity.ftl b/generator-web/src/main/resources/templates/code-generator/tk-mybatis/tk-entity.ftl new file mode 100644 index 0000000..41c6930 --- /dev/null +++ b/generator-web/src/main/resources/templates/code-generator/tk-mybatis/tk-entity.ftl @@ -0,0 +1,53 @@ +<#if isWithPackage?exists && isWithPackage==true>package ${packageName}.entity; + +<#if isAutoImport?exists && isAutoImport==true> +<#if isLombok?exists && isLombok==true>import lombok.Data; +import java.util.Date; +import java.util.List; +import java.io.Serializable; +import io.mybatis.provider.Entity; +<#if isSwagger?exists && isSwagger==true> +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +/** + * @description ${classInfo.classComment} + * @author ${authorName} + * @date ${.now?string('yyyy-MM-dd')} + */ +<#if isLombok?exists && isLombok==true>@Data +<#if isComment?exists && isComment==true>@Entity.Table("${classInfo.originTableName}")<#if isSwagger?exists && isSwagger==true> +@ApiModel("${classInfo.classComment}") +public class ${classInfo.className} implements Serializable { + + private static final long serialVersionUID = 1L; + + //@Entity.Column(id = true) +<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> +<#list classInfo.fieldList as fieldItem > + <#if isComment?exists && isComment==true>/** + * ${fieldItem.fieldComment} + */<#if isSwagger?exists && isSwagger==true> + @ApiModelProperty("${fieldItem.fieldComment}") + <#if isComment?exists && isComment==true>@Entity.Column("${fieldItem.columnName}") + private ${fieldItem.fieldClass} ${fieldItem.fieldName}; + + + public ${classInfo.className}() { + } + + +<#if isLombok?exists && isLombok==false> +<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> +<#list classInfo.fieldList as fieldItem > + public ${fieldItem.fieldClass} get${fieldItem.fieldName?cap_first}() { + return ${fieldItem.fieldName}; + } + + public void set${fieldItem.fieldName?cap_first}(${fieldItem.fieldClass} ${fieldItem.fieldName}) { + this.${fieldItem.fieldName} = ${fieldItem.fieldName}; + } + + + +} diff --git a/generator-web/src/main/resources/templates/code-generator/tk-mybatis/tk-mapper.ftl b/generator-web/src/main/resources/templates/code-generator/tk-mybatis/tk-mapper.ftl new file mode 100644 index 0000000..da6d61d --- /dev/null +++ b/generator-web/src/main/resources/templates/code-generator/tk-mybatis/tk-mapper.ftl @@ -0,0 +1,24 @@ +<#if isWithPackage?exists && isWithPackage==true>package ${packageName}.mapper; +<#if isAutoImport?exists && isAutoImport==true>import ${packageName}.entity.${classInfo.className}; + +<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0> + <#list classInfo.fieldList as fieldItem > + <#if fieldItem.fieldClass == "Date"> + <#assign importDdate = true /> + + + +import java.util.List; +import io.mybatis.mapper.Mapper; + +/** + * @description ${classInfo.classComment} + * @author ${authorName} + * @date ${.now?string('yyyy-MM-dd')} + */ +@org.apache.ibatis.annotations.Mapper +public interface ${classInfo.className}Mapper extends Mapper<${classInfo.className},Integer> { + + + +}