我是靠谱客的博主 拉长汽车,这篇文章主要介绍SpringBoot web--RestfulCRUD-demo-Restful风格(18),现在分享给大家,希望可以做个参考。

1、Restful CRUD:CRUD满足Rest风格

URI:/资源名称/资源标识        HTTP请求方式区分对资源CRUD操作


普通CRUD(uri来区分操作)Restful CRUD
查询getEmpemp--GET
添加addEmp?name=lucy&age=22emp--POST
修改updateEmp?id=1emp/{id}--PUT
删除deleteEmp?id=1emp/{id}--DELET


2、demo请求架构

请求URI请求方式
员工列表(查询所有员工)empsGET
提交添加员工empPOST
查询单一员工(进入修改页面)emp/1GET
修改保存员工empPUT
删除员工emp/1DELETE


3、 员工列表

thymeleaf公共页面元素抽取:

1、抽取公共片段


2、引入公共片段



    片段规范语法:

~{templatename :: selector}:模板名::选择器。包含在名称为templatename的模板上应用指定的标签选择器匹配的片段。

~{footer :: copy}:模板名::片段名。




4、把公共部分抽取一个页面中


引用方式:


5、链接高亮







6、显示数据




时间格式化:


详细,查看文档:https://download.csdn.net/download/yufang131/10420053

7、添加员工

1、列表页面添加一些操作按钮









复制代码
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
33
<h2>添加员工信息</h2> <form th:action="@{/user/emp}" method="post">  <div class="form-group"> <label for="exampleFormControlInput1">lastName</label> <input type="text" name="lastName" th:value="${emp!=null}?${emp.lastName}" class="form-control" placeholder="lily"> </div> <div class="form-group"> <label for="exampleFormControlInput1">Email address</label> <input type="email" name="email" th:value="${emp!=null}?${emp.email}" class="form-control" placeholder="name@example.com"> </div> <div class="form-group"> <label>Gender</label><br /> <div class="form-check form-check-inline"> <input class="form-check-input" type="radio" name="gender" value="1" th:checked="${emp!=null}?${emp.gender==1}"> <label class="form-check-label">男</label> </div> <div class="form-check form-check-inline"> <input class="form-check-input" type="radio" name="gender" value="0" th:checked="${emp!=null}?${emp.gender==0}"> <label class="form-check-label">女</label> </div> </div> <div class="form-group"> <label for="exampleFormControlSelect2">department</label> <select class="form-control" name="department.id"> <option th:each="dep : ${deps}" th:value="${dep.id}" th:text="${dep.departmentName}" th:selected="${emp!=null}?${dep.id == emp.department.id}"></option> </select> </div> <div class="form-group"> <label>Birth</label> <input type="text" name="birth" th:value="${emp!=null}?${#dates.format(emp.birth, 'yyyy/MM/dd HH:mm:ss')}" class="form-control" placeholder="2018/10/10" > </div> <button type="submit" class="btn btn-primary" th:text="${emp!=null}?'修改':'添加'">保存</button> </form>

8、修改员工


复制代码
1
2
<input type="hidden" name="_method" value="put" th:if="${emp!=null}" /> <input type="hidden" name="id" th:value="${emp.id}" th:if="${emp!=null}" />

9、删除员工信息





在第8步操作时,有一遗留的问题:添加新员工信息修改已有员工信息



感谢--尚硅谷


最后

以上就是拉长汽车最近收集整理的关于SpringBoot web--RestfulCRUD-demo-Restful风格(18)的全部内容,更多相关SpringBoot web--RestfulCRUD-demo-Restful风格(18)内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(61)

评论列表共有 0 条评论

立即
投稿
返回
顶部