controller.java.vm 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. package ${packageName}.controller;
  2. import java.util.List;
  3. import java.io.IOException;
  4. import javax.servlet.http.HttpServletResponse;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.web.bind.annotation.GetMapping;
  7. import org.springframework.web.bind.annotation.PostMapping;
  8. import org.springframework.web.bind.annotation.PutMapping;
  9. import org.springframework.web.bind.annotation.DeleteMapping;
  10. import org.springframework.web.bind.annotation.PathVariable;
  11. import org.springframework.web.bind.annotation.RequestBody;
  12. import org.springframework.web.bind.annotation.RequestMapping;
  13. import org.springframework.web.bind.annotation.RestController;
  14. import com.ruoyi.common.log.annotation.Log;
  15. import com.ruoyi.common.log.enums.BusinessType;
  16. import com.ruoyi.common.security.annotation.PreAuthorize;
  17. import io.swagger.annotations.Api;
  18. import io.swagger.annotations.ApiOperation;
  19. import io.swagger.annotations.ApiImplicitParam;
  20. import io.swagger.annotations.ApiImplicitParams;
  21. import ${packageName}.domain.${ClassName};
  22. import ${packageName}.service.I${ClassName}Service;
  23. import com.ruoyi.common.core.web.controller.BaseController;
  24. import com.ruoyi.common.core.web.domain.AjaxResult;
  25. import com.ruoyi.common.core.utils.poi.ExcelUtil;
  26. #if($table.crud || $table.sub)
  27. import com.ruoyi.common.core.web.page.TableDataInfo;
  28. #elseif($table.tree)
  29. #end
  30. /**
  31. * ${functionName}Controller
  32. *
  33. * @author ${author}
  34. * @date ${datetime}
  35. */
  36. @Api(description = "${functionName}")
  37. @RestController
  38. @RequestMapping("/${businessName}")
  39. public class ${ClassName}Controller extends BaseController
  40. {
  41. @Autowired
  42. private I${ClassName}Service ${className}Service;
  43. /**
  44. * 查询${functionName}列表
  45. */
  46. @ApiOperation(value = "查询${functionName}列表")
  47. @PreAuthorize(hasPermi = "${permissionPrefix}:list")
  48. @GetMapping("/list")
  49. #if($table.crud || $table.sub)
  50. public TableDataInfo list(${ClassName} ${className})
  51. {
  52. startPage();
  53. List<${ClassName}> list = ${className}Service.select${ClassName}List(${className});
  54. return getDataTable(list);
  55. }
  56. #elseif($table.tree)
  57. public AjaxResult list(${ClassName} ${className})
  58. {
  59. List<${ClassName}> list = ${className}Service.select${ClassName}List(${className});
  60. return AjaxResult.success(list);
  61. }
  62. #end
  63. /**
  64. * 导出${functionName}列表
  65. */
  66. @ApiOperation(value = "导出${functionName}列表")
  67. @PreAuthorize(hasPermi = "${permissionPrefix}:export")
  68. @Log(title = "${functionName}", businessType = BusinessType.EXPORT)
  69. @PostMapping("/export")
  70. public void export(HttpServletResponse response, ${ClassName} ${className}) throws IOException
  71. {
  72. List<${ClassName}> list = ${className}Service.select${ClassName}List(${className});
  73. ExcelUtil<${ClassName}> util = new ExcelUtil<${ClassName}>(${ClassName}.class);
  74. util.exportExcel(response, list, "${businessName}");
  75. }
  76. /**
  77. * 获取${functionName}详细信息
  78. */
  79. @ApiImplicitParam(name = "id",value = "主键")
  80. @ApiOperation(value = "获取${functionName}详细信息")
  81. @PreAuthorize(hasPermi = "${permissionPrefix}:query")
  82. @GetMapping(value = "/{${pkColumn.javaField}}")
  83. public AjaxResult getInfo(@PathVariable("${pkColumn.javaField}") ${pkColumn.javaType} ${pkColumn.javaField})
  84. {
  85. return AjaxResult.success(${className}Service.select${ClassName}ById(${pkColumn.javaField}));
  86. }
  87. /**
  88. * 新增${functionName}
  89. */
  90. @ApiOperation(value = "新增${functionName}")
  91. @PreAuthorize(hasPermi = "${permissionPrefix}:add")
  92. @Log(title = "${functionName}", businessType = BusinessType.INSERT)
  93. @PostMapping
  94. public AjaxResult add(@RequestBody ${ClassName} ${className})
  95. {
  96. return toAjax(${className}Service.insert${ClassName}(${className}));
  97. }
  98. /**
  99. * 修改${functionName}
  100. */
  101. @ApiOperation(value = "修改${functionName}")
  102. @PreAuthorize(hasPermi = "${permissionPrefix}:edit")
  103. @Log(title = "${functionName}", businessType = BusinessType.UPDATE)
  104. @PutMapping
  105. public AjaxResult edit(@RequestBody ${ClassName} ${className})
  106. {
  107. return toAjax(${className}Service.update${ClassName}(${className}));
  108. }
  109. /**
  110. * 删除${functionName}
  111. */
  112. @ApiOperation(value = "删除${functionName}")
  113. @PreAuthorize(hasPermi = "${permissionPrefix}:remove")
  114. @Log(title = "${functionName}", businessType = BusinessType.DELETE)
  115. @DeleteMapping("/{${pkColumn.javaField}s}")
  116. public AjaxResult remove(@PathVariable ${pkColumn.javaType}[] ${pkColumn.javaField}s)
  117. {
  118. return toAjax(${className}Service.delete${ClassName}ByIds(${pkColumn.javaField}s));
  119. }
  120. }