springMVC的RequestMapping请求不到路径

代码展示:

controller层配置:

@Controller

public class UserController {

	private UserService service = new UserServiceImpl();

	

	@RequestMapping(value="/list",method=RequestMethod.GET)

	public String list(Model model) throws Exception {

		List<User> list = service.getAll();

		model.addAttribute("list", list);

		return "list";

	}

}

web.xml配置:

<servlet>

  	<servlet-name>springmvc</servlet-name>

  	<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

  	<init-param>

  		<param-name>contextConfigLocation</param-name>

  		<param-value>classpath:springmvc.xml</param-value>

  	</init-param>

  </servlet>

  <servlet-mapping>

  	<servlet-name>springmvc</servlet-name>

  	<url-pattern>*.action</url-pattern>

  </servlet-mapping>

springmvc.xml的配置:

<context:component-scan base-package="cn.jzh"></context:component-scan>

	<context:annotation-config conversion-service="dateConverter"></context:annotation-config>

	<!-- 视图解析 -->

	<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">

		<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"></property>

		<property name="prefix" value="/WEB-INF/view/"></property>

		<property name="suffix" value=".jsp"></property>

	</bean>

	<!-- 配置转换器 -->

	<bean id="dateConverter" class="org.springframework.format.support.FormattingConversionServiceFactoryBean">

		<property name="converters">

			<bean class="cn.jzh.converter.DateConverter"></bean>

		</property>

	</bean>

	

	<!-- 静态放行 -->

	<mvc:default-servlet-handler/>

jsp层,就这一句话:

  <a href="list.action">用户列表</a>

发现直接测试接口:项目名+list.action是没用的直接报404的路径找不到
另外,最后跳转的/WEB-INF/view/list.jsp也是存在的

错误所在:

原来是springmvc.xml的配置文件配置错了,注解的映射和驱动错误的使用了context:annotation-config,应该使用的是mvc:annotation-driven

猜你喜欢

转载自blog.csdn.net/u012060033/article/details/82428140
今日推荐