zoukankan      html  css  js  c++  java
  • springboot-thymeleaf动态模板生成

    thymeleaf动态模板:

    Map data = new HashMap();
    data.put("code", "1234");
    SpringTemplateEngine springTemplateEngine = new SpringTemplateEngine();
    //IDialect iDialect = new SpringStandardDialect();
    //springTemplateEngine.setDialect(iDialect);
    StringTemplateResolver stringTemplateResolver = new StringTemplateResolver();
    stringTemplateResolver.setCacheable(true);
    stringTemplateResolver.setTemplateMode(TemplateMode.HTML);
    springTemplateEngine.setTemplateResolver(stringTemplateResolver);
    Context context = new Context();
    context.setVariables(data);
    String content = "短信验证码为:<span th:utext="${code}"></span>,5分钟内有效";
    String result = springTemplateEngine.process(content, context);

    pom文件引入:

    <dependency>
      <groupId>org.thymeleaf</groupId>
      <artifactId>thymeleaf</artifactId>
      <version>3.0.9.RELEASE</version>
    </dependency>

    若直接引入:

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-thymeleaf</artifactId>
      <version>2.0.4.RELEASE</version>
    </dependency>

    那么如果spring-boot的版本是2.0以下的会有问题

  • 相关阅读:
    bootstrap以及考试复习
    HTML复习
    驼峰命名法和模态对话框
    dom和bom
    dom习题复习和讲解
    DOM
    属性扩展
    sql防注入式攻击
    自动生成编号
    删除,修改,添加
  • 原文地址:https://www.cnblogs.com/tiramisuyj/p/9521152.html
Copyright © 2011-2022 走看看