3 回答
TA贡献1796条经验 获得超7个赞
thymeleaf 与 jsp 同时使用 for spring mvc
spring-mvc.xml
[html] view plain copy
<!-- **************************************************************** -->
<!-- THYMELEAF-SPECIFIC ARTIFACTS -->
<!-- TemplateResolver <- TemplateEngine <- ViewResolver -->
<!-- **************************************************************** -->
<bean id="templateResolver"
class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">
<property name="prefix" value="/WEB-INF/" />
<property name="suffix" value=".html" />
<property name="templateMode" value="HTML5" />
<!-- Template cache is true by default. Set to false if you want -->
<!-- templates to be automatically updated when modified. -->
<property name="cacheable" value="#{ systemProperties['thymeleaf.cacheable'] == 'false' ? false : true }" />
<property name="characterEncoding" value="utf-8"/>
</bean>
<bean class="org.thymeleaf.spring4.view.ThymeleafViewResolver">
<property name="templateEngine">
<bean class="org.thymeleaf.spring4.SpringTemplateEngine">
<property name="templateResolver" ref="templateResolver" />
</bean>
</property>
<property name="viewNames" value="thymeleaf/*"/>
<property name="order" value="0"/>
</bean>
<!-- jsp resolver -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/"/>
<property name="suffix" value=".jsp"/>
<property name="viewNames" value="jsps/*"/>
<property name="order" value="1"/>
<property name="cache" value="#{ systemProperties['jsp.cacheable'] == 'false' ? false : true }"/>
</bean>
加两个属性,
<property name="viewNames" value="thymeleaf/*"/>
<property name="viewNames" value="jsps/*"/>
ViewResolver 会根据 viewName 选择不同处理器。
另外开发时禁用红缓存,每次重新解析模板,改动立即生效。
<property name="cacheable" value="#{ systemProperties['thymeleaf.cacheable'] == 'false' ? false : true }" />
- 3 回答
- 0 关注
- 814 浏览
添加回答
举报