//一种传递参数的方式
@RequestMapping(value = "/cc1", method = RequestMethod.GET)
@ResponseBody
public String chuanCan1(@RequestParam(value = "name", required = false) String name){
if(name != null){
return name;
}else{
return "未传入参数";
}
}
//另一种传递参数的方式
@RequestMapping(value = "/cc2/{id}", method = RequestMethod.GET)
@ResponseBody
public Integer chuanCan2(@PathVariable("id") Integer id){
if(id != null){
return id;
}else {
return 0;
}
}
第一种方式,通过http://localhost:8080/cc1?name=hello形式访问,页面中显示hello,@Requestparam
第二种方式通过http://localhost:8080/cc2/88形式访问,得到id的值是88,@PathVariable