zoukankan      html  css  js  c++  java
  • thymeleaf 的使用(二)--基本语法

    在html文件中, 首先导入thymeleaf的名称空间

    <html lang="en" xmlns:th="http://www.thymeleaf.org">

    然后先感受一下thymeleaf的语法--he:

      先在controller中配置:

     1 @Controller
     2 public class Hellocontroller {
     3 
     4     @ResponseBody
     5     @RequestMapping("/success")
     6     public String success(Map<String,Object> map){
     7         map.put("hello", "你好你好~~~");
     8         return "success";
     9     }
    10 }

      html文件代码如下:

     1 <!DOCTYPE html>
     2 <html lang="en" xmlns:th="http://www.thymeleaf.org">
     3 <head>
     4     <meta charset="UTF-8">
     5     <title>success</title>
     6 </head>
     7 <body>
     8 <h2>成功!!!</h2>
     9 <!--设置div的文本-->
    10 <div th:text="${hello}">这是显示的欢迎信息</div>
    11 
    12 </body>
    13 </html>

    启动项目后浏览器访问: localhost:8080/success, 将返回:

     

     可以看见controller中的数据传到了HTML中, 可以通过这种方式将后台的数据在前端显示

  • 相关阅读:
    Alpha冲刺Day5
    Alpha冲刺Day4
    Alpha冲刺Day3
    团队作业——随堂小测
    Alpha冲刺Day2
    Alpha冲刺Day1
    团队项目需求分析
    结对项目第二次作业
    Linux中exec命令相关
    .lib和.dll文件
  • 原文地址:https://www.cnblogs.com/Ryan368/p/13674388.html
Copyright © 2011-2022 走看看