SpringBoot2--增删查改

前言

采用Restful风格进行增删查改(CRUD)

一、映射规则

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

普通CRUD RestfulCRUD
查询 getEmp emp- - -GET
添加 addEmp?xxx emp- - -POST
修改 updateEmp?id=xxx&xx=xxx emp/{id}- - -PUT
删除 deleteEmp?id=xxx emp/{id}- - -DELETE

依据上面的原则,我们实验的请求架构如下:

实验功能 请求URI 请求方式
查询所有员工 emps GET
查询某个员工(来到修改页面) emp/1 GET
来到添加页面 emp GET
添加员工 emp POST
修改员工 emp PUT
删除员工 emp/1 DELETE

二、查询所有员工

1.发送请求th:href="@{/emps}"
<li class="nav-item">
       <a class="nav-link"
          href="#" th:href="@{/emps}">
           <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-users">
               <path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"></path>
               <circle cx="9" cy="7" r="4"></circle>
               <path d="M23 21v-2a4 4 0 0 0-3-3.87"></path>
               <path d="M16 3.13a4 4 0 0 1 0 7.75"></path>
           </svg>
           员工管理
       </a>
 </li>
2.处理请求
	//查询所有员工
	@GetMapping("/emps")
	public String list(Model model){
   
		Collection<Employee> employees = employeeDao.getAll();
		model.addAttribute("emps",employees);
        //模板引擎默认的解析器
		return "emp/list";
	}
3.显示页面
<table class="table table-striped table-sm">
	<thead>
		<tr>
			<th>#</th>
			<th>lastName</th>
			<th>email</th>
			<th>gender</th>
			<th>department</th>
			<th>birth</th>
			<th>操作</th>
		</tr>
	</thead>
                      
    <tbody>
	    <tr th:each="emp:${emps}">
			<td th:text=
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值