@RequestParams
註解是將請求參數綁定到控制器的方法參數上(是springmvc中接收普通參數的註解)前端
當參數名與方法中變量名相同時,@RequestParams註解能夠省略spring
@RequestMapping(value="/value") public String testValue(@RequestParam String username,@RequestParam(value="password") String psw) { System.out.println("username==" + username); System.out.println("password==" + psw); return "success"; }
參數中沒包含password,則默認值爲defaultValue中設的默認值,username沒設默認值,則爲nullmvc
@RequestMapping(value="/defaultValue") public String testDefaultValue(String username,@RequestParam(defaultValue="987654") String password) { System.out.println("username==" + username); System.out.println("password==" + password); return "success"; }
參數總不包含password,報錯app
@RequestMapping(value="/requiredTrue") public String testRequired(String username,@RequestParam(required=true) String password) { System.out.println("username==" + username); System.out.println("password==" + password); return "success"; }