比如有如下的Action方法:
@RequestMapping("/test/{p1}/{p2}")
public String testRest(@RequestParam String p1, @RequestParam String p2){
System.out.println("p1:"+p1);
System.out.println("p1:"+p1);
return "/jsp/test";
}
那么当访问的URL为:
http://localhost:8080/test/param1/param2
时会正常打印出
1:param1
p2:param2
但是当访问地址为
http://localhost:8080/test/
时就直接报错了,怎样才能实现访问这个url时自动给p1和p2一个默认值呢?
谢谢!
@RequestParam(value="somvalue",required=false) 这个看看呢
或者就是写2遍吧,
@RequestMapping(value="/json/{type}", method=RequestMethod.GET)
public @ResponseBody TestBean typedTestBean(HttpServletRequest req, @PathVariable String type, @RequestParam("track") String track) {
return getTestBean(type);
}
@RequestMapping(value="/json", method=RequestMethod.GET)
public @ResponseBody TestBean testBean(HttpServletRequest req, @RequestParam("track") String track) {
return getTestBean();
}
@RequestParam(required = false)