zoukankan      html  css  js  c++  java
  • SSM框架整合thymeleafspring5模板引擎

    1、pom.xml文件增加依赖:

    <!--thymeleaf-spring5 -->
    <dependency>
         <groupId>org.thymeleaf</groupId>
         <artifactId>thymeleaf-spring5</artifactId>
         <version>3.0.11.RELEASE</version>
    </dependency>

    2、将spring-mvc.xml中原先jsp的视图解析器修改:

    <bean id="templateResolver" class="org.thymeleaf.spring5.templateresolver.SpringResourceTemplateResolver">
        <property name="prefix" value="/WEB-INF/templates/"/>
        <property name="suffix" value=".html"/>
        <property name="characterEncoding" value="UTF-8"/>
        <property name="order" value="1"/>
        <property name="templateMode" value="HTML5"/>
        <property name="cacheable" value="false"/>
    </bean>
    
    <bean id="templateEngine"
          class="org.thymeleaf.spring5.SpringTemplateEngine">
        <property name="templateResolver" ref="templateResolver"/>
    </bean>
    
    <bean id="viewResolver" class="org.thymeleaf.spring5.view.ThymeleafViewResolver">
        <property name="templateEngine" ref="templateEngine"/>
        <property name="characterEncoding" value="UTF-8"/>
    </bean>

    3、测试,controller:

    @Controller
    @RequestMapping("/test")
    public class TestController {
        @RequestMapping("")
        public String test(Model model)
        {
            model.addAttribute("name","I'm thymeleaf !");
            return "test";
        }
    }

    4、编写test.html

    <!DOCTYPE html>
    <html lang="en" xmlns:th="http://www.thymeleaf.org">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
        <h1 th:text="${name}"></h1>
    </body>
    </html>

    注意:

    • <property name="prefix" value="/WEB-INF/templates/"/>这里写页面相应的目录。
    • 在html头添加xmlns:th="http://www.thymeleaf.org",以便提示thymeleaf语法
  • 相关阅读:
    VC常用代码
    richedit
    vc++ 2005 发布程序
    管道应用之捕获控制台程序信息
    黑客基础知识编程(转)
    Get All IE Info from win32 api
    vc 界面编程常用方法(http://blog.emuch.net/244485/spacelistblogitemtypeid2708.html)
    使用ADO调用存储过程
    在C#中如何实现文件夹的复制(转)
    C语言开发病毒程序(转)
  • 原文地址:https://www.cnblogs.com/roak/p/14633479.html
Copyright © 2011-2022 走看看