开发者社区> 问答> 正文

关于controller注解应用问题!

@Controller
@RequestMapping("/demo")
public class HelloController  {
    @RequestMapping("/hello.do")
    public ModelAndView handleRequest(HttpServletRequest arg0,
            HttpServletResponse arg1) throws Exception {
          System.out.println("Hello, Controller.");
            return new ModelAndView("jsp/hello");
    }

}
 @Controller
@RequestMapping("/demo/hello.do")
public class HelloController  {
    public ModelAndView handleRequest(HttpServletRequest arg0,
            HttpServletResponse arg1) throws Exception {
          System.out.println("Hello, Controller.");
            return new ModelAndView("jsp/hello");
    }

}

有区别吗?为什么第二种写法会报错?

展开
收起
小旋风柴进 2016-03-04 16:58:57 2205 0
1 条回答
写回答
取消 提交回答
  • RequestMapping是一个用来处理请求地址映射的注解,可用于类或方法上。方法上是必须要写的,然后用于类上的时候是表示类中的所有响应
    请求的方法都是以该地址作为父路径。这也是SpringMVC和Struts的区别。一个是方法拦截,一个是类拦截。

    2019-07-17 18:52:33
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载