2011-08-25 47 views
1

我有以下的控制器映射爲爲什麼我的Spring MVC控制器映射不能在同一個控制器中引用另一個映射?

@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; 
} 

我打電話的回報,即另一個映射。,return「/ stsr/requery」;我得到 以下錯誤:

Uncaught exception thrown in one of the service methods of the servlet: mptstp. Exception thrown : javax.servlet.ServletException: Could not resolve view with name '/stsr/requery' in servlet with name 'xxx'

的問題是,我需要在一些地方明確定義此映射?我沒有任何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> 

任何幫助從你們將不勝感激。

回答

2

兩個選項:

  • 可以重定向return "redirect:/stsr/requery"
  • 您可以直接調用其他方法:return requery(request);
+0

感謝您的快速響應。哪種方法更好地完成重定向,與最佳實踐相關。 –

+0

取決於。我會在常見情況下使用重定向 – Bozho

1

它尋找一個視圖和你想要的映射。您必須使用重定向:

return "redirect:/stsr/requery"; 
相關問題