thymeleaf示例

 1.组件封装

th:fragment="topbar"

2.组件使用并携带数据

<div th:insert="~{commons/commons::sidebar(active='list.html')}"></div>

3.导航选中高亮,通过步骤2

<a th:class="${active=='main.html'?'nav-link active':'nav-link'}" th:href="@{/index.html}">

4.表单展示

  • 数据遍历:
<tr th:each="emp:${emps}">
  • 性别转换:
<td th:text="${emp.getGender()==0?'女':'男'}"></td>
  • 日期格式化:
<td th:text="${#dates.format(emp.getBirth(),'yyyy-MM-dd HH:mm:ss')}"></td>
<!--顶部导航栏-->
		<div th:insert="~{commons/commons::topbar}"></div>

		<div class="container-fluid">
			<div class="row">
<!--				侧边栏-->
<!--				插入组件~{页面名::组件名}-->
<!--				通过组件传参显示高亮-->
				<div th:insert="~{commons/commons::sidebar(active='list.html')}"></div>



				<main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">
					<h2>Section title</h2>
					<div class="table-responsive">
						<table class="table table-striped table-sm">
							<thead>
								<tr>
									<th>id</th>
									<th>lastName</th>
									<th>email</th>
									<th>gender</th>
									<th>department</th>
									<th>birth</th>
									<!--我们还可以在显示的时候带一些操作按钮-->
									<th>操作</th>
								</tr>
							</thead>
							<tbody>
								<tr th:each="emp:${emps}">
									<td th:text="${emp.getId()}"></td>
									<td th:text="${emp.getLastName}"></td>
									<td th:text="${emp.getEmail()}"></td>
<!--									性别表单-->
									<td th:text="${emp.getGender()==0?'女':'男'}"></td>
									<td th:text="${emp.getDepartment().getDepartmentName()}"></td>
<!--									时间格式化-->
									<td th:text="${#dates.format(emp.getBirth(),'yyyy-MM-dd HH:mm:ss')}"></td>
									<td>
										<button class="btn-sm btn-primary">编辑</button>
										<button class="btn-sm btn-danger">删除</button>
									</td>
								</tr>
							</tbody>
						</table>
					</div>
				</main>
			</div>
		</div>

5.rf风格传递对象属性

<a class="btn-sm btn-primary" th:href="@{/emp/}+${emp.getId()}">编辑</a>

6.单选框回显

<div class="form-check form-check-inline">
								<input th:checked="${emp.getGender()==1}"  class="form-check-input" type="radio" name="gender" value="1">
								<label class="form-check-label">男</label>
							</div>
							<div class="form-check form-check-inline">
								<input th:checked="${emp.getGender()==0}" class="form-check-input" type="radio" name="gender" value="0">
								<label class="form-check-label">女</label>
							</div>

7.多选框回显

<select class="form-control" name="department.id">
								<option th:each="dept:${departments}" th:selected="${dept.getId()==emp.getDepartment().getId()}" th:text="${dept.getDepartmentName()}" th:value="${dept.getId()}"></option>
							</select>

 8.前端格式化日期

<div class="form-group">
							<label>Birth</label>
							<input th:value="${#dates.format(emp.getBirth(),'yyyy-MM-dd HH:mm:ss')}" type="text" class="form-control" name="birth" placeholder="2019/1/1">
						</div>

9.后端格式化日期

  
spring:
    mvc:
        format:
          date: yyyy-MM-dd

10.修改编写id隐藏域

<input type="hidden" name="id" th:value="${emp.getId()}">

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

LI JS@你猜啊

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值