BONUS: Additions to Rest style request handling (1)
Rest style requests: notes and details
-
Client is PostMan, you can directly send Put, delete, etc. request, do not set the Filter.
-
If yo ah SpringBoot supports Rest functionality for page expressions, the following details need to be noted:
- Rest style request core Filter: HiddenHttpMethodFilter, the form request will be intercepted by HiddenHttpMethodFilter, get the value of form_method, and then determine the PUT/DELETE/PATCH (the patch method is newly introduced, it's a complement to the Put method. Used for localized updates to known resources :)/q/1010000005685904
- If you want SpringBoot to support Rest for page forms, you need to enable the filter function in Otherwise, it will not work.
- Modify (under the resources class path) to enable the filter function.
spring. mvc. hiddenmethod. HiddenHttpMethodFilter. enabled: true # Enable rest for page forms, HiddenHttpMethodFilter is enabled, rest is supported.
Rest's core filter:
-
Current browsers only support post/get requests, so in order to get put/delete requests you need the provided HiddenHttpMethodFilter to convert them.
-
HiddenHttpMethodFilter : Browser form forms only support get and post requests, but delete, put and other methods are not supported.
spring adds a filter that converts these requests to standard http parties to support get, post, put and delete requests. -
HiddenHttpMethodFilter is able to convert the post request method, so we need to pay special attention to this point
-
This filter needs to be configured in the
Spring Boot yaml syntax for opening a view parser
spring.
mvc.
hiddenmethod.
HiddenHttpMethodFilter.
enabled: true # Enable rest for page forms, HiddenHttpMethodFilter is enabled, rest is supported.
view: # Configure the view parser
prefix: /rainbowsea/** # Here is something to note, if you configure static-path-pattern: /rainbowsea/** you need to keep it consistent
# prefix: /rainbowsea/ all lines # Note that if you configure static-path-pattern: /rainbowsea/** you need to be consistent.
suffix: .html
static-path-pattern: /rainbowsea/**
Let's ponder a question here:Why return "hello" here? It's not a string that's returned, it's forwarded to the corresponding resource file.
package ;
import ;
import ;
@RestController
public class HiController {
@RequestMapping("/hello")
public String hi(){
return "hi:):)";
}
@RequestMapping("/go")
public String go(){
return "hello";
/*
return is to see if there is a page in the view parser, and if not, look for the controller to handle the request.
if there is no page in the view parser, then look for the controller control, if there is no page in the view parser, then look for a 404 error.
/* return
}
}
Note: I did configure the view parser.
Start Spring Boot and open a browser to enter:http://localhost:8080/go
When a static resource exists, it does not go controller
We will static file resource Remove and revisit:http://localhost:8080/go
Question:
We will static file resource Remove and revisit:http://localhost:8080/go
Finally:
"In this final chapter, I would like to express my gratitude to each and every one of my readers. Your attention and responses have been a source of motivation for me to create, and I have drawn endless inspiration and courage from you. I will keep your encouragement in my heart and continue to struggle in other areas. Thanks to you all, we will always meet again at some point."