The suffix of the returned page in springmvc is html or jsp

When there are both jsp and html pages in the project, how to configure the suffix to use

  1. Do not configure the suffix when configuring InternalResourceViewResolver, specify the suffix when controller returns
  2. Configure multiple instances of InternalResourceViewResolvers and set viewClass

Create ResourceView

    public class HtmlResourceView extends InternalResourceView {
     
    	@Override  
    	public boolean checkResource(Locale locale){
    		File file=new File(this.getServletContext().getRealPath("/")+getUrl());
    		return file.exists(); //判断页面是否存在, 不存在就会走第二个InternalResourceViewResolver
    	}
    }

xml configuration multiple viewResolver

   <bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
        <property name="viewClass" value="上面你定义的类的路径"/>
        <property name="order" value="0" />
        <property name="prefix" value="/"/>
        <property name="suffix" value=".jsp" />  
        <property name="contentType" value="text/html;charset=UTF-8"></property>  
    </bean>
       <bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
        <property name="viewClass" value="上面你定义的类的路径"/>
        <property name="order" value="-1" />
        <property name="prefix" value="/"/>
        <property name="suffix" value=".html" />  
        <property name="contentType" value="text/html;charset=UTF-8"></property>  
    </bean>


Guess you like

Origin blog.csdn.net/xiaodujava/article/details/104278702