Restful请求规范

请求规范

  1. 在开发供应商管理接口时,学习了Restful的请求规范。
  • GET:查询请求。

  • POST:新增请求。

  • PUT:更新请求。

  • DELETE:删除请求。

  1. 在PostMapping和PutMapping中要获取请求体中的数据必须使用@Requestbody
/**
    * 添加
    * @param dto
    * @return
    */
   @PostMapping
   public ResultDto<Integer> insert(@Validated @RequestBody LithiumElectricProductInsertOrUpdateDto dto){
   	return ResultUtil.success(service.insert(dto));
   }
  1. 使用@RequestParam获取get请求链接中的数据,使用@PathVariable获取url中的参数。
/**
	 * 停用
	 *
	 * @param id
	 * @return
	 */
	@PutMapping(value = "stopUsing/{id}")
	public ResultDto<Integer> stopUsing(@PathVariable("id") String id, @RequestParam("versionNo") Integer versionNo) {
		int status = Constant.SUPPLIER_STATUS_STOP;
		return ResultUtil.success(service.updateStatus(id, status, versionNo));
	}

前端请求格式

http://localhost:8001/base/supplier/stopUsing/100842?versionNo=18
posted @ 2020-12-24 12:11  小白白白白白白白白白  阅读(372)  评论(0编辑  收藏  举报