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

Springboot Thymeleaf实现HTML属性设置

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

Springboot Thymeleaf实现HTML属性设置

使用Thymeleaf的属性来设置HTML属性。

(1)使用th:attr属性可以修改原来HTML节点的属性;

(2)th:attr属性可以同时设置多个属性;

(3)每一个HTML属性都有对应的Thymeleaf属性,如th:attr="value='值'"可换为th:value="值"

(4)HTML的type为checkbox、readonly、required、disabled的,Thymeleaf属性可写为th:checked="true/false"形式;

(5)使用th:attrappend和th:attrprepend分别在HTML属性的后面或前面加入数据;

(6)使用th:styleappend和th:classappend分别向原有style、class属性添加样式;

(7)HTML5自定义属性以“data-”作为前缀,Thymeleaf同样支持自定义属性,例如可以使用“data-th-text”代替 “th:text”,使用“data-th-each”代替“th:each”;

开发环境:IntelliJ IDEA 2019.2.2

Spring Boot版本:2.1.8

新建一个名称为demo的Spring Boot项目。

1、pom.xml

加入Thymeleaf依赖

  
   org.springframework.boot
   spring-boot-starter-thymeleaf
  

2、src/main/java/com/example/demo/TestController.java

package com.example.demo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class TestController {
 @RequestMapping("/")
 public String test(){
  return "test";
 }
}

3、src/main/resources/templates/test.html




 
 Title





浏览器访问:http://localhost:8080

页面弹出:lc,30

右键查看网页源代码,生成的HTML源码:




 
 Title





以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持考高分网。

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

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

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