当前位置:
首页 >
前端技术
> javascript
>内容正文
javascript
Spring boot添加员工页面跳转
生活随笔
收集整理的这篇文章主要介绍了
Spring boot添加员工页面跳转
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
页面跳转
单击添加按钮,跳转到添加页面
可以选择员工的公寓,需要把公寓信息传递过去
添加按钮
<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"><!--需要区分是员工修改还是添加;--><form th:action="@{/emp}" method="post"><!--发送put请求修改员工数据--><!--1、SpringMVC中配置HiddenHttpMethodFilter;(SpringBoot自动配置好的)2、页面创建一个post表单3、创建一个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重定向请求