@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)了~求大牛解答!
1 回答
暴躁的代码
TA贡献7条经验 获得超10个赞
提了问之后,立马就想到了testA.action/100是不会经过springmvc的过滤器的
解决方案:
@RequestMapping(value = "/testA/{id}.action", 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/testA/100.action
添加回答
举报
0/150
提交
取消