From 4c31f6196415b06935c69167208568e185e7e27c Mon Sep 17 00:00:00 2001 From: huangfeng Date: Wed, 20 Mar 2024 10:37:49 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E8=8F=9C=E5=8D=95?= =?UTF-8?q?=E8=B5=84=E6=BA=90=E7=9A=84=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ResourceController.java | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 xymanager_admin/src/main/java/com/shxy/xymanager_admin/controller/ResourceController.java diff --git a/xymanager_admin/src/main/java/com/shxy/xymanager_admin/controller/ResourceController.java b/xymanager_admin/src/main/java/com/shxy/xymanager_admin/controller/ResourceController.java new file mode 100644 index 0000000..2ad0e2e --- /dev/null +++ b/xymanager_admin/src/main/java/com/shxy/xymanager_admin/controller/ResourceController.java @@ -0,0 +1,61 @@ +package com.shxy.xymanager_admin.controller; + +import com.shxy.xymanager_common.base.BaseController; +import com.shxy.xymanager_common.base.ResponseReult; +import com.shxy.xymanager_common.entity.TbResource; +import com.shxy.xymanager_common.exception.ApiException; +import com.shxy.xymanager_service.service.ResourceService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import javax.validation.constraints.NotNull; +import java.util.List; + +@RestController +@Api(tags = {"资源相关接口"}) +@RequestMapping("resource") +@Slf4j +public class ResourceController extends BaseController { + + @Resource + ResourceService service; + + @GetMapping("listAll") + @ApiOperation("查询全部列表") + public ResponseReult> listAll() { + List result = service.listAll(); + return ResponseReult.success(result); + } + + @PostMapping("add") + @ApiOperation("新增") + public ResponseReult add(@Validated @RequestBody TbResource item) throws Exception { + service.add(item); + return ResponseReult.success("OK"); + } + + @PostMapping("update") + @ApiOperation("更新") + public ResponseReult update(@Validated @RequestBody TbResource item) throws Exception { + if (item.getId() == null) { + throw new ApiException("id不能为空!"); + } + service.update(item); + return ResponseReult.success("OK"); + } + + @PostMapping("delete") + @ApiOperation("删除") + public ResponseReult delete(@Validated @NotNull(message = "id不能为空!") Integer id) throws Exception { + if (id == null) { + throw new ApiException("id不能为空!"); + } + service.delete(id); + return ResponseReult.success("OK"); + } + +}