zoukankan      html  css  js  c++  java
  • Springmvc 配置thymeleaf 和jsp 双模板引擎

    假设现在有这么一个需求,在Springmvc中需要存在两个模板引擎jsp和thymeleaf。
    我们可以这样来进行配置。

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:context="http://www.springframework.org/schema/context"
           xmlns:mvc="http://www.springframework.org/schema/mvc"
           xsi:schemaLocation="http://www.springframework.org/schema/mvc
            http://www.springframework.org/schema/mvc/spring-mvc.xsd
            http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context.xsd">
    
    
        <context:component-scan
                base-package="org.huluo"/>
    
        <mvc:annotation-driven validator="validator"/>
    
        <!--加入Bean校验配置-->
        <bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">
            <property name="providerClass" value="org.hibernate.validator.HibernateValidator"/>
        </bean>
    
        <!-- 双模板引擎 -->
        <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="prefix" value="/WEB-INF/jsp/"/>
            <property name="viewNames" value="*.jsp"/>
        </bean>
    
        <bean id="templateResolver" class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">
            <property name="prefix" value="/WEB-INF/thymeleaf/"/>
            <property name="templateMode" value="HTML5"/>
            <property name="characterEncoding" value="utf-8"/>
        </bean>
        <bean id="templateEngine" class="org.thymeleaf.spring3.SpringTemplateEngine">
            <property name="templateResolver" ref="templateResolver"/>
        </bean>
        <bean class="org.thymeleaf.spring3.view.ThymeleafViewResolver">
            <property name="templateEngine" ref="templateEngine"/>
            <property name="viewNames" value="*.html"/>
            <property name="characterEncoding" value="utf-8"/>
        </bean>
    </beans>

    关键性的地方在这里

     <property name="viewNames" value="*.jsp"/>
      <property name="viewNames" value="*.html"/>

    而不是以前的

    <property name="suffix" value=".jsp"/>
  • 相关阅读:
    POJ 1469 COURSES 二分图最大匹配
    POJ 1325 Machine Schedule 二分图最大匹配
    USACO Humble Numbers DP?
    SGU 194 Reactor Cooling 带容量上下限制的网络流
    POJ 3084 Panic Room 求最小割
    ZOJ 2587 Unique Attack 判断最小割是否唯一
    Poj 1815 Friendship 枚举+求最小割
    POJ 3308 Paratroopers 最小点权覆盖 求最小割
    1227. Rally Championship
    Etaoin Shrdlu
  • 原文地址:https://www.cnblogs.com/roak/p/14704202.html
Copyright © 2011-2022 走看看