SpringBoot5-Restful风格CRUD

一、Restful风格CRUD

1.1 就是一种规范

都是emp/1,你发送get就执行查询,发送put就执行修改

SpringBoot5-Restful风格CRUD

以前像springmvc这样配置路径就不需要你做了

SpringBoot5-Restful风格CRUD

1.2 示例代码

1.2.1 查询

SpringBoot5-Restful风格CRUD

限定请求方式为get

SpringBoot5-Restful风格CRUD

SpringBoot5-Restful风格CRUD

转换日期格式

SpringBoot5-Restful风格CRUD

SpringBoot5-Restful风格CRUD

1.2.2 添加

1.2.2.1 添加前跳转查询(部门)

查询跳转,添加之前的准备,超链接为get

SpringBoot5-Restful风格CRUD

SpringBoot5-Restful风格CRUD

SpringBoot5-Restful风格CRUD

1.2.2.2 真正添加

用请求方式来区分

SpringBoot5-Restful风格CRUD

SpringBoot5-Restful风格CRUD

一定注意最后要重定向请求/emps的Controller,会自动跳转至查询页面,如果直接请求emps页面就什么数据都没有

SpringBoot5-Restful风格CRUD

配置日期转换,否则会按照国外的格式,报错

SpringBoot5-Restful风格CRUD

1.2.3 修改

SpringBoot5-Restful风格CRUD

@$两套语法,中间要用+隔开

SpringBoot5-Restful风格CRUD

SpringBoot5-Restful风格CRUD

以前c标签写法,按顺序排列

SpringBoot5-Restful风格CRUD

SpringBoot5-Restful风格CRUD

开启禁用的put和delete请求

SpringBoot5-Restful风格CRUD

SpringBoot5-Restful风格CRUD

1.2.4 删除

跟修改是一样的,要带一个参数过来

SpringBoot5-Restful风格CRUD

SpringBoot5-Restful风格CRUD

这个可以实现,但是每个数据都弄一个表单,网页负担太大,怎么改进?

通过动态绑定action,只写一个form表单就可以了

自定义一个属性delurl,把这个表单的action赋给它

SpringBoot5-Restful风格CRUD

通过js小技巧把这个delurl赋给delform表单的action属性

SpringBoot5-Restful风格CRUD