处理注解@RequestParam的"Required String parameter is not present"

标签:
springmvcrequestparamrequired属性 |
分类: Web.JavaEE |
最近玩一下SpringMVC,代码如下:
访问http://localhost:8080/hellorest/test.do时发生如下问题:
http://s13/mw690/0026uWfMgy6MJkj4sBC5c&690Stringparameter is not present"" TITLE="处理注解@RequestParam的"Required String parameter is not present"" />
查了一下Annotation Type RequestParam的javadoc,加上可选参数required解决战斗。
@Controller
@RequestMapping("/test.do")
public class TestController {
@RequestMapping(method = RequestMethod.GET)
public ModelAndView sync(Model m,
@RequestParam("fid") String fid,
@RequestParam("sid") String sid) throws Exception {
if(fid==null || sid==null) {
m.addAttribute("file", new FileMetaDAO());
return new ModelAndView(ViewProvider.UPLOAD);
} else {
m.addAttribute("sync", new SyncDAO());
return new ModelAndView(ViewProvider.HR_SYNC);
}
}
}
访问http://localhost:8080/hellorest/test.do时发生如下问题:
http://s13/mw690/0026uWfMgy6MJkj4sBC5c&690String
查了一下Annotation Type RequestParam的javadoc,加上可选参数required解决战斗。
@Controller
@RequestMapping("/test.do")
public class TestController {
@RequestMapping(method = RequestMethod.GET)
public ModelAndView sync(Model m,
@RequestParam(value="fid", required = false) String fid,
@RequestParam(value="sid", required = false) String sid)
throws Exception {
if(fid==null || sid==null) {
m.addAttribute("file", new FileMetaDAO());
return new ModelAndView(ViewProvider.UPLOAD);
} else {
m.addAttribute("sync", new SyncDAO());
return new ModelAndView(ViewProvider.HR_SYNC);
}
}
}
后一篇:MinGW安装和使用