thymeleaf对于HTML页面中关于文本框、下拉框、单选按钮赋值处理

记个笔记

EmployeeConotroller.java

    /**
     * 使用RestFul风格
     * @param id
     * @param model
     * @return
     */
    @RequestMapping("/toUpdate/{id}")
    public String toUpdate(@PathVariable("id") Integer id, Model model) {
        Department departments = departmentDao.getDepartmentsById(id);
        System.out.println(employeeDao.getEmployeeById(id)+"======>");
        Employee employee = employeeDao.getEmployeeById(id);
        employee.setDepartment(departments);
        model.addAttribute("emp",employee);
        Collection<Department> department = departmentDao.getDepartment();
        model.addAttribute("department",department);
        return "emp/update";
    }

update.html

	<body>
	<!--这里的侧边栏和头部都是获取的公共组件-->
		 <div th:replace="~{commons/commons::navbar}"></div>
		<div class="container-fluid">
			<div class="row"> 
				<!--侧边栏-->
				<div th:replace="~{commons/commons::sidebar}"></div>
				<!--主内容-->
				<main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">
					<h2>员工添加</h2>
					<form method="post" action="/add">
						<div class="form-group">
							<label>用户名:</label>
							<!--文本框的赋值-->
							<input type="text" class="form-control" placeholder="lastName" name="lastName" th:value="${emp.getLastName()}">
						</div>
						<div class="form-group">
							<label for="exampleInputEmail1">邮箱地址</label>
							<input type="email" class="form-control" id="exampleInputEmail1" placeholder="Email" name="email" th:value="${emp.getEmail()}">
						</div>
						<!--单选按钮的赋值-->
						<div class="form-group" th:value="${emp.getGender()}">
							<label class="radio-inline">
								<input type="radio" name="gender" id="inlineRadio1" th:checked="${emp.getGender()==1}"></label>
							<label class="radio-inline">
								<input type="radio" name="gender" id="inlineRadio2"  th:checked="${emp.getGender()==0}"></label>
						</div>
						<!--下拉框的取值赋值-->
						<div class="form-group">
							<select class="form-control" name="department.id">
								<option th:each="dept:${department}" th:value="${dept.getId()}"
										th:selected="${dept.getId()==emp.getDepartment().getId()}">[[${dept.getDepartmentName()}]]</option>
							</select>
						</div>
						<!--对于日期格式的处理-->
						<div class="form-group">
							<label>生日:</label>
							<input type="text" class="form-control" placeholder="birth" name="birth" th:value="${#dates.format(emp.getBirth(),'yyyy-MM-dd')}">
						</div>
						<button type="submit" class="btn btn-default">Submit</button>
					</form>
				</main>
			</div>
		</div>
 
	</body>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值