使用注解配置SpringMVC是出现错误
代码:
@Controller
public class MySecondHandler {
@RequestMapping("/test1")
public ModelAndView test1() {
ModelAndView mav = new ModelAndView();
mav.addObject("name", "lisi");
mav.setViewName("show");
return mav;
}
springmvc.xml配置文件:
<!-- 配置视图解析器 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- 配置前缀 -->
<property name="prefix" value="/"></property>
<!-- 配置后缀 -->
<property name="suffix" value=".jsp"></property>
</bean>
<!-- 开启自动扫描 -->
<context:component-scan base-package="com.heng.springMVC"></context:component-scan>
<context:annotation-config></context:annotation-config>
提示错误:
4月 28, 2019 9:02:09 上午 org.springframework.web.servlet.DispatcherServlet noHandlerFound
警告: No mapping for GET /springMVC/test1
我使用非注解时,没有错误;
正在回答
同学你好,问一下同学在添加的add.jsp中的action是什么呢?是“/springMVC/test1”吗?建议同学修改为test1再试试呢。
如果我的回答解决了你的疑惑,请采纳。祝:学习愉快~
- 参与学习 人
- 提交作业 205 份
- 解答问题 4317 个
Java中非常实用的SSM整合开发内容,从Spring开始,到MyBaits的进阶内容,再到SpringMVC的应用,最后是SSM整合开发案例,逐步深入,助你成长为一名Java工程师!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星