mirror of
				https://github.com/YunaiV/ruoyi-vue-pro.git
				synced 2025-10-31 10:37:41 +08:00 
			
		
		
		
	添加 controller.vm 的模板
This commit is contained in:
		| @ -0,0 +1,78 @@ | |||||||
|  | package cn.iocoder.dashboard.modules.system.controller.test; | ||||||
|  |  | ||||||
|  | import cn.iocoder.dashboard.common.pojo.CommonResult; | ||||||
|  | import cn.iocoder.dashboard.common.pojo.PageResult; | ||||||
|  | import cn.iocoder.dashboard.modules.system.controller.test.vo.SysTestDemoCreateReqVO; | ||||||
|  | import cn.iocoder.dashboard.modules.system.controller.test.vo.SysTestDemoPageReqVO; | ||||||
|  | import cn.iocoder.dashboard.modules.system.controller.test.vo.SysTestDemoRespVO; | ||||||
|  | import cn.iocoder.dashboard.modules.system.controller.test.vo.SysTestDemoUpdateReqVO; | ||||||
|  | import cn.iocoder.dashboard.modules.system.convert.test.SysTestDemoConvert; | ||||||
|  | import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.test.SysTestDemoDO; | ||||||
|  | import cn.iocoder.dashboard.modules.system.service.test.SysTestDemoService; | ||||||
|  | import io.swagger.annotations.Api; | ||||||
|  | import io.swagger.annotations.ApiImplicitParam; | ||||||
|  | import io.swagger.annotations.ApiOperation; | ||||||
|  | import org.springframework.validation.annotation.Validated; | ||||||
|  | import org.springframework.web.bind.annotation.*; | ||||||
|  |  | ||||||
|  | import javax.annotation.Resource; | ||||||
|  | import javax.validation.Valid; | ||||||
|  | import java.util.Collection; | ||||||
|  | import java.util.List; | ||||||
|  |  | ||||||
|  | import static cn.iocoder.dashboard.common.pojo.CommonResult.success; | ||||||
|  |  | ||||||
|  | @Api(tags = "字典类型") | ||||||
|  | @RestController | ||||||
|  | @RequestMapping("/system/test-demo") | ||||||
|  | @Validated | ||||||
|  | public class SysTestDemoController { | ||||||
|  |  | ||||||
|  |     @Resource | ||||||
|  |     private SysTestDemoService testDemoService; | ||||||
|  |  | ||||||
|  |     @ApiOperation("创建字典类型") | ||||||
|  |     @PostMapping("/create") | ||||||
|  |     public CommonResult<Long> createTestDemo(@Valid SysTestDemoCreateReqVO createReqVO) { | ||||||
|  |         return success(testDemoService.createTestDemo(createReqVO)); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     @ApiOperation("更新字典类型") | ||||||
|  |     @PutMapping("/update") | ||||||
|  |     public CommonResult<Boolean> updateTestDemo(@Valid SysTestDemoUpdateReqVO updateReqVO) { | ||||||
|  |         testDemoService.updateTestDemo(updateReqVO); | ||||||
|  |         return success(true); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  | 	@ApiOperation("删除字典类型") | ||||||
|  | 	@DeleteMapping("/delete") | ||||||
|  |     @ApiImplicitParam(name = "id", value = "编号", required = true) | ||||||
|  |     public CommonResult<Boolean> deleteTestDemo(@RequestParam("id") Long id) { | ||||||
|  |         testDemoService.deleteTestDemo(id); | ||||||
|  |         return success(true); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     @GetMapping("/get") | ||||||
|  |     @ApiOperation("获得字典类型") | ||||||
|  |     @ApiImplicitParam(name = "id", value = "编号", required = true) | ||||||
|  |     public CommonResult<SysTestDemoRespVO> getTestDemo(@RequestParam("id") Long id) { | ||||||
|  |         SysTestDemoDO testDemo = testDemoService.getTestDemo(id); | ||||||
|  |         return success(SysTestDemoConvert.INSTANCE.convert(testDemo)); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     @GetMapping("/list") | ||||||
|  |     @ApiOperation("获得字典类型列表") | ||||||
|  |     @ApiImplicitParam(name = "ids", value = "编号列表", required = true) | ||||||
|  |     public CommonResult<List<SysTestDemoRespVO>> getTestDemoList(@RequestParam("ids") Collection<Long> ids) { | ||||||
|  |         List<SysTestDemoDO> list = testDemoService.getTestDemoList(ids); | ||||||
|  |         return success(SysTestDemoConvert.INSTANCE.convertList(list)); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     @ApiOperation("获得字典类型分页") | ||||||
|  |     @GetMapping("/page") | ||||||
|  |     public CommonResult<PageResult<SysTestDemoRespVO>> getTestDemoPage(@Valid SysTestDemoPageReqVO pageVO) { | ||||||
|  |         PageResult<SysTestDemoDO> pageResult = testDemoService.getTestDemoPage(pageVO); | ||||||
|  |         return success(SysTestDemoConvert.INSTANCE.convertPage(pageResult)); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  | } | ||||||
| @ -4,6 +4,7 @@ import cn.hutool.extra.template.TemplateConfig; | |||||||
| import cn.hutool.extra.template.TemplateEngine; | import cn.hutool.extra.template.TemplateEngine; | ||||||
| import cn.hutool.extra.template.TemplateUtil; | import cn.hutool.extra.template.TemplateUtil; | ||||||
| import cn.iocoder.dashboard.common.exception.util.ServiceExceptionUtil; | import cn.iocoder.dashboard.common.exception.util.ServiceExceptionUtil; | ||||||
|  | import cn.iocoder.dashboard.common.pojo.CommonResult; | ||||||
| import cn.iocoder.dashboard.common.pojo.PageParam; | import cn.iocoder.dashboard.common.pojo.PageParam; | ||||||
| import cn.iocoder.dashboard.common.pojo.PageResult; | import cn.iocoder.dashboard.common.pojo.PageResult; | ||||||
| import cn.iocoder.dashboard.framework.mybatis.core.dataobject.BaseDO; | import cn.iocoder.dashboard.framework.mybatis.core.dataobject.BaseDO; | ||||||
| @ -58,6 +59,7 @@ public class ToolCodegenEngine { | |||||||
|         // 全局配置 |         // 全局配置 | ||||||
|         globalBindingMap.put("basePackage", "cn.iocoder.dashboard.modules"); // TODO 基础包, 抽成参数 |         globalBindingMap.put("basePackage", "cn.iocoder.dashboard.modules"); // TODO 基础包, 抽成参数 | ||||||
|         // 全局 Java Bean |         // 全局 Java Bean | ||||||
|  |         globalBindingMap.put("CommonResultClassName", CommonResult.class.getName()); | ||||||
|         globalBindingMap.put("PageResultClassName", PageResult.class.getName()); |         globalBindingMap.put("PageResultClassName", PageResult.class.getName()); | ||||||
|         globalBindingMap.put("DateUtilsClassName", DateUtils.class.getName()); |         globalBindingMap.put("DateUtilsClassName", DateUtils.class.getName()); | ||||||
|         globalBindingMap.put("ServiceExceptionUtilClassName", ServiceExceptionUtil.class.getName()); |         globalBindingMap.put("ServiceExceptionUtilClassName", ServiceExceptionUtil.class.getName()); | ||||||
| @ -76,6 +78,7 @@ public class ToolCodegenEngine { | |||||||
|         bindingMap.put("table", table); |         bindingMap.put("table", table); | ||||||
|         bindingMap.put("columns", columns); |         bindingMap.put("columns", columns); | ||||||
|         bindingMap.put("primaryColumn", CollectionUtils.findFirst(columns, ToolCodegenColumnDO::getPrimaryKey)); // 主键字段 |         bindingMap.put("primaryColumn", CollectionUtils.findFirst(columns, ToolCodegenColumnDO::getPrimaryKey)); // 主键字段 | ||||||
|  |         // moduleName 相关 | ||||||
|         String simpleModuleName = codegenBuilder.getSimpleModuleName(table.getModuleName()); |         String simpleModuleName = codegenBuilder.getSimpleModuleName(table.getModuleName()); | ||||||
|         bindingMap.put("simpleModuleName", simpleModuleName); // 将 system 转成 sys |         bindingMap.put("simpleModuleName", simpleModuleName); // 将 system 转成 sys | ||||||
|         // className 相关 |         // className 相关 | ||||||
| @ -84,6 +87,7 @@ public class ToolCodegenEngine { | |||||||
|         bindingMap.put("simpleClassName", simpleClassName); |         bindingMap.put("simpleClassName", simpleClassName); | ||||||
|         bindingMap.put("simpleClassName_underlineCase", toUnderlineCase(simpleClassName)); // 将 DictType 转换成 dict_type |         bindingMap.put("simpleClassName_underlineCase", toUnderlineCase(simpleClassName)); // 将 DictType 转换成 dict_type | ||||||
|         bindingMap.put("classNameVar", lowerFirst(simpleClassName)); // 将 DictType 转换成 dictType,用于变量 |         bindingMap.put("classNameVar", lowerFirst(simpleClassName)); // 将 DictType 转换成 dictType,用于变量 | ||||||
|  |         bindingMap.put("simpleClassName_strikeCase", toSymbolCase(simpleClassName, '-')); // 将 DictType 转换成 dict-type | ||||||
|         // 执行生成 |         // 执行生成 | ||||||
| //        String result = templateEngine.getTemplate("codegen/dal/do.vm").render(bindingMap); | //        String result = templateEngine.getTemplate("codegen/dal/do.vm").render(bindingMap); | ||||||
| //        String result = templateEngine.getTemplate("codegen/dal/mapper.vm").render(bindingMap); | //        String result = templateEngine.getTemplate("codegen/dal/mapper.vm").render(bindingMap); | ||||||
| @ -95,7 +99,8 @@ public class ToolCodegenEngine { | |||||||
| //        String result = templateEngine.getTemplate("codegen/convert/convert.vm").render(bindingMap); | //        String result = templateEngine.getTemplate("codegen/convert/convert.vm").render(bindingMap); | ||||||
| //        String result = templateEngine.getTemplate("codegen/enums/errorcode.vm").render(bindingMap); | //        String result = templateEngine.getTemplate("codegen/enums/errorcode.vm").render(bindingMap); | ||||||
| //        String result = templateEngine.getTemplate("codegen/service/service.vm").render(bindingMap); | //        String result = templateEngine.getTemplate("codegen/service/service.vm").render(bindingMap); | ||||||
|         String result = templateEngine.getTemplate("codegen/service/serviceImpl.vm").render(bindingMap); | //        String result = templateEngine.getTemplate("codegen/service/serviceImpl.vm").render(bindingMap); | ||||||
|  |         String result = templateEngine.getTemplate("codegen/controller/controller.vm").render(bindingMap); | ||||||
|         System.out.println(result); |         System.out.println(result); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | |||||||
| @ -1,63 +1,76 @@ | |||||||
|  | package ${basePackage}.${table.moduleName}.controller.${table.businessName}; | ||||||
|  |  | ||||||
| import org.springframework.web.bind.annotation.*; | import org.springframework.web.bind.annotation.*; | ||||||
| import org.springframework.beans.factory.annotation.Autowired; | import javax.annotation.Resource; | ||||||
|  | import org.springframework.validation.annotation.Validated; | ||||||
|  |  | ||||||
| import io.swagger.annotations.*; | import io.swagger.annotations.*; | ||||||
|  |  | ||||||
| import javax.validation.constraints.*; | import javax.validation.constraints.*; | ||||||
| import javax.validation.*; | import javax.validation.*; | ||||||
| import java.util.*; | import java.util.*; | ||||||
|  |  | ||||||
| import org.springframework.validation.annotation.Validated; | import ${PageResultClassName}; | ||||||
|  | import ${CommonResultClassName}; | ||||||
|  | import static ${CommonResultClassName}.success; | ||||||
|  |  | ||||||
| /** | import ${basePackage}.${table.moduleName}.controller.${table.businessName}.vo.*; | ||||||
|  * ${class.description} Controller | import ${basePackage}.${table.moduleName}.dal.mysql.dataobject.${table.businessName}.${table.className}DO; | ||||||
|  */ | import ${basePackage}.${table.moduleName}.convert.${table.businessName}.${table.className}Convert; | ||||||
|  | import ${basePackage}.${table.moduleName}.service.${table.businessName}.${table.className}Service; | ||||||
|  |  | ||||||
|  | @Api(tags = "${table.classComment}") | ||||||
| @RestController | @RestController | ||||||
| @RequestMapping("/${class.classNameLowerUnderscore}") | ##二级的 businessName 暂时不算在 HTTP 路径上,可以根据需要写 | ||||||
| @Api(tags = "${class.description}") | @RequestMapping("/${table.moduleName}/${simpleClassName_strikeCase}") | ||||||
| @Validated | @Validated | ||||||
| public class ${class.className}Controller { | public class ${table.className}Controller { | ||||||
|  |  | ||||||
|     @Autowired |     @Resource | ||||||
|     private ${class.className}Service ${class.classNameVar}Service; |     private ${table.className}Service ${classNameVar}Service; | ||||||
|  |  | ||||||
|  |     @ApiOperation("创建${table.classComment}") | ||||||
|     @PostMapping("/create") |     @PostMapping("/create") | ||||||
|     @ApiOperation("创建${class.description}") |     public CommonResult<${primaryColumn.javaType}> create${simpleClassName}(@Valid ${table.className}CreateReqVO createReqVO) { | ||||||
|     public CommonResult<Integer> create${class.className}(@Valid ${class.className}CreateReqVO createVO) { |         return success(${classNameVar}Service.create${simpleClassName}(createReqVO)); | ||||||
|         return success(${class.classNameVar}Service.create${class.className}(createVO)); |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @PostMapping("/update") |     @ApiOperation("更新${table.classComment}") | ||||||
|     @ApiOperation("更新${class.description}") |     @PutMapping("/update") | ||||||
|     public CommonResult<Boolean> update${class.className}(@Valid ${class.className}UpdateReqVO updateVO) { |     public CommonResult<Boolean> update${simpleClassName}(@Valid ${table.className}UpdateReqVO updateReqVO) { | ||||||
|         ${class.classNameVar}Service.update${class.className}(updateVO); |         ${classNameVar}Service.update${simpleClassName}(updateReqVO); | ||||||
|         return success(true); |         return success(true); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @PostMapping("/delete") | 	@ApiOperation("删除${table.classComment}") | ||||||
|     @ApiOperation("删除${class.description}") | 	@DeleteMapping("/delete") | ||||||
|     @ApiImplicitParam(name = "${class.classNameVar}Id", value = "${class.description}编号", required = true) |     @ApiImplicitParam(name = "id", value = "编号", required = true) | ||||||
|     public CommonResult<Boolean> delete${class.className}(@RequestParam("${class.classNameVar}Id") Integer ${class.classNameVar}Id) { |     public CommonResult<Boolean> delete${simpleClassName}(@RequestParam("id") ${primaryColumn.javaType} id) { | ||||||
|         ${class.classNameVar}Service.delete${class.className}(${class.classNameVar}Id); |         ${classNameVar}Service.delete${simpleClassName}(id); | ||||||
|         return success(true); |         return success(true); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @GetMapping("/get") |     @GetMapping("/get") | ||||||
|     @ApiOperation("获得${class.description}") |     @ApiOperation("获得${table.classComment}") | ||||||
|     @ApiImplicitParam(name = "${class.classNameVar}Id", value = "${class.description}编号", required = true) |     @ApiImplicitParam(name = "id", value = "编号", required = true) | ||||||
|     public CommonResult<${class.className}RespVO> get${class.className}(@RequestParam("${class.classNameVar}Id") Integer ${class.classNameVar}Id) { |     public CommonResult<${table.className}RespVO> get${simpleClassName}(@RequestParam("id") ${primaryColumn.javaType} id) { | ||||||
|         return success(${class.classNameVar}Service.get${class.className}(${class.classNameVar}Id)); |         ${table.className}DO ${classNameVar} = ${classNameVar}Service.get${simpleClassName}(id); | ||||||
|  |         return success(${table.className}Convert.INSTANCE.convert(${classNameVar})); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @GetMapping("/list") |     @GetMapping("/list") | ||||||
|     @ApiOperation("获得${class.description}列表") |     @ApiOperation("获得${table.classComment}列表") | ||||||
|     @ApiImplicitParam(name = "${class.classNameVar}Ids", value = "${class.description}编号列表", required = true) |     @ApiImplicitParam(name = "ids", value = "编号列表", required = true) | ||||||
|     public CommonResult<List<${class.className}RespVO>> list${class.className}s(@RequestParam("${class.classNameVar}Ids") List<Integer> ${class.classNameVar}Ids) { |     public CommonResult<List<${table.className}RespVO>> get${simpleClassName}List(@RequestParam("ids") Collection<${primaryColumn.javaType}> ids) { | ||||||
|         return success(${class.classNameVar}Service.list${class.className}s(${class.classNameVar}Ids)); |         List<${table.className}DO> list = ${classNameVar}Service.get${simpleClassName}List(ids); | ||||||
|  |         return success(${table.className}Convert.INSTANCE.convertList(list)); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @ApiOperation("获得${table.classComment}分页") | ||||||
|     @GetMapping("/page") |     @GetMapping("/page") | ||||||
|     @ApiOperation("获得${class.description}分页") |     public CommonResult<PageResult<${table.className}RespVO>> get${simpleClassName}Page(@Valid ${table.className}PageReqVO pageVO) { | ||||||
|     public CommonResult<PageResult<${class.className}RespVO>> page${class.className}(${class.className}PageReqVO pageVO) { |         PageResult<${table.className}DO> pageResult = ${classNameVar}Service.get${simpleClassName}Page(pageVO); | ||||||
|         return success(${class.classNameVar}Service.page${class.className}(pageVO)); |         return success(${table.className}Convert.INSTANCE.convertPage(pageResult)); | ||||||
|     } |     } | ||||||
|  |  | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,5 +1,9 @@ | |||||||
| package ${basePackage}.${table.moduleName}.convert.${table.businessName}; | package ${basePackage}.${table.moduleName}.convert.${table.businessName}; | ||||||
|  |  | ||||||
|  | import java.util.*; | ||||||
|  |  | ||||||
|  | import ${PageResultClassName}; | ||||||
|  |  | ||||||
| import org.mapstruct.Mapper; | import org.mapstruct.Mapper; | ||||||
| import org.mapstruct.factory.Mappers; | import org.mapstruct.factory.Mappers; | ||||||
| import ${basePackage}.${table.moduleName}.controller.${table.businessName}.vo.*; | import ${basePackage}.${table.moduleName}.controller.${table.businessName}.vo.*; | ||||||
| @ -19,4 +23,10 @@ public interface ${table.className}Convert { | |||||||
|  |  | ||||||
|     ${table.className}DO convert(${table.className}UpdateReqVO bean); |     ${table.className}DO convert(${table.className}UpdateReqVO bean); | ||||||
|  |  | ||||||
|  |     ${table.className}RespVO convert(${table.className}DO bean); | ||||||
|  |  | ||||||
|  |     List<${table.className}RespVO> convertList(List<${table.className}DO> list); | ||||||
|  |  | ||||||
|  | 	PageResult<${table.className}RespVO> convertPage(PageResult<${table.className}DO> page); | ||||||
|  |  | ||||||
| } | } | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 YunaiV
					YunaiV