thymeleaf中前后端數(shù)據(jù)交互方法匯總
1. 引入靜態(tài)資源:th:href或th:scr+@{/從static目錄開始}
<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>書籍管理</title> </head>
2.前端將數(shù)據(jù)綁定到后端對象:*{對象屬性},前端引用后端數(shù)據(jù)${對象屬性}
<div class="form-group"> <label for="book_name" class="col-sm-2 control-label">書名:</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(由框架提供),前端使用${對象屬性}
@RequestMapping(value = "/create",method = RequestMethod.GET) public String createBookForm(ModelMap map){ map.addAttribute("book",book); map.addAttribute("action","create"); return BOOK_FORM; }
4.表單提交的注意點。
- action:表單中的內(nèi)容提交給哪個頁面進行處理,可能的取值:URL
- input元素:輸入框,由
type
決定類型。 - 觸發(fā)提交的動作:
- HTML DOM submit() 方法。
- type=submit
- button
到此這篇關(guān)于thymeleaf中前后端數(shù)據(jù)交互小結(jié)的文章就介紹到這了,更多相關(guān)thymeleaf前后端數(shù)據(jù)內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
java設(shè)計模式之建造者模式學(xué)習(xí)
建造者模式(Builder Pattern)主要用于“分步驟構(gòu)建一個復(fù)雜的對象”,在這其中“分步驟”是一個穩(wěn)定的算法,下面給出了詳細的示例2014-01-01Java實戰(zhàn)之小米交易商城系統(tǒng)的實現(xiàn)
這篇文章將利用Java實現(xiàn)小米交易商城系統(tǒng),文中采用的技術(shù)有:JSP?、Spring、SpringMVC、MyBatis等,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2022-04-04Java Jedis NOAUTH Authentication required問題解決方法
這篇文章主要介紹了Java Jedis NOAUTH Authentication required問題解決方法,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2019-07-07關(guān)于ObjectUtils.isEmpty()?和?null?的區(qū)別
這篇文章主要介紹了關(guān)于ObjectUtils.isEmpty()?和?null?的區(qū)別,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-02-02