首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Spring Rest模板-删除操作失败,请求错误

Spring Rest模板-删除操作失败,请求错误
EN

Stack Overflow用户
提问于 2019-05-15 03:02:37
回答 1查看 78关注 0票数 1

我正在使用Spring Rest模板执行Delete操作。

我收到了400个坏请求。然而,同样的请求也适用于Postman。网址:http://localhost:8080/product-service/customer/123456/customer-items/US?productCode=A-124896

控制器代码:

     @DeleteMapping(value = "/customer/{customer-number}/customer-items/{country}", params = {"uline-item-number"} , produces = {"application/json"})

public ResponseEntity<Boolean> deleteCustomerItem( @PathVariable("customer-number") final String customerNumber, 
               @PathVariable("country") final String countryCode,
                @RequestParam("productCode") final String productCode) {
            try {
                return new ResponseEntity<>(appCustomerService.deleteCustomerItem(customerNumber, countryCode, productCode), HttpStatus.OK);
            } catch (Exception e) {
                logger.error(e.getMessage(), e);
                return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
            }
        }

服务实施:

public Boolean deleteCustomerItem(String customerNumber, String countryCode, String productCode)
            throws Exception{
        Map<String, String> uriVariables = new HashMap<>();
        uriVariables.put("productCode", productCode);
        String productUrl = http://localhost:8080/product-service/customer/123456/customer-items/US";
        try {
            restTemplate.exchange(productUrl , HttpMethod.DELETE, HttpEntity.EMPTY, Void.class, uriVariables);
            return true;
        } catch (Exception e) {
            throw new Exception(e.getMessage());
        }
    }

我在请求中遗漏了什么吗?请帮助我解决此问题。

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56136952

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档