controller1.java.ftl 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package ${package.Controller};
  2. import org.springframework.web.bind.annotation.RequestMapping;
  3. import ${package.Entity}.${entity};
  4. import ${package.Service}.${table.serviceName};
  5. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  6. import org.springframework.web.bind.annotation.*;
  7. import javax.annotation.Resource;
  8. import java.util.List;
  9. <#if superControllerClassPackage??>
  10. import ${superControllerClassPackage};
  11. </#if>
  12. /**
  13. * <p>
  14. * ${table.comment!} 前端控制器
  15. * </p>
  16. *
  17. * @author ${author}
  18. * @since ${date}
  19. */
  20. <#if restControllerStyle>
  21. @RestController
  22. <#else>
  23. @Controller
  24. </#if>
  25. @RequestMapping("<#if package.ModuleName?? && package.ModuleName != "">/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
  26. <#if kotlin>
  27. class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
  28. <#else>
  29. <#if superControllerClass??>
  30. public class ${table.controllerName} extends ${superControllerClass} {
  31. <#else>
  32. public class ${table.controllerName} {
  33. </#if>
  34. @Resource
  35. private ${table.serviceName} ${table.entityPath}Service;
  36. @PostMapping
  37. public Boolean save(@RequestBody ${entity} ${table.entityPath}) {
  38. return ${table.entityPath}Service.saveOrUpdate(${table.entityPath});
  39. }
  40. @DeleteMapping("/{id}")
  41. public Boolean delete(@PathVariable Integer id) {
  42. return ${table.entityPath}Service.removeById(id);
  43. }
  44. @GetMapping
  45. public List<${entity}> findAll() {
  46. return ${table.entityPath}Service.list();
  47. }
  48. @GetMapping("/{id}")
  49. public List<${entity}> findOne(@PathVariable Integer id) {
  50. return ${table.entityPath}Service.list();
  51. }
  52. @GetMapping("/page")
  53. public Page<${entity}> findPage(@RequestParam Integer pageNum,
  54. @RequestParam Integer pageSize) {
  55. return ${table.entityPath}Service.page(new Page<>(pageNum, pageSize));
  56. }
  57. }
  58. </#if>