#author("2019-11-18T13:53:04+08:00","default:Admin","Admin") Thymeleaf

th:object

用于表单数据对象绑定,将表单绑定到后台controller的一个JavaBean参数。常与th:field一起使用进行表单数据绑定。

例如:

public class LoginBean implements Serializable{...}


@RequestMapping(value = "/login", method = RequestMethod.POST)

public String login(@ModelAttribute(value = "loginBean") LoginBean loginBean,ModelMap model) {...}

HTML

<form id="login-form" th:action="@{/login}" th:object="${loginBean}">...</form>

选择表达式

选择表达式选择的是th:object对象属性绑定的session.user对象中的属性。

<div th:object="${session.user}">
  <p>姓名:<span th:text="*{Name}">noodles</span></p>
  <p>年龄:<span th:text="*{age}">24</span></p>
  <p>国籍:<span th:text="*{nationlity}">中国</span></p>
</div>

上面这段代码相当于:

<div>
  <p>姓名:<span th:text="${session.user.Name}">noodles</span></p> 
  <p>年龄:<span th:text="${session.user.age}">24</span></p>
<p>国籍:<span th:text="${session.user.nationlity}">中国</span></p></div>

th:field

常用于表单字段绑定。通常与th:object一起使用。 属性绑定、集合绑定。

如:

public class LoginBean implements Serializable{...

private String username;

private List<User> user;

...}


public class User implements Serializable{...

private String username;;

...}


@RequestMapping(value = "/login", method = RequestMethod.POST)

public String login(@ModelAttribute(value = "loginBean") LoginBean loginBean,ModelMap model) {..}
<form id="login-form" th:action="@{/login}" th:object="${loginBean}">...

<input type="text" value="" th:field="*{username}"></input>

<input type="text" value="" th:field="*{user[0].username}"></input>

</form>

内联

<label for="body">Message body:</label>
<textarea id="body" name="body" th:inline="text">
Dear [[${customerName}]],

it is our sincere pleasure to congratulate your in your birthday:
    Happy birthday [[${customerName}]]!!!

See you soon, [[${customerName}]].

Regards,
    The Thymeleaf team
</textarea>

首先要在标签上声明:th:inline="text",和下面一样赋值时使用两个中括号

[[${customerName}]]
[[...]] 等价于 th:text
[(...)] 等价于 th:utext

内联js

<script type="text/javascript" th:inline="javascript">
    var result = /*[[${dataResult}]]*/;
</script>

这样就将后台返回的 dataResult 数据赋值给了 result ;

th:inline ="javascript" 只能在html文件中使用



中古車買取実績No.1ガリバー

コメント:



(画像の文字列を入力して下さい)

トップ   編集 凍結 差分 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2019/12/02 (月) 12:42:52 (1628d)

PCpዾyǗlgĂ܂}WŔ܂z 萔O~ył񂫁z Yahoo yV NTT-X Store

z[y[W ̃NWbgJ[h COiq ӂ邳Ɣ[ COsیI COze