Java 400带弹簧座的错误请求

Java 400带弹簧座的错误请求,java,spring,rest,Java,Spring,Rest,我有这样的春假服务 @RequestMapping(method = RequestMethod.POST, path = "/getdata", consumes = {"multipart/form-data"}, produces = MediaType.APPLICATION_JSON) public @ResponseBody Result getBarcode(@RequestParam("text") String sl,

我有这样的春假服务

@RequestMapping(method = RequestMethod.POST,
        path = "/getdata", consumes = {"multipart/form-data"}, produces =     MediaType.APPLICATION_JSON)
public
@ResponseBody
Result getBarcode(@RequestParam("text") String sl,
                  @RequestParam("imageFile") MultipartFile file)  {
                ... some logic
     return new Result(text, message, !processingError);
 }
当我从http表单调用它时,它工作正常并返回json文本。但是当我试图从java代码调用它时

RestTemplate restTemplate = new RestTemplate();
    MultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
    map.add("text", "123");
    map.add("imageFile", new File("...path to file..."));
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.MULTIPART_FORM_DATA);
      headers.setAccept(MediaType.parseMediaTypes("application/json,text/html,application/xhtml+xml,application/xml"));
    HttpEntity<MultiValueMap<String, Object>> requestEntity = new  HttpEntity<>(map, headers);
    ResponseEntity<BcResult> response = restTemplate.exchange("http://localhost:8080/getdata", HttpMethod.POST, requestEntity, BcResult.class);
RestTemplate RestTemplate=new RestTemplate();
MultiValueMap=新链接的MultiValueMap();
地图。添加(“文本”、“123”);
添加(“imageFile”,新文件(“…文件路径…”);
HttpHeaders=新的HttpHeaders();
headers.setContentType(MediaType.MULTIPART\u FORM\u DATA);
setAccept(MediaType.parseMediaTypes(“application/json,text/html,application/xhtml+xml,application/xml”);
HttpEntity requestEntity=新的HttpEntity(映射、头);
ResponseEntity response=restTemplate.exchange(“http://localhost:8080/getdata,HttpMethod.POST,requestEntity,BcResult.class);

然后我得到了400个错误请求错误。无法找出此代码的错误…

将文件设置为这样

 map.add("imageFile", new FileSystemResource(new File("...path to file...")));
还是像这样

map.add("imageFile", new ClassPathResource("...path to file..."));

像这样设置文件

 map.add("imageFile", new FileSystemResource(new File("...path to file...")));
还是像这样

map.add("imageFile", new ClassPathResource("...path to file..."));

删除使用多部分/表单数据无效。遇到同样的错误你检查过这个解决方案吗?删除使用多部分/表单数据无效。遇到同样的错误你检查过这个解决方案吗?谢谢。它起作用了!!:)谢谢。它起作用了!!:)