From 2f55cebbad3dea187a5f91d16ec80a9677dab699 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期三, 13 十一月 2024 11:16:53 +0800 Subject: [PATCH] 1 --- src/main/java/com/yssh/controller/LocationController.java | 75 +++++++++++++++++++++++++++++++++++++ 1 files changed, 75 insertions(+), 0 deletions(-) diff --git a/src/main/java/com/yssh/controller/LocationController.java b/src/main/java/com/yssh/controller/LocationController.java new file mode 100644 index 0000000..3d839ae --- /dev/null +++ b/src/main/java/com/yssh/controller/LocationController.java @@ -0,0 +1,75 @@ +package com.yssh.controller; + +import com.yssh.utils.CacheUtils; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; + +import java.util.List; + +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import com.yssh.entity.Location; +import com.yssh.service.LocationService; +import com.yssh.utils.Result; + +import javax.annotation.Resource; + +@Api(tags="鍘傚尯鐑偣鐐逛綅") +@RestController +@RequestMapping("/location") +@SuppressWarnings("rawtypes") +public class LocationController { + @Resource + private LocationService locationService; + + @ApiOperation(value = "鏉′欢鏌ヨ鐐逛綅鏁版嵁", notes = "鏍规嵁鍚嶇О鍙婂叾绫诲瀷鏌ヨ鐐逛綅璇︾粏淇℃伅") + @GetMapping("/query") + public Result query( + @RequestParam(value = "name", required = false) String name, + @RequestParam(value = "type", required = false) String type) { + List<Location> data = locationService.query(name, type); + return Result.OK(data); + } + + + @GetMapping("/list") + @ApiOperation(value = "鏌ヨ鎵�鏈夌偣浣嶆暟鎹�", notes = "鏌ヨ鎵�鏈夊巶鍖虹儹鐐圭偣浣嶆暟鎹�") + public Result list() { + //List<Location> list = locationService.getAll(); + String key = "locationService.getAll"; + List<Location> list = CacheUtils.getListByKey(key); + if (null == list) { + list = locationService.getAll(); + CacheUtils.putListByKey(key, list); + } + + return Result.OK(list); + } + + @ApiOperation(value = "鏂板鐐逛綅鏁版嵁", notes = "鏂板鐐逛綅璇︽儏鏁版嵁") + @PostMapping + public Result insertLocation(@RequestBody Location location) { + int i = locationService.insertLocation(location); + if (i == 0) { + return Result.error("鎻掑叆澶辫触"); + } + return Result.OK("鎻掑叆鎴愬姛"); + } + + @ApiOperation(value = "鍒犻櫎鐐逛綅鏁版嵁", notes = "鍒犻櫎鐐逛綅璇︽儏鏁版嵁") + @DeleteMapping("/{id}") + public Result deleteLocation(@PathVariable String id) { + int i = locationService.deleteLocation(id); + if (i == 0) { + return Result.error("鍒犻櫎澶辫触"); + } + return Result.OK("鍒犻櫎鎴愬姛"); + } +} -- Gitblit v1.9.3