Merge pull request '1.uniform response status code for user component' (#7) from unifiy_response into main

Reviewed-on: https://go.indie.cn/git/queyue-backend/luoo_parent/pulls/7
main
foo 11 months ago
commit 388efaf277

@ -0,0 +1,11 @@
package api;
/**
* API
* Created by Gary on 2024/1/12.
*/
public interface IErrorCode {
int getCode();
String getMessage();
}

@ -0,0 +1,31 @@
package api;
import java.util.List;
public class PageResult<T> {
private Long total;
private List<T> rows;
public PageResult(Long total, List<T> rows) {
super();
this.total = total;
this.rows = rows;
}
public Long getTotal() {
return total;
}
public void setTotal(Long total) {
this.total = total;
}
public List<T> getRows() {
return rows;
}
public void setRows(List<T> rows) {
this.rows = rows;
}
}

@ -0,0 +1,123 @@
package api;
public class Result<T> {
private long code;
private String message;
private T data;
protected Result() {
}
protected Result(long code, String message, T data) {
this.code = code;
this.message = message;
this.data = data;
}
public static Result<Void> success() {
return new Result<Void>(StatusCode.SUCCESS.getCode(), StatusCode.SUCCESS.getMessage(), null);
}
/**
*
*
* @param data
*/
public static <T> Result<T> success(T data) {
return new Result<T>(StatusCode.SUCCESS.getCode(), StatusCode.SUCCESS.getMessage(), data);
}
/**
*
*
* @param data
* @param message
*/
public static <T> Result<T> success(T data, String message) {
return new Result<T>(StatusCode.SUCCESS.getCode(), message, data);
}
/**
*
* @param errorCode
*/
public static <T> Result<T> failed(IErrorCode errorCode) {
return new Result<T>(errorCode.getCode(), errorCode.getMessage(), null);
}
/**
*
* @param errorCode
* @param message
*/
public static <T> Result<T> failed(IErrorCode errorCode,String message) {
return new Result<T>(errorCode.getCode(), message, null);
}
/**
*
* @param message
*/
public static <T> Result<T> failed(String message) {
return new Result<T>(StatusCode.FAILED.getCode(), message, null);
}
/**
*
*/
public static <T> Result<T> failed() {
return failed(StatusCode.FAILED);
}
/**
*
*/
public static <T> Result<T> validateFailed() {
return failed(StatusCode.VALIDATE_FAILED);
}
/**
*
* @param message
*/
public static <T> Result<T> validateFailed(String message) {
return new Result<T>(StatusCode.VALIDATE_FAILED.getCode(), message, null);
}
/**
*
*/
public static <T> Result<T> unauthorized(T data) {
return new Result<T>(StatusCode.UNAUTHORIZED.getCode(), StatusCode.UNAUTHORIZED.getMessage(), data);
}
/**
*
*/
public static <T> Result<T> forbidden(T data) {
return new Result<T>(StatusCode.FORBIDDEN.getCode(), StatusCode.FORBIDDEN.getMessage(), data);
}
public long getCode() {
return code;
}
public void setCode(long code) {
this.code = code;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
}

@ -0,0 +1,43 @@
package api;
public enum StatusCode implements IErrorCode {
//通用状态码
SUCCESS(200, "操作成功"),
FAILED(500, "操作失败"),
VALIDATE_FAILED(404, "参数检验失败"),
UNAUTHORIZED(401, "暂未登录或token已经过期"),
FORBIDDEN(403, "没有相关权限"),
//user 模块错误码以10XXX不足5位补0;
USER_COMMON_FAILED(10000, "用户模块失败"),
USER_VERIFICATION_CODE_EXPIRED(10001, "验证码过期,请重新获取"),
USER_VERIFICATION_CODE_MISMATCH(10002, "验证码校验失败,请输入正确的验证码"),
USER_NAME_OR_PASSWORD_FAILED(10003, "用户名或密码错误"),
// music 模块错误码以20XXX不足5位补0;
// comment 模块错误码以30XXX不足5位补0;
// friend 模块错误码以40XXX不足5位补0;
// tag 模块错误码以50XXX不足5位补0;
// music 模块错误码以60XXX不足5位补0;
// manage 模块错误码以70XXX不足5位补0;
MANAGE_COMMON_FAILED(70000, "管理模块失败");
private int code;
private String message;
private StatusCode(int code, String message) {
this.code = code;
this.message = message;
}
public int getCode() {
return code;
}
public String getMessage() {
return message;
}
}

@ -3,6 +3,8 @@ package swagger;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.core.annotation.Order; import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import api.StatusCode;
import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.builders.RequestHandlerSelectors;
@ -12,6 +14,7 @@ import springfox.documentation.service.*;
import springfox.documentation.spi.DocumentationType; import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.spring.web.plugins.Docket;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
public abstract class BaseSwaggerConfig { public abstract class BaseSwaggerConfig {
@ -19,12 +22,16 @@ public abstract class BaseSwaggerConfig {
@Bean @Bean
@Order(value = 1) @Order(value = 1)
public Docket createRestApi() { public Docket createRestApi() {
List<ResponseMessage> responseMessageList =new ArrayList<>();
responseMessageList.add(new ResponseMessageBuilder().code(200).message("成功").responseModel(new ModelRef("成功")).build()); //添加全局响应状态码
responseMessageList.add(new ResponseMessageBuilder().code(20001).message("失败").responseModel(new ModelRef("失败")).build()); List<ResponseMessage> responseMessageList = new ArrayList<>();
responseMessageList.add(new ResponseMessageBuilder().code(20002).message("用户名或密码错误").responseModel(new ModelRef("用户名或密码错误")).build()); Arrays.stream(StatusCode.values()).forEach(errorEnums -> {
responseMessageList.add(new ResponseMessageBuilder().code(20003).message("无权访问").responseModel(new ModelRef("无权访问")).build()); responseMessageList.add(
responseMessageList.add(new ResponseMessageBuilder().code(20009).message("重复提交").responseModel(new ModelRef("重复提交")).build()); new ResponseMessageBuilder().code(errorEnums.getCode()).message(errorEnums.getMessage()).responseModel(
new ModelRef(errorEnums.getMessage())).build()
);
});
SwaggerProperties swaggerProperties = swaggerProperties(); SwaggerProperties swaggerProperties = swaggerProperties();
return new Docket(DocumentationType.SWAGGER_2) return new Docket(DocumentationType.SWAGGER_2)
.globalResponseMessage(RequestMethod.GET, responseMessageList) .globalResponseMessage(RequestMethod.GET, responseMessageList)

@ -3,23 +3,16 @@ import java.util.*;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.luoo.user.pojo.Admin; import com.luoo.user.pojo.Admin;
import com.luoo.user.service.AdminService; import com.luoo.user.service.AdminService;
import entity.PageResult; import api.PageResult;
import entity.Result; import api.Result;
import entity.StatusCode; import api.StatusCode;
import util.JwtUtil; import util.JwtUtil;
/** /**
* *
* @author Administrator * @author Administrator
@ -37,37 +30,36 @@ public class AdminController {
private JwtUtil jwtUtil; private JwtUtil jwtUtil;
@RequestMapping(value = "/info",method = RequestMethod.GET) @GetMapping("/info")
public Result info(){ public Result<Map> info(){
Map map = new HashMap(); Map map = new HashMap();
map.put("name","admin"); map.put("name","admin");
List list =new ArrayList<>(); List list =new ArrayList<>();
list.add("admin"); list.add("admin");
map.put("roles",list); map.put("roles",list);
map.put("avatar",""); map.put("avatar","");
return new Result(true,StatusCode.OK,"查询成功",map); return Result.success(map);
} }
@RequestMapping(value = "/logout",method = RequestMethod.POST) @PostMapping("/logout")
public Result logout(){ public Result<Void> logout(){
return Result.success();
return new Result(true,StatusCode.OK,"登出成功");
} }
@RequestMapping(value = "/login",method = RequestMethod.POST) @PostMapping("/login")
public Result login(@RequestBody Map<String,String> loginMap) { public Result login(@RequestBody Map<String,String> loginMap) {
Admin admin = adminService.findByLoginnameAndPassword(loginMap.get("username"),loginMap.get("password")); Admin admin = adminService.findByLoginnameAndPassword(loginMap.get("username"),loginMap.get("password"));
if (admin !=null) { if (admin !=null) {
//生成token //生成token
String token = jwtUtil.createJWT(admin.getId(),admin.getLoginname(),"admin"); String token = jwtUtil.createJWT(admin.getId(),admin.getLoginname(),"admin");
Map<String, Object> map = new HashMap(); Map<String, Object> map = new HashMap<>();
map.put("token",token); map.put("token",token);
map.put("roles","admin"); map.put("roles","admin");
map.put("name",admin.getLoginname()); map.put("name",admin.getLoginname());
return new Result(true,StatusCode.OK,"登录成功",map); return Result.success(map);
} else { } else {
return new Result(false,StatusCode.LOGINERROR,"用户名或密码错误"); return Result.failed(StatusCode.USER_NAME_OR_PASSWORD_FAILED);
} }
} }
@ -75,9 +67,9 @@ public class AdminController {
* *
* @return * @return
*/ */
@RequestMapping(method= RequestMethod.GET) @GetMapping("/list")
public Result findAll(){ public Result<List<Admin>> findAll(){
return new Result(true,StatusCode.OK,"查询成功",adminService.findAll()); return Result.success(adminService.findAll());
} }
/** /**
@ -85,9 +77,9 @@ public class AdminController {
* @param id ID * @param id ID
* @return * @return
*/ */
@RequestMapping(value="/{id}",method= RequestMethod.GET) @GetMapping("/{id}")
public Result findById(@PathVariable String id){ public Result<Admin> findById(@PathVariable String id){
return new Result(true,StatusCode.OK,"查询成功",adminService.findById(id)); return Result.success(adminService.findById(id));
} }
@ -98,10 +90,10 @@ public class AdminController {
* @param size * @param size
* @return * @return
*/ */
@RequestMapping(value="/search/{page}/{size}",method=RequestMethod.POST) @PostMapping("/search/{page}/{size}")
public Result findSearch(@RequestBody Map searchMap , @PathVariable int page, @PathVariable int size){ public Result<PageResult<Admin>> findSearch(@RequestBody Map searchMap , @PathVariable int page, @PathVariable int size){
Page<Admin> pageList = adminService.findSearch(searchMap, page, size); Page<Admin> pageList = adminService.findSearch(searchMap, page, size);
return new Result(true,StatusCode.OK,"查询成功", new PageResult<Admin>(pageList.getTotalElements(), pageList.getContent()) ); return Result.success(new PageResult<Admin>(pageList.getTotalElements(), pageList.getContent()) );
} }
/** /**
@ -109,41 +101,40 @@ public class AdminController {
* @param searchMap * @param searchMap
* @return * @return
*/ */
@RequestMapping(value="/search",method = RequestMethod.POST) @PostMapping("/search")
public Result findSearch( @RequestBody Map searchMap){ public Result<List<Admin>> findSearch( @RequestBody Map searchMap){
return new Result(true,StatusCode.OK,"查询成功",adminService.findSearch(searchMap)); return Result.success(adminService.findSearch(searchMap));
} }
/** /**
* *
* @param admin * @param admin
*/ */
@RequestMapping(method=RequestMethod.POST) @PostMapping
public Result add(@RequestBody Admin admin ){ public Result<Void> add(@RequestBody Admin admin ){
adminService.add(admin); adminService.add(admin);
return new Result(true,StatusCode.OK,"增加成功"); return Result.success();
} }
/** /**
* *
* @param admin * @param admin
*/ */
@RequestMapping(value="/{id}",method= RequestMethod.PUT) @PutMapping("/{id}")
public Result update(@RequestBody Admin admin, @PathVariable String id ){ public Result<Void> update(@RequestBody Admin admin, @PathVariable String id ){
admin.setId(id); admin.setId(id);
adminService.update(admin); adminService.update(admin);
return new Result(true,StatusCode.OK,"修改成功"); return Result.success();
} }
/** /**
* *
* @param id * @param id
*/ */
@RequestMapping(value="/{id}",method= RequestMethod.DELETE) @DeleteMapping("/{id}")
public Result delete(@PathVariable String id ){ public Result<Void> delete(@PathVariable String id ){
adminService.deleteById(id); adminService.deleteById(id);
return new Result(true,StatusCode.OK,"删除成功"); return Result.success();
} }
} }

@ -1,12 +1,9 @@
package com.luoo.user.controller; package com.luoo.user.controller;
import entity.Result; import api.Result;
import entity.StatusCode; import api.StatusCode;
import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/** /**
* *
*/ */
@ -15,8 +12,8 @@ public class BaseExceptionHandler {
@ExceptionHandler(value = Exception.class) @ExceptionHandler(value = Exception.class)
@ResponseBody @ResponseBody
public Result error(Exception e){ public Result<Void> error(Exception e){
e.printStackTrace(); e.printStackTrace();
return new Result(false, StatusCode.ERROR, "执行出错"); return Result.failed(StatusCode.USER_COMMON_FAILED);
} }
} }

@ -1,5 +1,5 @@
package com.luoo.user.controller; package com.luoo.user.controller;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -7,21 +7,14 @@ import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.luoo.user.dto.response.UserRespDTO; import com.luoo.user.dto.response.UserRespDTO;
import com.luoo.user.pojo.User; import com.luoo.user.pojo.User;
import com.luoo.user.service.UserService; import com.luoo.user.service.UserService;
import entity.PageResult; import api.PageResult;
import entity.Result; import api.Result;
import entity.ResultVO; import api.StatusCode;
import entity.StatusCode;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import util.IdWorker; import util.IdWorker;
@ -29,13 +22,14 @@ import util.JwtUtil;
/** /**
* *
*
* @author Administrator * @author Administrator
* *
*/ */
@RestController @RestController
@CrossOrigin @CrossOrigin
@RequestMapping("/user") @RequestMapping("/user")
@Api(tags="UserController") @Api(tags = "UserController")
public class UserController { public class UserController {
@Autowired @Autowired
@ -52,154 +46,162 @@ public class UserController {
/** /**
* *
*
* @param * @param
* @return * @return
*/ */
@RequestMapping(value = "/{userid}/{friendid}/{x}",method = RequestMethod.PUT) @PutMapping("/{userid}/{friendid}/{x}")
public void updatefanscountandfollowcount(@PathVariable String userid,@PathVariable String friendid,@PathVariable int x){ public void updatefanscountandfollowcount(@PathVariable String userid, @PathVariable String friendid,
userService.updatefanscountandfollowcount(x,userid,friendid); @PathVariable int x) {
userService.updatefanscountandfollowcount(x, userid, friendid);
} }
@RequestMapping(value = "/login",method = RequestMethod.POST) @PostMapping("/login")
public Result login(@RequestBody User user){ @Deprecated
public Result login(@RequestBody User user) {
user = userService.login(user.getMobile(),user.getPassword()); user = userService.login(user.getMobile(), user.getPassword());
if (user == null) { if (user == null) {
return new Result(false,StatusCode.LOGINERROR,"登录失败"); // before there is a 'login error, intend to remvoe this interface'
return Result.failed();
} }
String token = jwtUtil.createJWT(user.getId(),user.getMobile(),"user"); String token = jwtUtil.createJWT(user.getId(), user.getMobile(), "user");
Map map = new HashMap(); Map map = new HashMap();
map.put("userid",user.getId()); map.put("userid", user.getId());
map.put("mobile",user.getMobile()); map.put("mobile", user.getMobile());
map.put("token",token); map.put("token", token);
map.put("name",user.getLoginname()); map.put("name", user.getLoginname());
map.put("avatar",user.getAvatar()); map.put("avatar", user.getAvatar());
map.put("roles","user"); map.put("roles", "user");
return new Result(true,StatusCode.OK,"登录成功",map); return Result.success(map);
} }
@ApiOperation(value="2.登录/注册后返回token") @ApiOperation(value = "2.登录/注册后返回token")
@RequestMapping(value = "/appLogin/{mobile}/{checkcode}",method = RequestMethod.POST) @PostMapping("/appLogin/{mobile}/{checkcode}")
public ResultVO appLogin(@PathVariable String mobile,@PathVariable String checkcode){ public Result appLogin(@PathVariable String mobile, @PathVariable String checkcode) {
// 得到缓存中的验证码 // 得到缓存中的验证码
String checkcodeRedis = (String)redisTemplate.opsForValue().get("checkcode_"+mobile); String checkcodeRedis = (String) redisTemplate.opsForValue().get("checkcode_" + mobile);
if (null==checkcodeRedis||checkcodeRedis.isEmpty()){ if (null == checkcodeRedis || checkcodeRedis.isEmpty()) {
return new ResultVO(false,StatusCode.ERROR,"请先获取手机验证码"); return Result.failed(StatusCode.USER_VERIFICATION_CODE_EXPIRED);
} }
if (!checkcodeRedis.equals(checkcode)) { if (!checkcodeRedis.equals(checkcode)) {
return new ResultVO(false,StatusCode.ERROR,"请输入正确的验证码"); return Result.failed(StatusCode.USER_VERIFICATION_CODE_MISMATCH);
} }
UserRespDTO userVO=userService.loginOrRegister(mobile); UserRespDTO userRespDTO = userService.loginOrRegister(mobile);
return ResultVO.success(userVO); return Result.success(userRespDTO);
} }
@ApiOperation(value="3.游客登录返回token",notes="token中的subject和roles均为tourist") @ApiOperation(value = "3.游客登录返回token", notes = "token中的subject和roles均为tourist")
@RequestMapping(value = "/touristLogin",method = RequestMethod.GET) @GetMapping("/touristLogin")
public ResultVO<UserRespDTO> touristLogin(){ public Result<UserRespDTO> touristLogin() {
UserRespDTO userVO=userService.touristLogin(); UserRespDTO userRespDTO = userService.touristLogin();
return ResultVO.success(userVO); return Result.success(userRespDTO);
} }
/** /**
* *
*/ */
@ApiOperation(value="1.发送短信验证码") @ApiOperation(value = "1.发送短信验证码")
@RequestMapping(value = "/sendsms/{mobile}",method = RequestMethod.POST) @PostMapping("/sendsms/{mobile}")
public ResultVO<Void> sendSms(@PathVariable String mobile) { public Result<Void> sendSms(@PathVariable String mobile) {
userService.sendSms(mobile); userService.sendSms(mobile);
return ResultVO.success("发送成功"); return Result.success();
} }
@RequestMapping(value = "/register/{code}",method = RequestMethod.POST) @PostMapping("/register/{code}")
public Result regist(@PathVariable String code,@RequestBody User user){ public Result regist(@PathVariable String code, @RequestBody User user) {
// 得到缓存中的验证码 // 得到缓存中的验证码
String checkcodeRedis = (String) redisTemplate.opsForValue().get("checkcode_"+user.getMobile()); String checkcodeRedis = (String) redisTemplate.opsForValue().get("checkcode_" + user.getMobile());
if (checkcodeRedis.isEmpty()){ if (checkcodeRedis.isEmpty()) {
//单独定义一个请重新获取验证码的code? 2024.01.12 by he,changgeng return Result.failed(StatusCode.USER_VERIFICATION_CODE_EXPIRED);
return new Result(false,StatusCode.ERROR,"请先获取手机验证码");
} }
if (!checkcodeRedis.equals(code)) { if (!checkcodeRedis.equals(code)) {
return new Result(false,StatusCode.ERROR,"请输入正确的验证码"); return Result.failed(StatusCode.USER_VERIFICATION_CODE_MISMATCH);
} }
userService.add(user); userService.add(user);
return new Result(true,StatusCode.OK,"注册成功"); return Result.success();
} }
/** /**
* *
*
* @return * @return
*/ */
@RequestMapping(method= RequestMethod.GET) @GetMapping
public Result findAll(){ public Result<List<User>> findAll() {
return new Result(true,StatusCode.OK,"查询成功",userService.findAll()); return Result.success(userService.findAll());
} }
/** /**
* ID * ID
*
* @param id ID * @param id ID
* @return * @return
*/ */
@RequestMapping(value="/{id}",method= RequestMethod.GET) @GetMapping("/{id}")
public Result findById(@PathVariable String id){ public Result<User> findById(@PathVariable String id) {
return new Result(true,StatusCode.OK,"查询成功",userService.findById(id)); return Result.success(userService.findById(id));
} }
/** /**
* + * +
*
* @param searchMap * @param searchMap
* @param page * @param page
* @param size * @param size
* @return * @return
*/ */
@RequestMapping(value="/search/{page}/{size}",method=RequestMethod.POST) @PostMapping("/search/{page}/{size}")
public Result findSearch(@RequestBody Map searchMap , @PathVariable int page, @PathVariable int size){ public Result<PageResult<User>> findSearch(@RequestBody Map searchMap, @PathVariable int page,
@PathVariable int size) {
Page<User> pageList = userService.findSearch(searchMap, page, size); Page<User> pageList = userService.findSearch(searchMap, page, size);
return new Result(true,StatusCode.OK,"查询成功", new PageResult<User>(pageList.getTotalElements(), pageList.getContent()) ); return Result.success(new PageResult<User>(pageList.getTotalElements(), pageList.getContent()));
} }
/** /**
* *
* @param searchMap *
* @return * @param searchMap
*/ * @return
@RequestMapping(value="/search",method = RequestMethod.POST) */
public Result findSearch( @RequestBody Map searchMap){ @PostMapping("/search")
return new Result(true,StatusCode.OK,"查询成功",userService.findSearch(searchMap)); public Result<List<User>> findSearch(@RequestBody Map searchMap) {
} return Result.success(userService.findSearch(searchMap));
}
/** /**
* *
*
* @param user * @param user
*/ */
@RequestMapping(method=RequestMethod.POST) @PostMapping
public Result add(@RequestBody User user ){ public Result<Void> add(@RequestBody User user) {
userService.add(user); userService.add(user);
return new Result(true,StatusCode.OK,"增加成功"); return Result.success();
} }
/** /**
* *
*
* @param user * @param user
*/ */
@RequestMapping(value="/{id}",method= RequestMethod.PUT) @PutMapping("/{id}")
public Result update(@RequestBody User user, @PathVariable String id ){ public Result<Void> update(@RequestBody User user, @PathVariable String id) {
user.setId(id); user.setId(id);
userService.update(user); userService.update(user);
return new Result(true,StatusCode.OK,"修改成功"); return Result.success();
} }
/** /**
* *
*
* @param id * @param id
*/ */
@RequestMapping(value="/{id}",method= RequestMethod.DELETE) @DeleteMapping("/{id}")
public Result delete(@PathVariable String id ){ public Result<Void> delete(@PathVariable String id) {
userService.deleteById(id); userService.deleteById(id);
return new Result(true,StatusCode.OK,"删除成功"); return Result.success();
} }
} }

Loading…
Cancel
Save