国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

SpringBoot 整合Thymeleaf教程及使用 springboot配合thymeleaf,調(diào)用接口不跳轉(zhuǎn)頁面只顯示文本

這篇具有很好參考價值的文章主要介紹了SpringBoot 整合Thymeleaf教程及使用 springboot配合thymeleaf,調(diào)用接口不跳轉(zhuǎn)頁面只顯示文本。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

Thymeleaf 是一款用于渲染 XML/XHTML/HTML5 內(nèi)容的模板引擎。它與 JSP,Velocity,F(xiàn)reeMaker 等模板引擎類似,也可以輕易地與 Spring MVC 等 Web 框架集成。與其它模板引擎相比,Thymeleaf 最大的特點是,即使不啟動 Web 應用,也可以直接在瀏覽器中打開并正確顯示模板頁面 。

目錄

一、整合Thymeleaf

二、Thymeleaf 使用教程

三、Thymeleaf 實戰(zhàn)應用


一、整合Thymeleaf

?1、引入Thymeleaf starter依賴

		<!-- thymeleaf 相關(guān)依賴 -->
		<dependency>
		    <groupId>org.springframework.boot</groupId>
		    <artifactId>spring-boot-starter-thymeleaf</artifactId>
		</dependency>

2、在 application.properties 添加 Thymeleaf 相關(guān)配置

server.port= 8092

#關(guān)閉 Thymeleaf 的緩存開發(fā)過程中無需重啟
spring.thymeleaf.cache = false
#設(shè)置thymeleaf頁面的編碼
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.mode=HTML5
#設(shè)置thymeleaf頁面的后綴
spring.thymeleaf.suffix=.html
#設(shè)置thymeleaf頁面的存儲路徑
spring.thymeleaf.prefix=classpath:/templates/

Thymeleaf默認會開啟頁面緩存,提高頁面并發(fā)能力。但會導致我們修改頁面不會立即被展現(xiàn),因此我們關(guān)閉緩存:spring.thymeleaf.cache=false

修改完畢頁面,需要使用快捷鍵:Ctrl + Shift + F9來刷新工程。

3、編寫訪問 Thymeleaf 頁面 Controller

@Controller
@RequestMapping("/hello")
public class ThymeleafHelloWrodController {
    @RequestMapping({"/", "/index"})
    @ResponseBody
    public String index(Model model,String id) {
        model.addAttribute("msg", "welcome you!" + id);

        Map<String,String> user = new HashMap<>();
        user.put("uid","11111");
        user.put("umc","testmc");
        user.put("etel","13550125501");
        model.addAttribute("user", user);
        return "index"; //返回的是index.html的頁面 
    }

	@RequestMapping("/thymeleaf")
	public String helloThymeleaf(Model model){
		model.addAttribute("hello","hello Thymeleaf!");
		return "hello/index";
	}
}


 

后臺springmvc 使用 Model 傳入數(shù)據(jù) (包名:org.springframework.ui.Model)

Thymeleaf的主要作用是把model中的數(shù)據(jù)渲染到html中,因此其語法主要是如何解析model中的數(shù)據(jù)。

3、Controller類編寫(@RequestBody注解是必須加上的,將java對象轉(zhuǎn)為json格式的數(shù)據(jù)。如果出現(xiàn)頁面顯示不了又沒有報錯可能就是Controller類沒有加@RequestBody)

返回的是Thymeleaf 模板對應的index.html的頁面?

- public interface Model{} ? ? ? ? ? ? //是一個接口
- public class ModelMap extends LinkedhashMap<String,Object>{} ? ? ? ? ? ?//繼承了LinkedHashMap
- public class ExtendedModelMap extends MOdelMap implements Model{} ? ? ? //繼承了ModelMap又實現(xiàn)了Model接口
? - public class BindingAwareModelMap{} ?//這個類對應的子類,就可以去實例化ModelMap也可以實例化Model
? ? - //因為ModelMap繼承了LinkedHashMap所以說,BindingAwareModelMap也可以實例化Map集合
?

4、Thymeleaf 頁面代碼如下

src/main/resources/templates/index.html

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="renderer" content="webkit">
    <title>首頁</title>
    <link rel="shortcut icon" th:href="@{/favicon.ico}"/>
    <link th:href="@{/static/css/bootstrap.min.css}" rel="stylesheet"/>
    <link th:href="@{/static/css/font-awesome.min.css}" rel="stylesheet"/>
</head>
<body class="fixed-sidebar full-height-layout gray-bg" style="overflow:hidden">
<div id="wrapper">
    <h1 th:text="${msg}"></h1>
    <p data-th-text="${msg}">test p</p>
    <p th:inline="text">p:[(${msg})]</p>
</div>
<h2>
    <p>Name: <span th:text="${user.uid}">Jack</span>.</p>
    <p>Age: <span th:text="${user.umc}">21</span>.</p>
    <p>friend: <span th:text="${user.etel}">Rose</span>.</p>
</h2>

<script th:src="@{/static/js/jquery.min.js}"></script>
<script th:src="@{/static/js/bootstrap.min.js}"></script>
<script>
</script>

</body>
</html>

5、訪問頁面

http://localhost:8092/index

http://localhost:8092/index?id=test

二、Thymeleaf 使用教程

Thymeleaf 模板引擎具有以下特點:
動靜結(jié)合:Thymeleaf 既可以直接使用瀏覽器打開,查看頁面的靜態(tài)效果,也可以通過 Web 應用程序進行訪問,查看動態(tài)頁面效果。
開箱即用:Thymeleaf 提供了 Spring 標準方言以及一個與 SpringMVC 完美集成的可選模塊,可以快速的實現(xiàn)表單綁定、屬性編輯器、國際化等功能。
多方言支持:它提供了 Thymeleaf 標準和 Spring 標準兩種方言,可以直接套用模板實現(xiàn) JSTL、 OGNL 表達式;必要時,開發(fā)人員也可以擴展和創(chuàng)建自定義的方言。
與 SpringBoot 完美整合:SpringBoot 為 Thymeleaf 提供了的默認配置,并且還為 Thymeleaf 設(shè)置了視圖解析器,因此 Thymeleaf 可以與 Spring Boot 完美整合。

1、在頁面的 html 標簽中聲明名稱空間

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

在 html 標簽中聲明此名稱空間,可避免編輯器出現(xiàn) html 驗證錯誤,但這一步并非必須進行的,即使我們不聲明該命名空間,也不影響 Thymeleaf 的使用。

把html 的名稱空間,改成:xmlns:th="http://www.thymeleaf.org" 會有語法提示

2、標準表達式語法

Thymeleaf的主要作用是把model中的數(shù)據(jù)渲染到html中,因此其語法主要是如何解析model中的數(shù)據(jù)。通過${}來獲取model中的變量,注意這不是el表達式,而是ognl表達式,但是語法非常像。

Thymeleaf崇尚自然模板,意思就是模板是純正的html代碼,脫離模板引擎,在純靜態(tài)環(huán)境也可以直接運行?,F(xiàn)在如果我們直接在html中編寫 ${}這樣的表達式,顯然在靜態(tài)環(huán)境下就會出錯,這不符合Thymeleaf的理念。

<h1>
    歡迎您:<span th:text="${user.name}">請登錄</span>
</h1>

靜態(tài)情況下,th指令不會被識別,而是顯示默認值:請登錄?

但是瀏覽器也不會報錯,把它當做一個普通屬性處理。這樣span的默認值請登錄就會展現(xiàn)在頁面
如果是在Thymeleaf環(huán)境下,th指令就會被識別和解析,而th:text的含義就是替換所在標簽中的文本內(nèi)容,于是user.name的值就替代了 span中默認的請登錄

如果不支持這種th:的命名空間寫法,那么可以把th:text換成 data-th-text,Thymeleaf也可以兼容。

th:text指令出于安全考慮,會把表達式讀取到的值進行處理,防止html的注入。

例如,<p>你好</p>將會被格式化輸出為$lt;p$gt;你好$lt;/p$lt;。

如果想要不進行格式化輸出,而是要輸出原始內(nèi)容,則使用th:utext來代替.

?Thymeleaf中所有的表達式都需要寫在指令中,指令是HTML5中的自定義屬性,在Thymeleaf中所有指令都是以th:開頭。因為表達式${user.name}是寫在自定義屬性中,因此在靜態(tài)環(huán)境下,表達式的內(nèi)容會被當做是普通字符串,瀏覽器會自動忽略這些指令,這樣就不會報錯了!

<h2>
    <p>Name: <span th:text="${user.name}">Jack</span>.</p>
    <p>Age: <span th:text="${user.age}">21</span>.</p>
    <p>friend: <span th:text="${user.friend.name}">Rose</span>.</p>
</h2>

對象.屬性名方式?

${user.name} 可以寫作${user['name']}

<h2 th:object="${user}">
    <p>Name: <span th:text="*{name}">Jack</span>.</p>
    <p>Age: <span th:text="*{age}">21</span>.</p>
    <p>friend: <span th:text="*{friend.name}">Rose</span>.</p>
</h2>

?當數(shù)據(jù)量比較多的時候,頻繁的寫user.就會非常麻煩。

首先在 h2上 用 th:object="${user}"獲取user的值,并且保存
然后,在h2內(nèi)部的任意元素上,可以通過 *{屬性名}的方式,來獲取user中的屬性,這樣就省去了大量的user.前綴了

<h2 th:object="${user}">
    <p>FirstName: <span th:text="*{name.split(' ')[0]}">Jack</span>.</p>
    <p>LastName: <span th:text="*{name.split(' ')[1]}">Li</span>.</p>
</h2>

ognl表達式本身就支持方法調(diào)用?

?Thymeleaf中提供了一些內(nèi)置對象,并且在這些對象中提供了一些方法,方便我們來調(diào)用。獲取這些對象,需要使用#對象名來引用。

一些環(huán)境相關(guān)對象
對象 ? ?作用
#ctx ? ?獲取Thymeleaf自己的Context對象
#requset ? ?如果是web程序,可以獲取HttpServletRequest對象
#response ? ?如果是web程序,可以獲取HttpServletReponse對象
#session ? ?如果是web程序,可以獲取HttpSession對象
#servletContext ? ?如果是web程序,可以獲取HttpServletContext對象
Thymeleaf提供的全局對象:
對象 ? ?作用
#dates ? ?處理java.util.date的工具對象
#calendars ? ?處理java.util.calendar的工具對象
#numbers ? ?用來對數(shù)字格式化的方法
#strings ? ?用來處理字符串的方法
#bools ? ?用來判斷布爾值的方法
#arrays ? ?用來護理數(shù)組的方法
#lists ? ?用來處理List集合的方法
#sets ? ?用來處理set集合的方法
#maps ? ?用來處理map集合的方法

?java代碼:

@GetMapping("show3")
public String show3(Model model){
    model.addAttribute("today", new Date());
    return "show3";
}

頁面代碼:?

<p>
  今天是: <span th:text="${#dates.format(today,'yyyy-MM-dd')}">2018-04-25</span>
</p>

${#strings.equals('編程幫',name)}

${#session.getAttribute('map')}
${session.map}

字面值:

基本類型如:字符串、數(shù)值、布爾等,并不希望被Thymeleaf解析為變量,這個時候稱為字面值

字符串字面值:th:text="'thymeleaf'" 使用一對'引用的內(nèi)容

數(shù)字字面值:th:text="2018" 數(shù)字不需要任何特殊語法, 寫的什么就是什么,而且可以直接進行算術(shù)運算

布爾字面值:th:if="true"

空字面值:<p th:text="${user == null}"></p>

<p>
? 你正在觀看 <span th:text="'thymeleaf'">template</span> 的字符串常量值.
</p>

拼接
我們經(jīng)常會用到普通字符串與表達式拼接的情況:

<span th:text="'歡迎您:' + ${user.name} + '!'"></span>

?字符串字面值需要用'',拼接起來非常麻煩,Thymeleaf對此進行了簡化,使用一對|即可:

<span th:text="|歡迎您:${user.name}|"></span>

運算

<span th:text="${user.age}"></span>
<span th:text="${user.age}%2 == 0"></span>

支持的算術(shù)運算符:+ - * / %

支持的比較運算:>, <, >= and <=

但是>, <不能直接使用,因為xml會解析為標簽,要使用別名。

注意 == and !=不僅可以比較數(shù)值,類似于equals的功能。

可以使用的別名:gt (>), lt (<), ge (>=), le (<=), not (!). Also eq (==), neq/ne (!=).

三元運算:<span th:text="${user.sex} ? '男':'女'"></span>

默認值:?<span th:text="${user.name} ?: '二狗'"></span>?( ?:之間沒有空格 )

${}內(nèi)部的是通過OGNL表達式引擎解析的,外部的才是通過Thymeleaf的引擎解析,因此運算符盡量放在${}外進行。?

設(shè)置屬性值

在 Thymeleaf 模板文件中,你可以使用th:*(或者使用th:attr屬性)來設(shè)置任意的 HTML5 標簽屬性的值。不僅如此,你還可以th:*-*來同時為多個不同的標簽屬性設(shè)置相同的一個值,甚至你可以使用th:attrappendth:attrprepend來追加新的值到現(xiàn)有的標簽屬性值中。

th:attr 這種方式是不被推薦的

<!-- <div item-id="1001">Welcome to BeiJing!</div> -->
<div th:item-id="${user.id}">Welcome to BeiJing!</div>

<img src="logo.png" th:alt-title="LOGO圖片">

th:*? 中的*可以是 HTML5 支持的任意屬性名稱,甚至這些屬性名稱可以是自定義的

th:*-*?如果想要同時為標簽的多個不同屬性設(shè)置相同的一個值,可以使用th:*-*的語法:

th:attrappend & th:attrprepend? 可以將表達式的結(jié)果分別追加到指定的屬性值之后和之前。

<!-- <button class="btn enable">購買</button> -->
<button class="btn" th:attrappend="class=${outOfStock} ? ' enable' : ' disable'">購買</button>
<!-- <button class="enable btn">購買</button> -->
<button class="btn" th:attrprepend="class=${outOfStock} ? 'enable ' : 'disable '">購買</button>

還有兩個常用的具體附加屬性th:classappend="..."th:styleappend=""。它們分別用來代替th:attrappend="class=..."th:attrappend="style=..."

<!-- <button class="btn enable">購買</button> -->
<button class="btn" th:classappend="${outOfStock} ? ' enable' : ' disable'">購買</button>

?循環(huán)/IF/SWITCH

<tr th:each="user : ${users}">
    <td th:text="${user.name}">Onions</td>
    <td th:text="${user.age}">2.41</td>
</tr>

<tr th:each="user,stat : ${users}">
    <td th:text="${user.name}">Onions</td>
    <td th:text="${user.age}">2.41</td>
</tr>

?stat對象包含以下屬性:

index,從0開始的角標
count,元素的個數(shù),從1開始
size,總元素個數(shù)
current,當前遍歷到的元素
even/odd,返回是否為奇偶,boolean值
first/last,返回是否為第一或最后,boolean值

<div th:switch="${user.role}">
  <p th:case="'admin'">用戶是管理員</p>
  <p th:case="'manager'">用戶是經(jīng)理</p>
  <p th:case="*">用戶是別的玩意</p>
</div>

?JS模板

<script th:inline="javascript">
    const user = /*[[${user}]]*/ {};
    const age = /*[[${user.age}]]*/ 20;
    console.log(user);
    console.log(age)
</script>

在script標簽中通過th:inline="javascript"來聲明這是要特殊處理的js腳本

語法結(jié)構(gòu):

const user = /*[[Thymeleaf表達式]]*/ "靜態(tài)環(huán)境下的默認值";

因為Thymeleaf被注釋起來,因此即便是靜態(tài)環(huán)境下, js代碼也不會報錯,而是采用表達式后面跟著的默認值。

鏈接表達式?@{}

@{}是專門用來處理 URL 鏈接地址的。
不管是靜態(tài)資源的引用,還是 form 表單的請求,凡是鏈接都可以用鏈接表達式 (@{...})。

鏈接表達式的形式結(jié)構(gòu)如下:

無參請求:@{/xxx}
有參請求:@{/xxx(k1=v1,k2=v2)}

絕對地址:?

<!-- https://fanlychie.github.io -->
<p th:text="@{https://fanlychie.github.io}"></p>

頁面相對地址示例:

<!-- commons/base.html -->
<p th:text="@{commons/base.html}"></p>

上下文相對地址(相對于當前的服務(wù))示例:

<!-- /css/mian.css -->
<p th:text="@{/css/mian.css}"></p>

服務(wù)器相對地址(相對于部署在同一個服務(wù)器中的不同服務(wù))示例:

<!-- /image/upload -->
<p th:text="@{~/image/upload}"></p>

參數(shù)使用示例:

<!-- /css/mian.css?v=1.0 -->
<p th:text="@{/css/mian.css(v=1.0)}"></p>
<!-- /user/order?username=fanlychie -->
<p th:text="@{/user/order(username=${session.user.name})}"></p>
<!-- /user/order?username=fanlychie&status=PAIED -->
<p th:text="@{/user/order(username=${session.user.name},status='PAIED')}"></p>
<!-- /user/fanlychie/info -->
<p th:text="@{/user/{username}/info(username=${session.user.name})}"></p>?

片段表達式

~{}可以用來引用一段公共的 HTML 代碼片段。

?在 Thymeleaf 模板文件中,你可以使用th:fragment屬性來定義一段公共的代碼片段,然后你可以通過使用th:insert、th:replace屬性來將這些公共的代碼片段引入到模板文件中來。

th:insert是直接將代碼片段插入到標簽體內(nèi)

th:replace則是用代碼片段直接替換標簽體內(nèi)容。

src/main/resources/templates/base.html,通過th:fragment屬性定義一段公共的代碼片段:

<div id="footer" th:fragment="footerFragment">&copy; 2017 fanlychie</div>

src/main/resources/templates/index.html,通過th:insert屬性引用一段公共的代碼片段:

<div th:insert="~{base :: footerFragment}"></div>
<div th:replace="~{base :: footerFragment}"></div>

(1)其中,~{}是可選的,我們可以去掉這層的包裹:

<div th:insert="base :: footerFragment"></div>

(2)若 index.html 與 base.html 不在同級目錄,如 templates/commons/base.html:

<div th:insert="~{commons/base :: footerFragment}"></div>

(3)使用th:fragment屬性定義代碼片段時,你還可以聲明一組參數(shù):
<div th:fragment="crumbs(parent, child)">
    <i th:text="${parent}"></i> <i th:text="${child}"></i>
</div>
    
<!--
<i>用戶中心</i>
<i>我的訂單</i>
-->
<div th:insert="::crumbs('用戶中心', '我的訂單')"></div>

三、Thymeleaf 實戰(zhàn)應用

1、input 、textarea 賦值

//JAVA
@RequestMapping(value = { "formData", "" })
public String list(HttpServletRequest request, ModelMap model) {
	Entity entity = xxxService.getEntity();
	model.addAttribute("entity", entity);
	return "test.html";
}
<!-- HTML -->
<input type="text" th:attr="name=${entity.name},required=${entity.propRequired}" placeholder="請輸入"/>
<textarea th:text="${entity.remarks=='null'?'':entity.remarks}" placeholder="請輸入"></textarea>

2.復選框 判斷選中

//JAVA
@RequestMapping(value = { "checkboxValue", "" })
public String list(HttpServletRequest request, ModelMap model) {
	Entity entity = xxxService.getEntity();
	model.addAttribute("entity", entity);
	return "test.html";
}
<input type="checkbox"  th:checked="${entity.prop1 eq '1'}"> aaa
<input type="checkbox"  th:checked="${entity.prop2 eq '1'}"> bbb

3.下拉框 動態(tài)賦值 與 回顯

//JAVA
@RequestMapping(value = { "selectList", "" })
public String list(HttpServletRequest request, ModelMap model) {
	List<selectData> selectList = xxxService.getSelectList();
	int type = xxxService.getType();
	model.addAttribute("type", type);
	model.addAttribute("selectList", selectList);
	return "test.html";
}
  • 下拉框數(shù)據(jù)填充
<select data-placeholder="請選擇"  id="selectData" >
   <option value=" " selected>請選擇</option>
   <option th:each="data:${selectList}" th:value="${data.id}" th:text="${data.name}"> </option>
</select>
  • 下拉框數(shù)據(jù)填充,判斷,回顯數(shù)據(jù)
<select>
	<option value=""  th:selected="${type eq ''}">請選擇</option>
	<option value="1" th:selected="${type eq 1}">字符型</option>
	<option value="2" th:selected="${type eq 2}">整型</option>
	<option value="3" th:selected="${type eq 3}">日期</option>
</select>
  • js設(shè)置下拉框選中,回顯數(shù)據(jù)
<script type="text/javascript">
    $("#selectData").ready(function() {
        var value= "[[${type}]]";
        $("#selectData option[value= " + value + "]").prop("selected",true);
    });
</script>

4.循環(huán)遍歷

@RequestMapping(value = { "loopTest", "" })
public String list(HttpServletRequest request, ModelMap model) {
	List<Entity> dataList = xxxService.getEntityList();
	Map<String,List<Entity>> dataMap = xxxService.getEntityMap();
	model.addAttribute("dataList", dataList);
	model.addAttribute("dataMap", dataMap);
	return "test.html";
}
  • 遍歷 list 數(shù)據(jù):循環(huán)生成表格數(shù)據(jù)
<table>
 <head>
 	<tr>
 		<th>ID</th>
		<th>名稱</th>
		<th>類型</th>
		<th>時間</th>
		<th>是否可用</th>
 </head>
 <body>
 	<tr th:each="data : ${dataList}" >
 		<td th:text="${data.id}"></td>
        <td th:text="${data.name}"></td>
 		<td th:switch="${data.type}">
   			<span th:case="1">字符型</span>
   			<span th:case="2">整型</span>
   			<span th:case="3">日期</span>
        </td>
        <td th:text="${#dates.format(data.createDate, 'yyyy-MM-dd HH:mm:ss')}"></td>
        <td>
   			<span th:if="${data.usable} eq '1'">
				<i class="fa fa-check"></i>
			</span>
        </td>
	</tr>
 </body>
</table>
  • 遍歷map數(shù)據(jù)
<div th:each="dataEntry,dataStat: ${dataMap}" >
	<div> [[${dataEntry.key}]] </div>
	<div th:each="data: ${dataEntry.value}">
		<div>
			<dt>[[${data.id}]]: </dt>
			<dd>[[${data.name}]]</dd>
		</div>							
	</div>
</div>

5.超鏈接 url傳參

@RequestMapping(value = { "formData", "" })
public String list(HttpServletRequest request, ModelMap model) {
	Entity entity = xxxService.getEntity();
	model.addAttribute("entity", entity);
	return "test.html";
}
<a th:href="@{test/form(id=${entity.id},name=${entity.name})}">超鏈接1</a>
<a th:href="@{test/form?id='+${entity.id}}+'&name='+${entity.name}">超鏈接2</a>

springboot配合thymeleaf,調(diào)用接口不跳轉(zhuǎn)頁面只顯示文本

問題一:thymeleaf不跳轉(zhuǎn)頁面,只顯示文本index

@RequestMapping("/excel")
@RestController
public class OperateExcelController {

    @GetMapping(value = "")
    public String index() {
        //使用@RestController不能直接返回return "index",否則不會跳轉(zhuǎn)頁面,只會再頁面顯示index文本而已
        return "index";
    }

@RestController注解相當于@ResponseBody和@Controller合在一起的作用。在使用@RestController注解Controller時,Controller中的方法無法返回jsp頁面,或者html,配置的視圖解析器 InternalResourceViewResolver不起作用,返回的內(nèi)容就是Return 里的內(nèi)容。

包括在Mapping注解使用的同時使用@ResponseBody時也會出現(xiàn)同樣的問題。

解決方案

解決辦法①:去除@ResponseBody或?qū)⒑蠷est的注解換成對應的原始注解@Controller;

@RequestMapping("/excel")
@Controller
public class OperateExcelController {
    @GetMapping(value = "")
    public String index() {
        return "index";
    }

?解決辦法②:不通過String返回,通過ModelAndView對象返回,上述例子可將return語句換成下面的句子,在使用ModelAndView對象返回的時候,不需要考慮有沒有@ResponseBody類似的注解。文章來源地址http://www.zghlxwxcb.cn/news/detail-482792.html

@RequestMapping("/excel")
@RestController
public class OperateExcelController {
    @GetMapping(value = "")
    public ModelAndView index() {
        return new ModelAndView("index");
    }

到了這里,關(guān)于SpringBoot 整合Thymeleaf教程及使用 springboot配合thymeleaf,調(diào)用接口不跳轉(zhuǎn)頁面只顯示文本的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔相關(guān)法律責任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • 【Springboot】SpringBoot基礎(chǔ)知識及整合Thymeleaf模板引擎

    【Springboot】SpringBoot基礎(chǔ)知識及整合Thymeleaf模板引擎

    ??博客x主頁:己不由心王道長??! ??文章說明:spring?? ?系列專欄:spring ??本篇內(nèi)容:對SpringBoot進行一個入門學習及對Thymeleaf模板引擎進行整合(對所需知識點進行選擇閱讀呀~)?? ??每日一語:在人生的道路上,即使一切都失去了,只要一息尚存,你就沒有絲毫理

    2023年04月23日
    瀏覽(24)
  • Thymeleaf詳細教程(SpringBoot版)

    Thymeleaf詳細教程(SpringBoot版)

    目錄 一、簡單介紹 二、引入依賴 三、創(chuàng)建頁面 3.1 關(guān)于靜態(tài)資源目錄相關(guān)(選看) 問題1:SpringBoot靜態(tài)資源目錄在哪里? 問題2:如何修改SpringBoot默認的靜態(tài)資源路徑? 問題3:如何給靜態(tài)資源添加訪問前綴? 問題4:添加全局前綴 3.2 創(chuàng)建文件模板(選看) 3.3?thymeleaf 簡單

    2024年02月11日
    瀏覽(15)
  • springboot整合security,mybatisPlus,thymeleaf實現(xiàn)登錄認證及用戶,菜單,角色權(quán)限管理

    springboot整合security,mybatisPlus,thymeleaf實現(xiàn)登錄認證及用戶,菜單,角色權(quán)限管理

    本系統(tǒng)為springboot整合security,mybatisPlus,thymeleaf實現(xiàn)登錄認證及用戶,菜單,角色權(quán)限管理。頁面為極簡模式,沒有任何渲染。 源碼:https://gitee.com/qfp17393120407/spring-boot_thymeleaf 架構(gòu)截圖 此處以用戶表為例,其他表數(shù)據(jù)可在源碼獲取。 用戶表 共用屬性 共用屬性自動填充配置

    2024年02月07日
    瀏覽(21)
  • SpringBoot自帶模板引擎Thymeleaf使用詳解①

    SpringBoot自帶模板引擎Thymeleaf使用詳解①

    目錄 前言 一、SpringBoot靜態(tài)資源相關(guān)目錄 二、變量輸出 2.1 在templates目錄下創(chuàng)建視圖index.html 2.2 創(chuàng)建對應的Controller 2.3 在視圖展示model中的值 三、操作字符串和時間 3.1 操作字符串 3.2 操作時間 ????????Thymeleaf是一款用于渲染XML/HTML5內(nèi)容的模板引擎,類似JSP。它可以輕易的

    2024年02月08日
    瀏覽(20)
  • SpringBoot自帶模板引擎Thymeleaf使用詳解②

    SpringBoot自帶模板引擎Thymeleaf使用詳解②

    目錄 一、條件判斷和迭代遍歷 1.1 條件判斷 2.2 迭代遍歷 二、獲取域中的數(shù)據(jù)和URL寫法 2.1 獲取域中的數(shù)據(jù) 2.2 URL寫法 三、相關(guān)配置 語法 作用 th:if 條件判斷 準備數(shù)據(jù) model.addAttribute(\\\"sex\\\",\\\"男\(zhòng)\\"); 使用實例 div ??? span th:if=\\\"${sex}==\\\'女\\\'\\\"這是女生/span ??? span th:if=\\\"${sex}==\\\'男\(zhòng)\\'\\\"這是男

    2024年02月08日
    瀏覽(17)
  • springboot項目開發(fā),使用thymeleaf前端框架的簡單案例

    springboot項目開發(fā),使用thymeleaf前端框架的簡單案例

    springboot項目開發(fā),使用thymeleaf前端框架的簡單案例!我們看一下,如何在springboot項目里面簡單的構(gòu)建一個thymeleaf的前端頁面。來完成動態(tài)數(shù)據(jù)的渲染效果。 第一步,我們在上一小節(jié),已經(jīng)提前預下載了對應的組件了。 如圖,springboot的強大之處就在于,它有一套完整的版本依

    2024年01月25日
    瀏覽(23)
  • Springboot 使用thymeleaf 服務(wù)器無法加載resources中的靜態(tài)資源異常處理

    Springboot 使用thymeleaf 服務(wù)器無法加載resources中的靜態(tài)資源異常處理

    Springboot使用thymeleaf,并 連接遠程數(shù)據(jù)庫 啟動時,無法加載resources中的靜態(tài)資源 瀏覽器報錯 后端啟動時報錯 前端打開頁面時后端報錯 打包編譯項目,顯示找不到j(luò)s、css、html等靜態(tài)資源,但本地路徑并沒有寫錯,于是我去找編譯文件,查看是不是靜態(tài)資源沒有編譯到,打開項

    2024年02月04日
    瀏覽(22)
  • SpringBoot Thymeleaf模板引擎

    SpringBoot Thymeleaf模板引擎

    前端交給我們的頁面,是 html 頁面。如果是我們以前開發(fā),我們需要把他們轉(zhuǎn)成jsp頁面,jsp好處就是當我們查出一些數(shù)據(jù)轉(zhuǎn)發(fā)到JSP頁面以后,我們可以用jsp輕松實現(xiàn)數(shù)據(jù)的顯示,及交互等。 jsp支持非常強大的功能,包括能寫Java代碼,但是呢,我們現(xiàn)在的這種情況,SpringBoot這

    2024年02月13日
    瀏覽(56)
  • 【SpringBoot】| Thymeleaf 模板引擎

    【SpringBoot】| Thymeleaf 模板引擎

    目錄 Thymeleaf 模板引擎 1. 第一個例子 2. 表達式 ①標準變量表達式 ②選擇變量表達式(星號變量表達式) ③鏈接表達式(URL表達式) 3. Thymeleaf的屬性 ①th:action ②th:method ③th:href ④th:src ⑤th:text ⑥th:style ⑦th:each (重點) ⑧條件判斷 if-unless ⑨switch-case 判斷語句 ⑩th:inline內(nèi)聯(lián)

    2024年02月08日
    瀏覽(21)
  • SpringBoot+thymeleaf實戰(zhàn)遇到的問題

    SpringBoot+thymeleaf實戰(zhàn)遇到的問題

    目錄 一、控制臺: 二、數(shù)據(jù)庫查詢異常: 三、前后端錯誤校驗 ?編輯 四、在serviceImp中需要添加一個eq條件,表示和數(shù)據(jù)庫中的哪個字段進行比較,否則會查出所有數(shù)據(jù),導致500 五、使用流轉(zhuǎn)換數(shù)據(jù)更簡潔 六、重復報錯,多次遇見 七、Mybatis使用,常見錯誤: 1.名字寫錯了

    2024年01月19日
    瀏覽(11)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包