SPRINGMVC (iii) Requestmapping modified class

Source: Internet
Author: User

SPRINGMVC uses @requestmapping annotations to specify which URL requests can be processed by the controller.

can be used for class definitions and method definitions:

Class definition: Provides preliminary request mapping information. The root directory relative to the Web App.

Method: Provides further subdivision mapping information. Relative to the URL at the class definition. If there is no definition at the class definition, it is relative to the root directory.

For example, if the @requestmapping ("Pathclass") annotation is set for the class, @requestmapping ("method") is set for the method, the URL of the final call to the method is Pathclass/method. Full path such as Http://localhost:8080/HelloWorld/pathclass/helloworld.

Refer to the following controller test code:

 Packagecom.tiekui.springmvc.handlers;ImportOrg.springframework.stereotype.Controller;Importorg.springframework.web.bind.annotation.RequestMapping, @Controller @requestmapping ("Pathclass") Public classRequestmappingtest {Private StaticString success= "SUCCESS"; @RequestMapping ("HelloWorld")     PublicString Hello () {System.out.println ("Hello World from" +getclass ()); returnSUCCESS; }}

The reference code for calling this method in the JSP is as follows, and the following code can be added to the index.jsp in the HelloWorld project.

<href= "Pathclass/helloworld">pathclass Hello World Test</  a>

SPRINGMVC (iii) Requestmapping modified class

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.