日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

[JAVAEE] Thymeleaf 基本语法: form相关标签

發布時間:2023/11/27 生活经验 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 [JAVAEE] Thymeleaf 基本语法: form相关标签 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
  • th:action 指定表單提交地址
  • th:value 給value屬性賦值
  • th:field 能自動生成id、name和value屬性

form表單示例

  • 運行結果
  • 更改數據
  • 點擊保存

控制器代碼:TestController.java
package com.example.demo.controller;import com.example.demo.bean.Student;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;import java.util.HashMap;
import java.util.Map;@Controller
public class TestController {@RequestMapping("/edit")public String edit(Model model) {Student s = new Student(2019001, "小明");model.addAttribute("stu", s);return "th/form";}@RequestMapping(value = "/save", method = RequestMethod.GET)@ResponseBodypublic Student save(Student stu) {return stu;    //代碼簡潔很多}
}
頁面代碼:form.html
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>form</title><link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/><script src="https://cdn.bootcss.com/jquery/2.1.1/jquery.min.js"></script><script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<form class="form-horizontal" th:action="@{/save}" method="get"><div class="form-group"><label for="id" class="col-sm-2 control-label">學號</label><div class="col-sm-5"><input type="text" class="form-control" id="id" name="id" th:value="${stu.id}" placeholder="請輸入學號"></div></div><div class="form-group"><label for="name" class="col-sm-2 control-label">姓名</label><div class="col-sm-5"><input type="text" class="form-control" id="name" name="name" th:value="${stu.name}" placeholder="請輸入姓名"></div></div><div class="form-group"><div class="col-sm-5 col-sm-offset-2"><button id="btn" class="btn btn-default" type="submit">保存</button></div></div>
</form></body>
</html>

總結

以上是生活随笔為你收集整理的[JAVAEE] Thymeleaf 基本语法: form相关标签的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。