楼子湾

导航

 

get、post、delete、put请求

restful风格就是根据请求方式以及参数类型

1.新增: post

@RequestMapping(value = "/",method = RequestMethod.POST)

public MessageResponse save(@RequestBody UserVo userVo){

userService.save(userVo);

return MessageResponse.ok();

}

2.修改:put

@RequestMapping(value = "/",method = RequestMethod.PUT)

public MessageResponse update(@RequestBody UserVo userVo){

userService.update(userVo);

return MessageResponse.ok();

}

3.删除 delete: 这里的请求只需要传个数组就可以了

@RequestMapping(method = RequestMethod.DELETE)

public MessageResponse batchDeleteByIds(@RequestBody List<Integer> ids)

{

return MessageResponse.ok();

}

postman请求:

DELETE /dict HTTP/1.1

Host: localhost:8808

Content-Type: application/json

token: vvrgnD1wMm56n7667LxtaTI09rO96WMLKaPNajP7Yw0Er4mL3XOhv27cgNelgyoQAe/mgCUVGHGfA7JEclf0f//T0G6Fl6PnDzrSqH!q8hgtSju9kxDIWaJqB!Fv1rJ!

Cache-Control: no-cache

Postman-Token: f7051918-14fb-ec58-be63-7fc5c582407a

[29, 30, 31, 32, 33, 34]

4.查询 get

@RequestMapping(value = "/{id}",method = RequestMethod.GET)

public MessageResponse getById(@PathVariable("id") String id){

return MessageResponse.ok(userService.selectById(id));

}

请求样例: http://localhost:8808/info/e4254a341a01455f9d97effa1291c471 最后的字符串就是id

删除也可以用这种路径方式请求(url/{id})

 

2019-12-2416:09:53

 

posted on 2019-12-24 16:11  楼子湾  阅读(234)  评论(0编辑  收藏  举报