IDEA2025 thymeleaf引入静态资源文件

一、项目结构

二、放置静态资源

将CSS、JS和Image 文件放在src/main/webapp/目录css,js,images下 。

在Thymeleaf模板中,可以使用Thymeleaf的URL表达式来引用这些静态资源。

html 复制代码
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <link rel="stylesheet" href="css/index.css"/>
    <script src="js/index.js"></script>

<!--    URL表达式-->
<!--    <link rel="stylesheet" th:href="@{/css/index.css}"/>-->
</head>
<body>
欢迎页面!<p/>
<h1 th:text="${hello}">Hello</h1>
<button onclick="my1()">Click</button>
<a href="javascript:my2()"><img src="images/woman.jpeg" height="200px" width="200px"> </a>
<a href="javascript:my3()"><img th:src="@{/images/2.png}" height="200px" width="200px"> </a>

</body>
</html>

三、运行效果

相关推荐
budingxiaomoli7 小时前
Spring IoC &DI
java·spring·ioc·di
Spider Cat 蜘蛛猫8 小时前
Springboot SSO系统设计文档
java·spring boot·后端
未若君雅裁8 小时前
MySQL高可用与扩展-主从复制读写分离分库分表
java·数据库·mysql
学习中.........8 小时前
从扰动函数的变化,感受红黑树带来的性能提升
java
计算机安禾8 小时前
【c++面向对象编程】第24篇:类型转换运算符:自定义隐式转换与explicit
java·c++·算法
weixin199701080169 小时前
【保姆级教程】淘宝/天猫商品详情 API(item_get)接入指南:Python/Java/PHP 调用示例与 JSON 返回值解析
java·python·php
环流_9 小时前
redis核心数据类型在java中的操作
java·数据库·redis
雨辰AI9 小时前
SpringBoot3 项目国产化改造完整流程|从 MySQL 到人大金仓落地
java·数据库·后端·mysql·政务
带刺的坐椅9 小时前
Java 流程编排新范式 Solon Flow:一个引擎,七种节点,覆盖规则/任务/工作流/AI 编排全场景
java·spring·ai·solon·flow
知彼解己10 小时前
Arthas:Java生产环境问题排查利器,从入门到实战
java