Spring Annotations @requestmapping Request Path mapping problem

Source: Internet
Author: User

@RequestMapping Request Path Mapping, assuming that the label is at the class level of a controller, the access to the method under such a path is accompanied by its configured path. Most often used is labeled on the method. Indicates which detailed method to accept processing a request.

The following two ways can be passed from the URL, but the applicability of the other way is higher, when the reference is included in Chinese, assuming that the first way to pass the parameters, often the number of participants before the controller has been encoded (for example: after Utf-8 encoding, The original number of references to be transmitted will be%+ab ... CD this way), and then the Controller accepts such a request, it simply cannot resolve the request should go to that business method. Then there will be a common 404 problem.

。。

Package Com.test.jeofey.web;import Javax.servlet.http.httpservletrequest;import Javax.servlet.http.httpservletresponse;import Org.springframework.stereotype.controller;import Org.springframework.web.bind.annotation.pathvariable;import org.springframework.web.bind.annotation.RequestMapping; @Controller @requestmapping ("/path") public class TestController {///first-pass access address such as: http: domain name/path/method1/keyword.html@requestmapping ("Method1/{keyword}") public String Getzhishidetaildata (@PathVariable ("KeyWord") string keyword,httpservletrequest request, HttpServletResponse Response) {System.out.println (KeyWord); return "V1/detail";} Another way to access addresses such as: http: domain name/path/method2.html?key=keyword@requestmapping ("METHOD2") Public String Getcommondata ( HttpServletRequest request, HttpServletResponse response) {String keyword= request.getparameter ("key"); System.out.println (KeyWord); return "V1/common";}}


Spring Annotations @requestmapping Request Path mapping problem

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.