1、调用者
@RestController
public class testFeign {
@Autowired
ProducerFeign producerFeign;
@PostMapping("/testFeign")
public Result testFeign(@RequestParam("file") MultipartFile file, @RequestParam("startRow")Integer startRow, @RequestParam("endRow")Integer endRow){
List<Map<String, Object>> maps = producerFeign.getFile(file, startRow, endRow);
return Result.success(maps);
}
}
2、被调用者
@RestController
public class ProducerController {
@Autowired
ExcelParseService excelParseService;
@PostMapping(path = "/getFileInfo")//RequestPart这里要用RequestPart接收参数
public List<Map<String, Object>> getFile(@RequestPart(required = true,name = "file") MultipartFile file,
@RequestParam("startRow")Integer startRow,
@RequestParam("endRow")Integer endRow) {
List<Map<String, Object>> result = excelParseService.parse(file, startRow, endRow);
return result;
}
}
3、Feign接口
@FeignClient(name = "producer")
//,configuration = FeignMultipartSupportConfig.class网上找到这样的配置去解决方案但是不加这个也能成功
public interface ProducerFeign {
@PostMapping(value = "/getFileInfo",consumes = {MediaType.MULTIPART_FORM_DATA_VALUE})//,consumes = {MediaType.MULTIPART_FORM_DATA_VALUE}这也是必须要加的,将调用此接口的请求参数转换成multipart/form-data格式
List<Map<String, Object>> getFile(@RequestPart(required = true,name = "file") MultipartFile file,//也要用@RequestPart接受参数
@RequestParam("startRow") Integer startRow,
@RequestParam("endRow") Integer endRow);
}