2014-04-21 51 views
0

我有一個觀點解析:
的Spring MVC作爲UrlBasedViewResolver自定義視圖文件

<bean id="viewResolver" 
     class="org.springframework.web.servlet.view.UrlBasedViewResolver"> 
     <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /> 
     <property name="prefix" value="/WEB-INF/views/" /> 
     <property name="suffix" value=".jsp" /> 
    </bean> 

和控制器:

@RequestMapping(value = "/home", method = RequestMethod.GET) 
    public String loadPage(HttpServletRequest request,HttpServletResponse response, HttpSession session,ModelMap modelMap) { 
String langlayout = "eng"; 
      UrlBasedViewResolver urlResolver = new UrlBasedViewResolver();   
      urlResolver.setPrefix("/WEB-INF/views/"+langlayout); 
      urlResolver.setSuffix(".jsp"); 
      return "home/list.jsp"; 
} 

點擊在jsp後,其仍然在尋找在WEB-INF/views/home/list而不是WEB-INF/views/eng/home/list
如何定義自定義視圖頁面

回答

1

終於拿到了我的問題

<!-- Declare a view resolver --> 
    <bean class="com.project.controller.AppPortalViewResolver"> 
     <property name="viewResolver" ref="viewResolver" /> 
    </bean> 
<bean id="viewResolver" 
     class="org.springframework.web.servlet.view.UrlBasedViewResolver"> 
     <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /> 
     <property name="prefix" value="/WEB-INF/views/" /> 
     <property name="suffix" value=".jsp" /> 
    </bean> 

AppPortalViewResolver.class

public class AppPortalViewResolver implements ViewResolver { 

private ViewResolver viewResolver; 

public void setViewResolver(ViewResolver viewResolver) { 
    this.viewResolver = viewResolver; 
} 


@Override 
public View resolveViewName(String viewName, Locale locale) throws Exception { 
     /* do your logic to change the view name */ 
     viewName = "ur_folder_structure"; 
    return viewResolver.resolveViewName(viewName, locale);  
} 
0
@RequestMapping(value = "/home", method = RequestMethod.GET) 
    public String loadPage(HttpServletRequest request,HttpServletResponse response, HttpSession session,ModelMap modelMap) { 
String langlayout = "eng"; 
      return langlayout+"/home/list.jsp"; 
} 
+0

是的,我試過this..but我有一個時間的配置做到這一點的解決方案?像鏈式視圖解析器 –