Spring MVC learning – detailed explanation of URL parameter passing
In the process of learning spring MVC, it is necessary to understand several key parameters first:
@Controller:
If you annotate the class, this class will program a controller. Spring will automatically scan this class and map the corresponding URL route when the project starts.
@RequestMapping
Specify the URL mapping path. If requestmapping is configured on the controller and the specific request method is also configured with the path, the mapped path is the superposition of the two paths. Common mappings such as requestmapping ("URL. HTML")
Configure mapping path:
Above configuration mapping
http://***:8080:web1/get_ alluser. html:
If @ requestmapping (value = "/ user") is added to @ controller, the mapping path becomes
http://***:8080:web1/user/get_ alluser. html
@ResponseBody
Returns the string corresponding to the annotation method directly
@RequestParam
Automatically map the parameter corresponding to the URL to the value above the action. Requestparam is a required parameter by default.
@PathVariable
Gets the URL mapping parameter of the specified format in the @ requestmapping configuration
Page Jump:
Direct return JSON
The requested URL must be in JSON end, otherwise exception
Failed to load resource: the server responded with a status of 406 (Not Acceptable) : The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers ()
Return entity:
Return action
Request:
/web1/urlinfo/getuser. json
Output:
The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.