First, review the previous controller's wording:http://www.cnblogs.com/eco-just/p/7882016.html.
We can see that the previous wording was this:
@RequestMapping ("/hello3") //http://localhost: 8080/webmvc/hello4?name=eco Publicstring Hello4 (string name) {System. out. println (name); return "Hello"; } @RequestMapping ("/hello4") Public voidHello3 (HttpServletRequest req,httpservletresponse resp) throws exception{Req.setattribute ("a","that's me .");//A can be written on the following page with the EL expressionReq.getrequestdispatcher ("01.jsp"). Forward (req, resp);//request forwarding to the root directory jsp--does not require a view resolver//resp.sendredirect ("01.jsp");//request redirected to jsp--in root does not require view resolver}
}
Or combine the above two, but we find a problem, if it is written as above, how many links have to be written
The matching @RequestMappingcan be said to be very egg-sore. For example, for a class of links, we can combine this type of link into a
A @requestmapping up. So the following @PathVariableto say:
@RequestMapping ("/{put}") Publicstring Hello1 (@PathVariable string put) {returnput; }
@RequestMapping ("/free/{put}") PublicString Hello2 (@PathVariable ("put") StringGet) { return Get; }
Two methods:
1. Pass the path parameter put to the method parameter put, note that the two put to be consistent, that is, the path parameter name is put, the function parameter name is also put;
[Email protected] ("put") gets the value of the path parameter named put and passes it to the method parameter get, where the function parameter name can be arbitrary;
In this way, although we only write a @requestmapping, but can achieve a lot of link jump behavior:
http://localhost:8080/projectname/index--------jump to index page;
http://localhost:8080/projectname/Hello---------jump to the Hello page;
http://localhost:8080/projectname/Free/good---------jump to good page;
http://localhost:8080/projectname/free/job-----------Jump to the job page;
A little supplement to the SPRINGMVC controller