SPRINGMVC can be mapped by Requestparam annotations to obtain parameters, using the following:
Example:
Configuration procedure omitted
1. New Controller class
1 PackageCom.loger.controller;2 3 ImportOrg.springframework.stereotype.Controller;4 Importorg.springframework.web.bind.annotation.RequestMapping;5 6 7 @Controller8 Public classRequestparam {9 Ten Public Static FinalString SUCCESS = "SUCCESS"; One A@RequestMapping (value= "/requestparam") - PublicString Requestparam (@org. springframework.web.bind.annotation. -Requestparam (value= "username") String un, the@org. Springframework.web.bind.annotation.RequestParam (value= "Age") (Integer age) { - -System.out.println (un + "" +Age ); - + returnSUCCESS; - } +}
2.index.jsp
Operation Result:
Add: If the table sole name is consistent with the parameter name of the method, you do not need to use the @requestparam annotation to map it.
If you change to
@RequestMapping (value= "/requestparam") public string Requestparam (String Username,integer-age)!
Use the class as an argument and include the parameter-fetching method for the cascading property :
1. New Adress class
1 PackageCom.loger.bean;2 3 Public classAddress {4 PrivateString Province;5 PrivateString City;6 PublicString getprovince () {7 returnProvince;8 }9 Public voidsetprovince (String province) {Ten This. Province =Province; One } A PublicString getcity () { - returnCity ; - } the Public voidsetcity (String city) { - This. City =City ; - } - @Override + PublicString toString () { - return"Address [province=" + Province + ", city=" + City + "]"; + } A at}
2. New User class
1 PackageCom.loger.bean;2 3 Public classAddress {4 PrivateString Province;5 PrivateString City;6 PublicString getprovince () {7 returnProvince;8 }9 Public voidsetprovince (String province) {Ten This. Province =Province; One } A PublicString getcity () { - returnCity ; - } the Public voidsetcity (String city) { - This. City =City ; - } - @Override + PublicString toString () { - return"Address [province=" + Province + ", city=" + City + "]"; + } A at}
3.controller
4. Forms
User has a cascading attribute address, and the form passed in with the parameter address.city address.province
1 <formAction= "Pojoparam">2Name:<inputtype= "text"name= "Name"><BR>3Age:<inputtype= "text"name= "Age"><BR>4City:<inputtype= "text"name= "Address.city"><BR>5Provinces:<inputtype= "text"name= "Address.province"><BR>6 <inputtype= "Submit"value= "Submit"><BR>7 </form>
Operation Result:
SPRINGMVC parameters obtained by annotations