Replies: 3 comments
-
补充一下哈~ @DeleteMapping("users/{uid}")
public void rmUser(@PathVariable int uid) {
userService.rmUser(uid);
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
修改前: 修改后: + @RequestMapping("/api/users") // 因为奖品属于某个用户
- @RequestMapping("/api")
public class PrizeController {
@Autowired
PrizeService prizeService;
/**
* 获取用户的获奖情况
*
* @param uid
* @return
*/
+ @GetMapping("/{uid}/prizes") // 列出某个用户的所有prize, 路径里传了uid, 但参数表中用 @RequestAttribute int uid,防止伪造请求
- @GetMapping("/prizeList")
public List<Prize> findByUserId(@RequestAttribute int uid) {
return prizeService.findByUser(uid);
}
/**
* 新增奖项
* @param uid
* @param prizeVO
*/
+ @PostMapping("/{uid}/prizes") // 新建某个用户的一个 prize
- @PutMapping("/prize")
public void addNewPrize(@RequestAttribute int uid, @RequestBody PrizeVO prizeVO){
prizeService.addNewPrize(uid,prizeVO);
}
/**
* 更新奖项信息
* @param prizeVO
*/
+ @PutMapping("/{uid}/prizes/{prizeId}") // 更新某个用户的某个指定prize的信息(提供该prize的全部信息),prizeId 其实没有用到,没关系~
- @PostMapping("/prize/update")
public void updatePrize(@RequestBody PrizeVO prizeVO){
prizeService.updatePrize(prizeVO);
}
/**
* 删除奖项
* @param prizeId
*/
+ @DeleteMapping("/{uid}/prizes/{prizeId}") // 删除某个用户的某个 prize
+ public void deletePrize(@PathVariable int prizeId){
- @DeleteMapping("/prize")
- public void deletePrize(@RequestBody int prizeId){
prizeService.deletePrize(prizeId);
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
可以仔细看一下嘿🍄: https://www.ruanyifeng.com/blog/2014/05/restful_api.html |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
@DirectorJerrian
dingtalk-app-server/src/main/java/com/softeng/dingtalk/controller/PrizeController.java
Lines 49 to 61 in e931b95
请看超人:RESTful API 设计指南
这里的
@PostMapping("/prize/update")
,@GetMapping("/prize/delete")
好像不符合Restful 风格,(当然因为历史原因,项目的有些代码也没遵循 Restful 风格),可以用:@PutMapping("/prize")
@DeleteMapping("/prize/{id}")
其他注解:
HTTP请求方法一览
Beta Was this translation helpful? Give feedback.
All reactions