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