您好,登錄后才能下訂單哦!
這篇“thymeleaf中前后端數(shù)據(jù)交互怎么實(shí)現(xiàn)”文章的知識(shí)點(diǎn)大部分人都不太理解,所以小編給大家總結(jié)了以下內(nèi)容,內(nèi)容詳細(xì),步驟清晰,具有一定的借鑒價(jià)值,希望大家閱讀完這篇文章能有所收獲,下面我們一起來(lái)看看這篇“thymeleaf中前后端數(shù)據(jù)交互怎么實(shí)現(xiàn)”文章吧。
1. 引入靜態(tài)資源:th:href或th:scr+@{/從static目錄開(kāi)始}
<html lang="en" xmlns:th="http://www.thymeleaf.org"> <head> <link th:href="@{/iamges/favicon.ico}" rel="external nofollow" type="image/x-icon"/> <link th:href="@{/css/bootstrap.min.css}" rel="external nofollow" rel="stylesheet"/> <meta charset="UTF-8"> <title>書(shū)籍管理</title> </head>
2.前端將數(shù)據(jù)綁定到后端對(duì)象:*{對(duì)象屬性},前端引用后端數(shù)據(jù)${對(duì)象屬性}
<div class="form-group"> <label for="book_name" class="col-sm-2 control-label">書(shū)名:</label> <div class="col-xs-4"> <input type="text" class="form-control" id="book_name" name="name" th:value="${book.name}" th:field="*{book.name}"/> </div> </div>
3.后端將數(shù)據(jù)傳入前端 ModelMap(由框架提供),前端使用${對(duì)象屬性}
@RequestMapping(value = "/create",method = RequestMethod.GET) public String createBookForm(ModelMap map){ map.addAttribute("book",book); map.addAttribute("action","create"); return BOOK_FORM; }
4.表單提交的注意點(diǎn)。
action:表單中的內(nèi)容提交給哪個(gè)頁(yè)面進(jìn)行處理,可能的取值:URL
input元素:輸入框,由type
決定類(lèi)型。
觸發(fā)提交的動(dòng)作:
HTML DOM submit() 方法。
type=submit
button
以上就是關(guān)于“thymeleaf中前后端數(shù)據(jù)交互怎么實(shí)現(xiàn)”這篇文章的內(nèi)容,相信大家都有了一定的了解,希望小編分享的內(nèi)容對(duì)大家有幫助,若想了解更多相關(guān)的知識(shí)內(nèi)容,請(qǐng)關(guān)注億速云行業(yè)資訊頻道。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。