我将以下控制器映射为
@Controller( value = "stockToStoreController" )
@RequestMapping("/stsr")
public class StockToStoreController extends BaseController {...}
我有删除映射
@Transactional(propagation = Propagation.REQUIRED)
@RequestMapping(value = "/delete")
public String delete(@RequestParam("xxxId") long xxxId) {
XXXModel xxxModel = stockToStoreDao.findById(xxxId);
if(xxxModel != null) {
xxxDao.delete(xxxModel);
}
return "/stsr/requery";
}
该映射看起来像这样
@SuppressWarnings("unchecked")
@RequestMapping(value = "/requery")
public ModelAndView requery(HttpServletRequest request) {
ModelAndView mav = new ModelAndView("manageStockToStore");
//do stuff
return mav;
}
我尝试在返回中调用另一个映射,即返回“/ stsr / requery”;我明白了 以下错误:
在servlet的一个服务方法中抛出未捕获的异常:mptstp。抛出异常:javax.servlet.ServletException:无法解析名为'xxx'的servlet中名为'/ stsr / requery'的视图
问题是,我是否需要在某处明确定义此映射?我没有定义任何MappingHandlers,我的-servlet.xml看起来像
<!-- Configures the @Configuration annotation for java configuration -->
<context:annotation-config/>
<!-- Scans the classpath of this application for @Components to deploy as beans -->
<context:component-scan base-package="xxx.testspringmvc.stsr" />
<!-- Configures the @Controller programming model -->
<mvc:annotation-driven />
<!-- Configures resources so they can be used across web modules -->
<mvc:resources mapping="/resources/**" location="/, classpath:/META-INF/public-resources/" />
<!-- Application Message Bundle -->
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basenames" value="classpath:META-INF/public-resources/mptstp-messages, classpath:META-INF/public-resources/mptstp-error-messages, classpath:META-INF/public-resources/stsr/stsr-messages" />
<property name="cacheSeconds" value="0" />
</bean>
<!-- Spring MVC View Resolver -->
<bean id="viewResolver" class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
<property name="basename" value="stsr-views" />
<property name="defaultParentView" value="parentView"/>
</bean>
<mvc:interceptors>
<mvc:interceptor>
<mvc:mapping path="/**"/>
<bean id="urlConfiguredSiteIdInterceptor" class="xxx.testspringmvc.stsr.interceptor.UrlConfiguredSiteIdInterceptor">
<property name="siteIdConfigParamName" value="urlConfiguredSiteId" />
<property name="errorView" value="siteIdNotFound" />
</bean>
</mvc:interceptor>
</mvc:interceptors>
非常感谢你们的任何帮助。
答案 0 :(得分:2)
两个选项:
return "redirect:/stsr/requery"
return requery(request);
答案 1 :(得分:1)
它正在寻找一个视图,你想要一个映射。您必须使用重定向:
return "redirect:/stsr/requery";