当前位置:网站首页>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 ");
}
}
边栏推荐
- Leetcode36 effective Sudoku
- Basic knowledge about memory chips
- Flink SQL(三) 连接到外部系统System和JDBC
- 天翼云Web应用防火墙(边缘云版)支持检测和拦截Apache Spark shell命令注入漏洞
- Redis的数据操作
- 低功耗多通道WFAS1431无线数据采集采发仪使用流程说明
- Code cloud, which officially supports the pages function, can deploy static pages
- Docker container MySQL enables binlog and scheduled backup
- 基于专利多属性融合的技术主题划分方法研究
- 1对1直播源码——1对1语音聊天源码
猜你喜欢

redis学习笔记

C language_ Structure pointer to access structure array

Solve the problem that JUnit of idea console cannot be input with scanner

基于双层主题模型的技术演化分析框架及其应用

MySQL-03 数据库操作

Tianyi cloud web application firewall (edge cloud version) supports the detection and interception of Apache spark shell command injection vulnerabilities

gdb常用命令

Pytoch learning notes (I) installation and use of common functions

~6. ccf 2021-09-1 数组推导

OA项目之会议排座和送审
随机推荐
MySQL-04 存储引擎和数据类型
Use the requests library to crawl web pages
Integer internal cache
[mathematical modeling] summary of common basic models
Videojs to canvas pause, play, switch video
注解和反射
Mobile dual finger scaling event (native), e.originalevent.touches
Leetcode question type priority queue (TOPK question)
IDEA(warning)No artifacts configured
Docker integrates the redis sentinel mode (one master, two slave and three sentinels)
C语言贪吃蛇-链表和指针练习
基于SPO语义三元组的疾病知识发现
My meeting of OA project
C language_ Combination of structure and array
.net6与英雄联盟邂逅之——根据官方LCU API制作游戏助手
基于专利多属性融合的技术主题划分方法研究
redis学习笔记
PHP uses sqlserver
.net6 encounter with the League of heroes - create a game assistant according to the official LCU API
Jzoffer (array; string; linked list)