springboot02-yml-日志-静态资源映射-thymeleaf
1.yml
# 这里是注释
#@ConfigurationProperties(prefix="person") 获取
#@Value()获取
server:
port: 8081
2.日志
日志门面: JCL . SLF4j . jboss-logging
日志实现: Log4j . JUL . log4j2. logback
SpringBoot选用SLF4j和logback
3.静态资源映射
webjars的方式(略)
静态资源的文件夹
- 1.classpath:/META_INF/resources/
- 2.classpath:/resources/
- 3.classpath:/static/
- 3.classpath:/public/
4.欢迎页
静态资源文件夹下的所有index.html页面
5.favicon.ico
静态资源文件夹下 **/favicon.ico
6.thymeleaf
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
thymeleaf语法
默认前缀:classpath:/templates/
默认后缀:html
Controller通过thymeleaf向html传值
@RequestMapping("/success")
public String success(Model model, Map<String,Object> map){
model.addAttribute("key01","value01");
map.put("key02","value02");
return "success";
}
<div th:text="${key01}">这里显示欢迎信息</div>
<div th:text="${key02}">这里显示欢迎信息</div>
thymeleaf标签
优先级由高到低
------------
片段包含
th:insert
th:replace
-------------
遍历
th:each
-------------
判断
th:if
th:unless
th:switch
th:case
-------------
变量声明
th:object
th:with
-------------
任意属性修改
支持prepedn,append
th:attr
th:attrprepend
th:attrappend
-------------
修改指定属性默认值
th:value
th:href
th:src
----------------
修改标签体内容
th:text 转义特殊字符
th:utext 不转义特殊字符
----------------
声明片段
th:fragment
---------------
th:remove
thymeleaf表达式语法
${...} 获取变量值
Access to properties using the point.Equivalent to calling property getters
${person.father.name}
也可以这样写
${person['father']['name']}
数组
${personArray[0].name}
方法调用
${person.createCompleteName()}
${person.createCompleteNameWithSeparator('.')}
${...}
中可以使用内置对象
${...}
中可以使用内置工具
*{...}
和${...}
功能相似
但是*{...}
配合th:object
使用
#{...}
获取国际化内容
@{...}
定义URL
跳转其他界面
<p>Please select an option</p>
<ol>
<li><a href="product/list.html" th:href="@{/product/list}">Product List</a></li>
<li><a href="order/list.html" th:href="@{/order/list}">Order List</a></li>
<li><a href="subscribe.html" th:href="@{/subscribe}">Subscribe to our Newsletter</a></li>
<li><a href="userprofile.html" th:href="@{/userprofile}">See User Profile</a></li>
</ol>
超链接传参数
<!-- Will produce 'http://localhost:8080/gtvg/order/details?orderId=3' (plus rewriting) -->
<a href="details.html"
th:href="@{http://localhost:8080/gtvg/order/details(orderId=${o.id})}">view</a>
<!-- Will produce '/gtvg/order/details?orderId=3' (plus rewriting) -->
<a href="details.html" th:href="@{/order/details(orderId=${o.id})}">view</a>
<!-- Will produce '/gtvg/order/3/details' (plus rewriting) -->
<a href="details.html" th:href="@{/order/{orderId}/details(orderId=${o.id})}">view</a>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了