1
嗨我已经创建了一个Spring MVC应用程序,我有两种方法称为估计控制器。春天MVC宁静的路径
我可以去这个网址www.wesite.com/xyz/estimation
访问该控制器的家庭法但我尝试去这个网址访问homeById方法www.wesite.com/xyz/estimation/1 我收到404错误,请求的资源不可用。
可以任何身体请在它上面洒一些光。
@Controller
@RequestMapping("/estimation")
public class EstimationController {
@RequestMapping("")
public ModelAndView home(HttpServletRequest request, HttpServletResponse response) {
ModelAndView mv = new ModelAndView("productEstimate");
return mv;
}
@RequestMapping(value="/{productId}", method = RequestMethod.GET)
public ModelAndView homeById(HttpServletRequest request, HttpServletResponse response,@PathVariable int productId) {
ModelAndView mv = new ModelAndView("productEstimate");
return mv;
}
的web.xml
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
WEB-INF/classes/spring/applicationContext.xml,
WEB-INF/classes/spring/hibernateContext.xml
</param-value> </context-param>
<servlet>
<servlet-name>projectName</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value></param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>projectName</servlet-name>
<url-pattern>/estimation/*</url-pattern>
</servlet-mapping>
的applicationContext.xml
<mvc:annotation-driven />
<bean id="velocityConfig" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
<property name="resourceLoaderPath" value="/views/" />
</bean>
<bean id="viewResolver" class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
<property name="cache" value="true"/>
<property name="prefix" value=""/>
<property name="layoutUrl" value="layout.vm"/>
<property name="suffix" value=".vm"/>
</bean>
你可以得到两个如果映射不匹配的错误或者如果视图无法呈现(但是我发现您对这两个请求都使用相同的视图,所以如果第一个视图正常工作,第二个视图也应该如此)。看看你是否有错误,例如:警告:找不到使用URI的HTTP请求映射 – namero999