@requestMapping
1. URL mapping
Defines the URL for the controller method, which is used for processor mapping
@RequestMapping ("/items")
public class Itemscontroller {...}
2. Narrowing request Mapping
3. Restricting the HTTP request method
For security reasons, the link to the HTTP method is limited.
If the limit request is a post method, make a get request with an error:
But because method={} is an array, you can write the post and Get methods in
The return value of the Controller method
1. Return to Modelandview
At the end of the method, define the Modelandview and set the model and view separately:
Modelandview.addobject ("item", Itemscustom);
Modelandview.setviewname ("EditItem");
2. Return string
If the Controller method returns a string
A. Represents the return logical view name . (the so-called logical view name is: The prefix and suffix are configured in Springmmvc, so the specific path is reduced to the path of removing the prefix and suffix)
Real View (JSP path ) = prefix + Logical View name + suffix
B,redirect redirect
After the product modification is submitted, redirect to the product query list.
REDIRECT redirection feature: The URL in the browser address bar will change. The request data for the modification submission cannot be uploaded to the redirected address. Re- requestafter redirection(request cannot be shared)
C, forward page forwarding
Page forwarding via forward, the URL of the browser address bar is not changed,request can be shared.
3. return void
request and response can be defined on the controller method parameters, using the request or Response Specify the response result:
a , using Request turn to the page as follows:
Request.getrequestdispatcher ("page path"). Forward (request, response);
b , you can also pass Response page redirection:
Response.sendredirect ("url")
C , you can also pass Response Specify response results, such as response JSON The data are as follows:
Response.setcharacterencoding ("Utf-8");
Response.setcontenttype ("Application/json;charset=utf-8");
Response.getwriter (). Write ("JSON string");
@requestmapping problem in SPRINGMVC and the return value problem of controller method