Java file import interface multi-parameter writing method
The POST method supports receiving both file streams and other parameters.
Use the form method to transmit, please note that other parameters need to be used@RequestPartAnnotation is used to receive, because in the post method, the form transmission uses @RequestParam to receive the json format, which is regarded as a string type by default, and the interface cannot map the corresponding entity class.
@RequestParam relies on Converter or PropertyEditor for data parsing. @RequestPart refers to the 'Content-Type' header and relies on HttpMessageConverters for data parsing.
/**
* 批量导入
*
* @param file 文件
* @param labelList 绑定标签(非必传)
*/
@PostMapping("/import")
public void importExcel(@RequestParam("file") MultipartFile file, @RequestPart(value = "labelList", required = false) List<EntLabel> labelList) {
keyEntService.importExcel(file, labelList);
}
Interface testing
You need to specify the parameter type (Content Type) when requesting, json is application/json, file stream is multipart/form-data