Spring MVC Annotations

Source: Internet
Author: User

1. Start Scan Package
<context:component-scan base-package= "Annotation" ></context:component-scan>
2. Start annotations
1), Spring mode start annotations
<context:annotation-config></context:annotation-config>
2), <mvc:annotation-driven></mvc:annotation-driven>
3), <bean class= "org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" ></bean >
<bean class= "Org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" ></bean>

3. View Parser
<bean class= "Org.springframework.web.servlet.view.InternalResourceViewResolver" >
<property name= "Viewclass" value= "Org.springframework.web.servlet.view.JstlView" ></property>
<property name= "prefix" value= "/view/" ></property>
<property name= "suffix" value= ". JSP" ></property>
</bean>

4. @Controller controller definition
@Controller
public class Hellowordcontroller

5. @RequestMapping Definition URL
Defined on the class: the URL access controller on the Url+ method on the class
Defined on method: method on URL Access controller
@Controller
@RequestMapping (value= "/Home")
public class Hellowordcontroller {

6. Parameters on the @RequestParam binding method
public string Helloword (@RequestParam (value= "SSS") string s)
Assign the values on the SS to S
7. @SessionAttributes
Places the specified attribute in the Modelmap in the session
@Controller
@RequestMapping ("/user.do")
@SessionAttributes ({"U", "a"})//Put the attribute name U in Modelmap and a in the session. In this way, both the request and the session are available.
Publicclass Usercontroller {
@RequestMapping (params= "METHOD=REG4")
Public String REG4 (Modelmap map) {
System.out.println ("Hellocontroller.handlerequest ()");
Map.addattribute ("U", "uuuu"); Put u in the request scope so that the forwarding page can also fetch this data.
Return "index";
}
}

Spring MVC annotations

Related Article

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.