@Controller // 表示这是一个Controller @RequestMapping("annotation") // 映射规则 匹配 /annotation/*的请求 public class AnnotationController { @RequestMapping(value = "/test.action", method = RequestMethod.GET) // 该方法映射/annotation/test.action?id= // @RequestParam("id")将映射request-url中的参数id public String test(@RequestParam("id") Integer id, Model model) { System.out.println("test():" + id); List<Integer> list = new ArrayList<Integer>(); for (int i = 0; i < id; i++) { list.add(i); } model.addAttribute("list", list); return "list"; } /** * RESTFul风格的url testA.action/120</br> * 隐藏了参数id=120 * * @return String视图路径 */ @RequestMapping(value = "/testA.action/{id}", method = RequestMethod.GET) public String testA(@PathVariable("id") Integer id, Map<String, Object> model) { System.out.println(id); List<Integer> list = new ArrayList<Integer>(); for (int i = 0; i < id; i++) { list.add(i); } model.put("list", list); return "list"; } }
"http://localhost/springmvc/annotation/test.action?id=100"这个url访问第一个方法是可以的
但是用http://localhost/springmvc/annotation/testA.action/100访问就会404
我现在就当它是不支持(.action)了~
求大牛解答!
暴躁的代码
相关分类