[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相关标签相关推荐
- [JAVAEE] Thymeleaf 基本语法:常用表达式
Thymeleaf 基本语法 常用表达式 变量表达式 ${ } 使用方法:th:xx = "${ }" 获取对象属性值给 th:xx . 后台代码: Student s=new S ...
- [JAVAEE] Thymeleaf 基本语法: 迭代循环
th:each 遍历集合 基本语法: <div th:each="变量名 : 集合"> <p th:text="${变量名}">< ...
- thymeleaf模板html a标签,Thymeleaf常用语法:模板片断
Thymeleaf常用语法:模板片断 系统中的很多页面有很多公共内容,例如菜单.页脚等,这些公共内容可以提取放在一个称为"模板片断"的公共页面里面,其它页面可以引用这个 " ...
- body中的相关标签
body中的相关标签,主要展现在页面的内容区域. 学习<hx>标签,为你的网页添加标题 比如打开一个百度新闻的网站,https://baijiahao.baidu.com/s?id=170 ...
- Thymeleaf基础语法
Thymeleaf基础语法 今天学习一下Thymeleaf的基础语法. 1-引入Thymeleaf 首先,将view层页面中的html标签进行修改,然后在View层页面文件的其它标签里使用th:*动态 ...
- python 全栈开发,Day45(html介绍和head标签,body标签中相关标签)
python 全栈开发,Day45(html介绍和head标签,body标签中相关标签) 一.html介绍 1.web标准 web准备介绍: w3c:万维网联盟组织,用来制定web标准的机构(组织) ...
- html中头部相关标签(<head>)基本概念
头部相关标签基本概念 1 头部相关标签 1.1 title标签 1.2 meta标签 1.3 link标签 1.4 style标签 2 相关选择题及参考答案 2.1 选择题 2.2 参考答案 1 头部 ...
- 网页入门D2-HTML语法与基础标签练习
HTML语法与基础标签 练习总结 写在前面:今天利用所学的HTML的语法和常用的HTML元素.实现在网页上显示图片.显示不同类型的文本以及实现页面跳转.(PS:HTML很多语法和写博客的markdow ...
- html标签详细讲解,HTML语法中的标签详细讲解1
对标签的总结: 头信息标签 主体内容标签 换行标签 水平线标签 居中对齐标签 字体标签 段落标签 格式化标签 引用标签 HTML注释语法 字符控制标签 标题文字标签 ~ 列表标签 . . table表 ...
最新文章
- Python程序设计 第六章 函数(续
- 11.2.0.2 asmcmd lsdg show incorrect diskgroup number
- 谈谈晋升-互联网民工篇
- nodejs: mkdirs 递归创建目录
- PHP 2014.5.21的总结:
- GW48CK/PK2/PK/PK4 系统万能接插口与结构图信号/与芯片引脚对照表
- es6 Class 的静态方法
- php oracle数据库连接池,数据库管理Oracle 连接池信息的修改
- netcore之hello
- 一个Android开发快速入门Flutter (一)
- 解决ajaxSubmit无法传递自动回填和下拉框的数据
- DeepStream:下一代智慧城市的视频分析
- ArcGIS:如何对要素类进行查询要素属性、更改符号、标记?
- 通过网络数据采集系统快速获得优质销售线索
- 平衡二叉树的原理及实现
- 免费的ASP.net2.0免费空间
- ubuntu下安裝搜狗輸入法
- EasyUI的Vue版本
- SQL中数据类型转换
- Deep Domain Confusion:Maximinzing for Domain Invariance阅读笔记
热门文章
- 2022-2028年中国领带行业投资分析及前景预测报告
- OpenCV 笔记(07)— Mat 对象输出格式设置(Python 格式、CSV 格式、NumPy 格式、C 语言格式)
- 【B/S实践】解决:vs中修改样式表后不起作用的问题
- python实现glove,gensim.word2vec模型训练实例
- TensorFlow用法
- PyTorch 进行 Neural-Transfer
- 基于ARM Cortex-M的SoC存储体系结构和实战
- 机器视觉系统的几个问题解析
- 大数据调度平台Airflow(一):什么是Airflow
- 2021年大数据Flink(二十三):​​​​​​​Watermaker案例演示