栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

SpringBoot-thymeleaf

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

SpringBoot-thymeleaf

Thymeleaf 官网:https://www.thymeleaf.org/

Thymeleaf 在Github 的主页:https://github.com/thymeleaf/thymeleaf

引入Thymeleaf


    org.springframework.boot
    spring-boot-starter-thymeleaf
Thymeleaf 语法学习

我们做个最简单的练习 :我们需要查出一些数据,在页面中展示

1、修改测试请求,增加数据传输;

package com.zjb.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class TestController {

    @RequestMapping("/test")
    public String test(Model model){
        model.addAttribute("msg","hello,SpringBoot");
        return "test";
    }
}

2、我们要使用thymeleaf,需要在html文件中导入命名空间的约束,方便提示。

我们可以去官方文档中看一下命名空间拿来过来:

 xmlns:th="http://www.thymeleaf.org"

3、我们去编写下前端页面




  
  Title


  

4、启动测试!

th:text 、th:utext
package com.zjb.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class TestController {

    @RequestMapping("/test")
    public String test(Model model){
        model.addAttribute("msg","hello,SpringBoot");
        return "test";
    }
}




  
  Title


  
  
  
  

 ​​​​​​​​​​​​​​

   th:each 遍历
package com.zjb.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Arrays;

@Controller
public class TestController {

    @RequestMapping("/test")
    public String test(Model model){
        model.addAttribute("users", Arrays.asList("lisi","zhangsan"));
        return "test";
    }
}



  
  Title


   

 ​​​​​​​​​​​​​​

关于网站图标说明:

首先2.2.x 和 2.2.x之前的版本 配置方式是不一样:

2.2.x之前配置:

只需要在yml文件中配置

spring:
  mvc:
    favicon:
      enabled: false

以及在resources文件夹中添加  favicon.ico 图片既可

 2.2.x之后配置:

不需要在yml文件中配置, 而是在html中配置





    
    nosoul
    
    


成功

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/582715.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号