controller.java.vm 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. package ${package.Controller};
  2. #foreach($field in ${table.fields})
  3. #if(${field.name.equals("name")})
  4. #set($hasName=true)
  5. #end
  6. #end
  7. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  8. import lombok.extern.slf4j.Slf4j;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.web.bind.annotation.RequestMapping;
  11. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  12. import com.baomidou.mybatisplus.core.metadata.IPage;
  13. #if(${restControllerStyle})
  14. import org.springframework.web.bind.annotation.RestController;
  15. #else
  16. import org.springframework.stereotype.Controller;
  17. #end
  18. #if(${superControllerClassPackage})
  19. import ${superControllerClassPackage};
  20. #end
  21. import ${package.Service}.${table.serviceName};
  22. import ${package.Entity}.${table.entityName};
  23. import ${cfg.resp};
  24. import org.springframework.web.bind.annotation.*;
  25. #if(${hasName})
  26. import ${cfg.pullDownModel};
  27. #end
  28. import ${cfg.basePkg}.utils.ConvertUtil;
  29. import ${cfg.basePkg}.utils.HttpKit;
  30. import ${cfg.basePkg}.exception.ErrorCode;
  31. import java.util.Date;
  32. import java.util.List;
  33. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  34. import org.springframework.http.MediaType;
  35. import org.springframework.web.multipart.MultipartFile;
  36. /**
  37. * $!{table.comment}
  38. *
  39. * @author ${author}
  40. * @since ${date}
  41. */
  42. #if(${restControllerStyle})
  43. @RestController
  44. #else
  45. @Controller
  46. #end
  47. ##@RequestMapping("#if(${package.ModuleName})/${package.ModuleName}#end/#if(${controllerMappingHyphenStyle})${controllerMappingHyphen}#else${table.entityPath}#end")
  48. @RequestMapping("${table.entityPath}")
  49. @Slf4j
  50. #if(${kotlin})
  51. class ${table.controllerName}#if(${superControllerClass}) : ${superControllerClass}()#end
  52. #else
  53. #if(${superControllerClass})
  54. public class ${table.controllerName} extends ${superControllerClass} {
  55. #else
  56. public class ${table.controllerName} {
  57. #end
  58. @Autowired
  59. private ${table.serviceName} ${table.entityPath}Service;
  60. /**
  61. * $!{table.comment}列表
  62. */
  63. @GetMapping("")
  64. public RestResponse<Page<${table.entityName}>> page(${table.entityName} ${table.entityPath}, Page page){
  65. Page<${table.entityName}> pages=${table.entityPath}Service.selectPage(page,${table.entityPath});
  66. return RestResponse.data(pages);
  67. }
  68. /**
  69. * $!{table.comment}详情
  70. */
  71. @GetMapping("/{id}")
  72. public RestResponse<${table.entityName}> detail(@PathVariable Long id){
  73. ${table.entityName} x${table.entityName} =${table.entityPath}Service.detail(id);
  74. return RestResponse.data(x${table.entityName});
  75. }
  76. /**
  77. * $!{table.comment}新增
  78. */
  79. @PostMapping("")
  80. public RestResponse<Boolean> save(@RequestBody ${table.entityName} ${table.entityPath}) {
  81. Boolean ret = ${table.entityPath}Service.add(${table.entityPath});
  82. return RestResponse.data(ret);
  83. }
  84. /**
  85. * $!{table.comment}更新
  86. */
  87. @PutMapping("")
  88. public RestResponse<Boolean> update(@RequestBody ${table.entityName} ${table.entityPath}) {
  89. Boolean ret = ${table.entityPath}Service.update(${table.entityPath});
  90. return RestResponse.data(ret);
  91. }
  92. /**
  93. * $!{table.comment}删除
  94. */
  95. @DeleteMapping("/{id}")
  96. public RestResponse<Boolean> delete(@PathVariable Long id) {
  97. Boolean ret = ${table.entityPath}Service.delete(id);
  98. return RestResponse.data(ret);
  99. }
  100. #if(${hasName})
  101. /**
  102. * $!{table.comment}下拉列表
  103. */
  104. @GetMapping("/simpleAll")
  105. public RestResponse<List<PullDownModel>> simpleAll(){
  106. LambdaQueryWrapper<${table.entityName}> lambdaQueryWrapper = new LambdaQueryWrapper<${table.entityName}>()
  107. .select(${table.entityName}::getId,${table.entityName}::getName)
  108. .eq(${table.entityName}::getDeleted,false);
  109. List<${table.entityName}> list= ${table.entityPath}Service.list(lambdaQueryWrapper);
  110. List<PullDownModel> ret=ConvertUtil.copyList(list, PullDownModel.class);
  111. return RestResponse.data(ret);
  112. }
  113. #end
  114. }
  115. #end