springboot与servlet两者封装对象的方式
springboot的Controller层当中
1 |
|
addSuccess方法中使用Employee对象作为入参,在前端html代码的form表单中1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32<form th:action="@{/add}" method="post">
<div class="form-group">
<label class="col-sm-2 control-label">名字</label>
<div class="col-sm-10">
<input type="text" class="form-control" placeholder="请输入名字" name="name">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">邮箱</label>
<div class="col-sm-10">
<input type="text" class="form-control" placeholder="请输入邮箱" name="email">
</div>
</div>
<div class="form-group">
<label>部门</label>
<!-- 因为department是一个对象,传参的时候不能传一个对象,故先传对象的id值,然后后端接受了id值后,通过id值来查询department,并将查询到的department赋值给employee -->
<select class="form-control" name="department.id">
<option th:text="${department.getDepartmentName()}" th:each="department:${departments}" th:value="${department.getId()}"></option>
</select>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">日期</label>
<div class="col-sm-10">
<input type="text" class="form-control" placeholder="请输入日期" name="birth">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">添加</button>
</div>
</div>
</form>