40、尚硅谷_SpringBoot_web开发-【实验】-员工添加-来到添加页面

本文介绍了一个使用Spring MVC实现的员工信息添加功能,包括添加页面展示、部门信息获取及员工信息提交流程。通过示例代码展示了如何在Web应用中实现CRUD中的创建(Create)操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

6)、CRUD-员工添加

@Controller
public class EmployeeCtrl {

    @Autowired
    EmployeeDao dao;
    @Autowired
    DepartmentDao departmentDao;
    //列出所有员工
    @GetMapping("/emps")
    public String list(Model model){
        Collection<Employee>   collection =  dao.getAll();
        model.addAttribute("emps",collection);
        return "employee/list";
    }


    //添加页面
    @GetMapping("/emp")
    public String addVide(Model model){
        //查询部门信息
        Collection<Department>  collection = departmentDao.getDepartments();
        model.addAttribute("deparms",collection);
        return "employee/add";
    }
}

添加页面

<body>
<div th:replace="commons/bar::nav"></div>

<div class="container-fluid"  >
	<div class="row">
        <div th:replace="commons/bar::#sidebar(activeUri='employee')"></div>

		<main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">
			<div class="table-responsive">
				<form>
					<div class="form-group">
						<label>LastName</label>
						<input type="text" class="form-control" placeholder="zhangsan">
					</div>
					<div class="form-group">
						<label>Email</label>
						<input type="email" class="form-control" placeholder="zhangsan@atguigu.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">
							<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">
							<label class="form-check-label"></label>
						</div>
					</div>
					<div class="form-group">
						<label>department</label>
						<select class="form-control">
							<option th:each="dep:${deparms}" th:value="${dep.id}" th:text="${dep.departmentName}">1</option>
						</select>
					</div>
					<div class="form-group">
						<label>Birth</label>
						<input type="text" class="form-control" placeholder="zhangsan">
					</div>
					<button type="submit" class="btn btn-primary">添加</button>
				</form>
			</div>
		</main>
	</div>
</div>
</body>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值