客户端到服务器在 RequestBody 中使用字符串效果很好。
@RequestMapping(method = RequestMethod.POST,value = "/createSessions",
produces = { "application/json", "multipart/related", "application/problem+json" },
consumes = { "application/json", "multipart/related","multipart/mixed"})
public ResponseEntity<SessionData> testSessions(Request jettyRequest, Map<String, List<String>> httpHeaderMap, @RequestBody String sessionCreateDataMultiPart) {
Response response = null;
try {
MimeMultipart mimeMultipart = new MimeMultipart(new ByteArrayDataSource(multipartData, "multipart/related"));
for (int i = 0; i < mimeMultipart.getCount(); i++) {
BodyPart bodyPart = mimeMultipart.getBodyPart(i);
log.info("MultiPart: ", bodyPart);
log.info("MultiParts: ", bodyPart);
}
} catch (Exception e) {
e.printStackTrace();
}
}
客户端到服务器在RequestPart中使用Java对象无法解析。
@RequestMapping(method = RequestMethod.POST,value = "/createSessions",
produces = { "application/json", "multipart/related", "application/problem+json" },
consumes = { "application/json", "multipart/related","multipart/mixed"})
public ResponseEntity<SessionData> testSessions(Request jettyRequest, Map<String, List<String>> httpHeaderMap, @RequestPart SessionCreateDataMultiPart sessionCreateDataMultiPart) {
Response response = null;
try {
MimeMultipart mimeMultipart = new MimeMultipart(new ByteArrayDataSource(multipartData, "multipart/related"));
for (int i = 0; i < mimeMultipart.getCount(); i++) {
BodyPart bodyPart = mimeMultipart.getBodyPart(i);
log.info("MultiPart: ", bodyPart);
log.info("MultiParts: ", bodyPart);
}
} catch (Exception e) {
e.printStackTrace();
}
}