http://localhost:8080/zhuyuanjie_springmvc1/quick?username=zhangsan&age=12
@RequestMapping("/quick")
@ResponseBody
public void quickMethod(String username,int age) throws IOException {
System.out.println(username);
System.out.println(age);
}
http://localhost:8080/zhuyuanjie_springmvc1/quick?username=zhangsan&age=12
public class User {
private String username;
private int age;
getter/setter…
}
@RequestMapping("/quick")
@ResponseBody
public void quickMethod(User user) throws IOException {
System.out.println(user);
}
http://localhost:8080/zhuyuanjie_springmvc1/quick?strs=111&strs=222&strs=333
@RequestMapping("/quick")
@ResponseBody
public void quickMethod(String[] strs) throws IOException {
System.out.println(Arrays.asList(strs));
}
< form action= " ${ pageContext.request.contextPath } /quick" method= "post" >< input type= "text" name= "name" >< br >< input type= "submit" value= " 提交 " >< br >form >
@RequestMapping("/quick")
@ResponseBody
public void quickMethod(@RequestParam("name") String username) throws
IOException {
System.out.println(username);
}
注解@RequestParam还有如下参数可以使用:
@RequestMapping("/quick")
@ResponseBody
public void quickMethod(@RequestParam(value="name",required =
false,defaultValue = "zhuyuanjie") String username) throws IOException {
System.out.println(username);
}
http://localhost:8080/zhuyuanjie_springmvc1/quick19/zhangsan
@RequestMapping("/quick/{name}")
@ResponseBody
public void quickMethod(@PathVariable(value = "name",required = true) String name){
System.out.println(name);
}
@RequestMapping("/quick")
@ResponseBody
public void quickMethod(HttpServletRequest request,HttpServletResponse response,HttpSession session){
System.out.println(request);
System.out.println(response);
System.out.println(session);
}