Spring Boot Series (5) - Restful CURD Notes

Billion, what is RESTful style

  RESTful not a technology, but a set of design specifications. In a RESTful style, to a network abstract entity into a "resource" with URI to represent "resources".

  1. Basic Specifications:

  (. 1) URI does not contain a verb, each represents a URI resource;

  (2) the client and server, transmitting manifestation of the resource;

  (3) by four client HTTP verbs (GET / POST / PUT / DELETE), server-side resources operate.

  2. Specific reference:

  Understand RESTful architecture , RESTful API design guidelines

 

A use, PUT and DELETE

  1. Description

  Based RESTful style, using an HTTP request to distinguish four CRUD operations on resources. GET request which means "get"; POST request indicates the "Add"; PUT request indicates "modify"; DELETE request indicates "delete."

  In the method attribute of the form tag html code, only GET and POST are two options when we need to use PUT and DELETE requests, you need to do extra work.

  Step 2. PUT / DELETE of

  (1) Set the POST method form tag property value, and add an additional text box in the form:

<input type="hidden" name="_method" value="DELETE" >

  (2) method on the Controller, the corresponding annotations added:

  Wherein @DeleteMapping (...) corresponding to @RequestMapping (value = "...", method = RequestMethod.DELETE)

1     @DeleteMapping("/emp/{id}")
2     public String deleteEmp(@PathVariable("id") Integer id){
3         employeeDao.delete(id);
4         return "redirect:/emps";
5     }

  (3) work process:

  Spring MVC has HiddenHttpMehodFilter class, is a filter (SpringBoot have a good default configuration). The filter can persist whether the POST request form, if and whether there _method parameters for the POST request, if the parameters change in accordance with the request method.

  

 

 

Two, redirect and forward the difference

  (1) from the address bar displays is: forward is internal server redirects the client browser's URL does not change; redirect occurs a status code that tells the server to re-request the URL, displayed the new URL.

  (2) Data Sharing: during orientation using the same forward a request, can be shared; not the redirect.

  (3) In essence: forward forwarding behavior on the server and redirect the client behavior.

  (4) http number of requests: forward only once, redirect twice.

 

Guess you like

Origin www.cnblogs.com/Drajun/p/12239167.html