比如有如下的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();
}
重寫源碼