Spring Annotations @requestmapping Request Path mapping problem

Source: Internet
Author: User

@RequestMapping Request Path Mapping, if it is labeled at the class level of a controller, it indicates that access to the method under such a path is accompanied by the path to its configuration, which is most commonly labeled on the method, indicating which specific method to accept processing a request.

The following two ways can be passed from the URL parameters, but the second approach is more applicable, when the parameter contains Chinese, if the first way to pass parameters, often the parameters are not yet the controller has been encoded (for example: after Utf-8 encoding, The original parameters to be passed will be%+ab ... CD), and then the Controller accepts such a request, it is not possible to resolve the request at all should go 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 parameter access address for example: 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";} The second way to pass the parameter is to access the address for example: http: Domain/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";}}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

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.