————————传统方式和RESTful对比——————————
传统方式操作资源
传统方式操作资源
查询,GET------ http://127.0.0.1/item/queryItem.action?id=1
新增,POST ------http://127.0.0.1/item/saveItem.action
更新,POST------ http://127.0.0.1/item/updateItem.action
删除,GET或POST------http://127.0.0.1/item/deleteItem.action?id=1
使用RESTful
使用RESTful
操作资源
查询,GET ------http://127.0.0.1/item/1
新增,POST ------http://127.0.0.1/item
更新,PUT ------http://127.0.0.1/item
删除,DELETE------http://127.0.0.1/item/1
————————下面由我带你了解RESTful—————————
一、搭建一个简单的SpringBoot项目
第1步:选择 Spring Initializer,点击next
第2步:自己编辑一个项目的名字,点击next
第3步:选择Web,选中Spring Web,点击next
第4步:点击Finish
二、在创建好的项目里添加一个类,把我下面的代码放进去就可以了
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/restfull")
public class Restfull {
/**
* 查询,GET
* @return
*/
@GetMapping()
public String getEmployee(){
return "restfull查询成功";
}
/**
* 新增,POST
* @return
*/
@PostMapping()
public String getEmployee1(){
return "restfull新增成功";
}
/**
* 更新,PUT
* @return
*/
@PutMapping()
public String getEmployee2(){
return "restfull更新成功";
}
/**
* 删除,DELETE
* @return
*/
@DeleteMapping()
public String getEmployee3(){
return "restfull删除成功";
}
}
三、查询结果展示
工具的使用和下载:点我