当前位置:网站首页>What is restful style and its four specific implementation forms
What is restful style and its four specific implementation forms
2022-07-26 14:08:00 【Work hard, work hard, gzc】
One 、 background
When we developed the project before , We generally don't pay attention to the way in which the front end requests data from the back end , No matter what comes from your front end get Request or post request , That is, no matter what kind of request , We can all use @RequestMapping To deal with .
But if during the project development , The boss of the group stipulates that we must clearly deal with what kind of request our front-end is , yes get still post? yes put still delete? At this time, in fact, we will take restful Style to handle our front-end requests . meanwhile ,restful Can also be realized : The request path is the same ( For example, several request paths are "/user/test") Under the circumstances , We can ask for different methods , To match different back-end interfaces .
Two 、Restful Four request implementations of
restful There are four main implementations , That is, the four corresponding to us http Request mode :
(1)GET: get data
(2)POST: Add data
(3)PUT: Modifying data
(4)DELETE: Delete data
In the project ,GET,POST,PUT,DELETE The four request methods correspond to @GetMapping、PostMapping、@PutMapping、@DeleteMapping. Each annotation performs its own duties , You can only do your part , namely @GetMapping Can only handle get request , The other three requests cannot be processed .
1、GET That is, the database select operation : The request will send a request to the database to query data , To get information , It is only used to query the data , Not modify 、 Add or update data , It doesn't affect the content of the resource . No matter how many operations , The contents of the database will not change .
2、PUT That is, the database update operation : The request is to send data to the server , And change the message , It is used to modify the content of data , But the data will not be added , No matter how many times PUT operation , The database will not add or reduce data .
3、POST That is, the database insert operation : Request the same PUT The request is similar to , They all send data to the server , But the request will add data , Almost all of the current commit operations use POST Requested ( For example, user registration ).
4、DELETE That is, the database delete operation : A request is used to delete a resource .
POST Mainly Acting on a collection of resources (url), and PUT Acting primarily on a specific resource (url/xxx). Such as URL It can be determined on the client side , Then you can use PUT, Otherwise, use POST.
One URL Address , It is used to describe resources on a network , and HTTP Medium GET,POST,PUT,DELETE The four request methods correspond to the query of this resource in the database , increase , Change , Delete 4 Operations .
3、 ... and 、 Code instance
@RestController
@RequestMapping("/user/test")
public class JoblevelController {
@Autowired
private JoblevelService joblevelService;
@ApiOperation(value = " Get all titles ")
@GetMapping("/")
public List<Joblevel> getAllJobLevels(){
return joblevelService.list();
}
@ApiOperation(value = " Add title ")
@PostMapping("/")
public RespBean addJobLevel(@RequestBody Joblevel joblevel){
if(joblevelService.save(joblevel)){
return RespBean.success(" Title added successfully ");
}
return RespBean.error(" Failed to add professional title ");
}
@ApiOperation(value = " Modify the title ")
@PutMapping("/")
public RespBean updateJobLevel(@RequestBody Joblevel joblevel){
if(joblevelService.updateById(joblevel)){
return RespBean.success(" Title Modified successfully ");
}
return RespBean.error(" Failed to modify professional title ");
}
@ApiOperation(value = " Delete professional title ")
@DeleteMapping("/{id}")
public RespBean deleteJobLevelById(@PathVariable Integer id){
if(joblevelService.removeById(id)){
return RespBean.success(" The professional title was deleted successfully ");
}
return RespBean.error(" Failed to delete professional title ");
}
@ApiOperation(value = " Delete professional titles in batch ")
@DeleteMapping("/")
public RespBean deleteJobLevelByIds(Integer[] ids){
if(joblevelService.removeByIds(Arrays.asList(ids))){
return RespBean.success(" Batch deletion of professional titles succeeded ");
}
return RespBean.error(" Failed to delete professional titles in batch ");
}
}
边栏推荐
- Digital collections accelerate the breaking of the circle and help the industry find new opportunities
- Convert the array in JSON file to struct
- OLAP (business) - transaction analysis (query)
- 注解和反射
- C language_ Combination of structure and array
- Docker swarm cluster builds highly available MySQL active and standby
- PHP uses sqlserver
- JS get the current time, time and timestamp conversion
- UE4 智能指针和弱指针
- 「中高级试题」:MVCC实现原理是什么?
猜你喜欢

敏捷开发与DevOps的对比

Add a display horizontal line between idea methods

大脑带来的启发:深度神经网络优化中突触整合原理介绍

聚力打造四个“高地”,携手合作伙伴共铸国云!

DP sword finger offer II 100. sum of minimum paths in triangle

@千行百业,一起乘云而上!

大小端模式
![[dark horse morning post] many apps under bytek have been taken off the shelves; The leakage of deoxidizer in three squirrels caused pregnant women to eat by mistake; CBA claimed 406million yuan from](/img/f6/03e39799db36c33a58127359aa2794.png)
[dark horse morning post] many apps under bytek have been taken off the shelves; The leakage of deoxidizer in three squirrels caused pregnant women to eat by mistake; CBA claimed 406million yuan from

循环队列(c语言实现)

在检测分割中一些轻量级网络模型(自己学习的笔记分享)
随机推荐
JS, e.pagex, pagey modal box drag
Inspiration from brain: introduction to synaptic integration principle in deep neural network optimization
Tianyi cloud web application firewall (edge cloud version) supports the detection and interception of Apache spark shell command injection vulnerabilities
Completable future practical usage
二叉树的层序遍历(C语言实现)
OA项目之我的会议
Flink SQL (III) connects to the external system system and JDBC
Jzoffer (array; string; linked list)
android安全基础知识学习
Re bet overseas: Alibaba, jd.com and SF again fight for "internal power"
Mlx90640 infrared thermal imager temperature sensor module development notes (6)
基于标签嵌入注意力机制的多任务文本分类模型
A survey of machine learning based technology term recognition
C language_ Structure pointer to access structure array
gdb常用命令
~6. ccf 2021-09-1 数组推导
MySQL's practice of SQL analysis and optimization from the index principle
Meeting seating and submission for approval of OA project
ISCC2021 LOCKK题解
JS download files, filesaver.js export txt and Excel files