當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
Spring boot添加员工页面跳转
生活随笔
收集整理的這篇文章主要介紹了
Spring boot添加员工页面跳转
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
頁面跳轉
單擊添加按鈕,跳轉到添加頁面
可以選擇員工的公寓,需要把公寓信息傳遞過去
添加按鈕
<h2><a class="btn btn-sm btn-success" href="emp" th:href="@{/emp}">員工添加</a></h2>Controller
//來到員工添加頁面 @GetMapping("/emp") public String toAddPage(Model model) {//來到添加頁面,查出所有的部門,在頁面顯示Collection<Department> departments = departmentDao.getDepartments();model.addAttribute("depts", departments);return "emp/add"; }添加頁面
可以選擇用戶的公寓
<!--提交的是部門的id--> <select class="form-control" name="department.id"><option th:selected="${emp!=null}?${dept.id == emp.department.id}" th:value="${dept.id}" th:each="dept:${depts}" th:text="${dept.departmentName}">1</option> </select>頁面
<main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4"><!--需要區(qū)分是員工修改還是添加;--><form th:action="@{/emp}" method="post"><!--發(fā)送put請求修改員工數(shù)據(jù)--><!--1、SpringMVC中配置HiddenHttpMethodFilter;(SpringBoot自動配置好的)2、頁面創(chuàng)建一個post表單3、創(chuàng)建一個input項,name="_method";值就是我們指定的請求方式--><input type="hidden" name="_method" value="put" th:if="${emp!=null}"/><input type="hidden" name="id" th:if="${emp!=null}" th:value="${emp.id}"><div class="form-group"><label>LastName</label><input name="lastName" type="text" class="form-control" placeholder="zhangsan" th:value="${emp!=null}?${emp.lastName}"></div><div class="form-group"><label>Email</label><input name="email" type="email" class="form-control" placeholder="zhangsan@atguigu.com" th:value="${emp!=null}?${emp.email}"></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>department</label><!--提交的是部門的id--><select class="form-control" name="department.id"><option th:selected="${emp!=null}?${dept.id == emp.department.id}" th:value="${dept.id}" th:each="dept:${depts}" th:text="${dept.departmentName}">1</option></select></div><div class="form-group"><label>Birth</label><input name="birth" type="text" class="form-control" placeholder="zhangsan" th:value="${emp!=null}?${#dates.format(emp.birth, 'yyyy-MM-dd HH:mm')}"></div><button type="submit" class="btn btn-primary" th:text="${emp!=null}?'修改':'添加'">添加</button></form> </main>總結
以上是生活随笔為你收集整理的Spring boot添加员工页面跳转的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Spring boot添加员工
- 下一篇: Spring boot重定向请求