1. Configuring the package scanner in Applicationcontext.xml
<!--- <base-package = " Cn.cnsdhzzl.controller "/>
2. Configuring the Controller
/*Processor*/@Controller/*name Space*/@RequestMapping ("/annotation") Public classAnnotationcontroller {/*URL of the mapping request*/@RequestMapping (Value= "/fist.do") PublicString One () {System.out.println (The first method of annotations); /*Resource View logical name*/ return"Login"; } /*use annotations to pass parameters, and set the parameter is not necessary, when using the annotation tag to pass the parameter, do not pass the error, do not use the annotation label default Required=false, do not pass error*/@RequestMapping (Value= "/two.do") PublicString, @RequestParam (required =false) (String text) {System.out.println (The second method of annotations); System.out.println (text); return"Login"; } /*Automatic assembly Parameters*/@RequestMapping (Value= "/three.do") Publicstring Three (string text) {System.out.println (The third method of annotations); System.out.println (text); return"Login"; } /*use model to pass value to page, model is a map (key value pair)*/@RequestMapping (Value= "/four.do") Publicstring Four (string text, model model) {Model.addattribute ("Model", "HelloAnnotation4"); System.out.println ("Fourth method of annotations"); System.out.println (text); return"Login"; } /*do not write key by default to get values by type*/@RequestMapping (Value= "/five.do") Publicstring Five (string text, model model) {Model.addattribute ("HelloAnnotation5"); System.out.println ("Fifth method of annotations"); System.out.println (text); return"Login"; } /*use rest style to carry parameters, you need to configure web.xml:<url-pattern>*.do</url-pattern>*/@RequestMapping (Value= "/six/{text}") PublicString Six (@RequestParam (required=false) @PathVariable String text, model model) {Model.addattribute ("Model", text); System.out.println ("Sixth method of annotations"); System.out.println (text); return"Login"; } /*return directly to Modelandview*/@RequestMapping (Value= "/seven.do") PublicModelandview Seven () {Modelandview mv=NewModelandview (); Mv.setviewname ("Login"); Mv.addobject ("Model", "Modelandview"); returnMV; }}
annotation configuration springmvc and assigning values to scopes