7.16

//将一个JSP页面转换成一个HTML页面

1.在servlet中配置thymeleaf

<!-- thymeleaf的视图解析器 -->

<bean id="templateResolver"

class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">

<property name="prefix" value="/WEB-INF/html/" />

<property name="suffix" value=".html" />

<property name="templateMode" value="HTML5" />

</bean>

<bean id="templateEngine" class="org.thymeleaf.spring4.SpringTemplateEngine">

<property name="templateResolver" ref="templateResolver" />

</bean>

<bean id="viewResolverThymeleaf" class="org.thymeleaf.spring4.view.ThymeleafViewResolver"> //重点在此做了修改

<property name="templateEngine" ref="templateEngine" />

<property name="characterEncoding" value="UTF-8"/>

<property name="order" value="0"/>

</bean>

2.导入下面三个包

thymeleaf-2.1.4.RELEASE.jar

thymeleaf-spring4-2.1.4.RELEASE.jar

unbescape-1.1.0.RELEASE.jar

3.在html页面的顶端写下如下代码

<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">

让页面与thymeleaf关联这样就可以使用th:标签。

4.特别注意在使用thymelear包后对页面的标签将非常严格一定记住结束语标签

5.在获取后台的值时<span th:text="${userInfo.userId}">15</span>要使用span标签,因为thymelear只有属性没有标签所以要加一个span标签这样才能显示后台传来的值。//在标签中有个15,是静态页面时显示的数字,如果是动态页面,那么后台传来的值就会覆盖这个15。

你可能感兴趣的:(7.16)