通过URL限定:绑定{xxx}中的值-Spring3MVC注解教程

时间:2021-04-25 08:34:37
【文件属性】:
文件名称:通过URL限定:绑定{xxx}中的值-Spring3MVC注解教程
文件大小:2.65MB
文件格式:PPT
更新时间:2021-04-25 08:34:37
spring mvc 通过URL限定:绑定{xxx}中的值 @RequestMapping("/{userId}") public ModelAndView showDetail(@PathVariable("userId") String userId){ ModelAndView mav = new ModelAndView(); mav.setViewName("user/showDetail"); mav.addObject("user", userService.getUserById(userId)); return mav; } @Controller @RequestMapping("/owners/{ownerId}") public class RelativePathUriTemplateController { @RequestMapping("/pets/{petId}") public void findPet(@PathVariable String ownerId, @PathVariable String petId, Model model) { … } } URL中的{xxx}占位符可以通过@PathVariable("xxx")绑定到操作方法的入参中。 如果@PathVariable不指定参数名,只有在编译时打开debug开关(javac -debug=no)时才可行!!(不建议) 参考《Spring 3.x企业应用开发实战》

网友评论