Java 无法通过Spring MVC中的POJO类在resttemplate中发送多部分文件
我无法通过Java 无法通过Spring MVC中的POJO类在resttemplate中发送多部分文件,java,spring-boot,spring-mvc,resttemplate,spring-resttemplate,Java,Spring Boot,Spring Mvc,Resttemplate,Spring Resttemplate,我无法通过restemplate将MultipartFile以及POJO类中的其他文本数据发送到不同的API restTemplate调用方法 public String getBannerMngmntCreate(BannerView2 bannerView) { RestTemplate restTemplate = new RestTemplate(); String ROOT_URI = IPADDRESS + "bannerMngmnt
restemplate
将MultipartFile
以及POJO
类中的其他文本数据发送到不同的API
restTemplate调用方法
public String getBannerMngmntCreate(BannerView2 bannerView) {
RestTemplate restTemplate = new RestTemplate();
String ROOT_URI = IPADDRESS + "bannerMngmntcreate";
ResponseEntity<String> responseEntity = restTemplate.postForEntity(
ROOT_URI, bannerView, String.class);
String message = (String) responseEntity.getBody();
return message;
}
POJO类,包含多部分文件和其他与JSP页面映射的字段
@RequestMapping(value = "/bannerMngmntcreate", method = RequestMethod.POST)
public String createBannerMngmnt(@RequestBody BannerView2 bannerView,
BindingResult result) {
logger.info("createBannerMngmnt method***************");
if (result.hasErrors()) {
logger.info("createBannerMngmnt method***************Error********");
return "failure";
} else {
String response = bannerMgtService.getBannerMngmntCreate(bannerView);
return response;
}
}
import java.io.Serializable;
import org.springframework.web.multipart.MultipartFile;
public class BannerView2 implements Serializable{
private static final long serialVersionUID = 4557452205618821243L;
private Long id;
private String bannerName;
private String status;
private MultipartFile filePath;
private String bannerType;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getBannerName() {
return bannerName;
}
public void setBannerName(String bannerName) {
this.bannerName = bannerName;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public MultipartFile getFilePath() {
return filePath;
}
public void setFilePath(MultipartFile filePath) {
this.filePath = filePath;
}
public String getBannerType() {
return bannerType;
}
public void setBannerType(String bannerType) {
this.bannerType = bannerType;
}
}
但在网页中,我收到了以下错误:
白标错误页
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Mon May 10 18:04:29 IST 2021
There was an unexpected error (type=Internal Server Error, status=500).
Could not write JSON document: No serializer found for class java.io.FileDescriptor and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: pack123.pack321.view.BannerView2["filePath"]->org.springframework.web.multipart.support.StandardMultipartHttpServletRequest$StandardMultipartFile["inputStream"]->java.io.FileInputStream["fd"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class java.io.FileDescriptor and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: pack123.pack321.view.BannerView2["filePath"]->org.springframework.web.multipart.support.StandardMultipartHttpServletRequest$StandardMultipartFile["inputStream"]->java.io.FileInputStream["fd"])