我对Spring的MyBatis很新,我遇到了这个错误。我正在尝试将图像上传到我的数据库,即MySQL
Failed to convert value of type 'java.lang.String' to required type 'org.springframework.web.multipart.commons.CommonsMultipartFile'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [org.springframework.web.multipart.commons.CommonsMultipartFile]: no matching editors or conversion strategy found
这是我的控制者:
@RequestMapping(value = "/GalleryResults", method = RequestMethod.GET)
public String insert(Model model,
@RequestParam(value = "photo", required = false) CommonsMultipartFile photo,
@RequestParam(value = "caseNo", required = false) String caseNo,
@RequestParam(value = "date", required = false) String date,
@RequestParam(value = "offenseIncident", required = false) String offenseIncident,
@RequestParam(value = "nameAKA", required = false) String nameAKA,
@RequestParam(value = "height", required = false) String height,
@RequestParam(value = "built", required = false) String built,
@RequestParam(value = "otherInfo", required = false) String otherInfo,
@RequestParam(value = "describedBy", required = false) String describedBy,
@RequestParam(value = "requestingParty", required = false) String requestingParty,
@RequestParam(value = "investOnCase", required = false) String investOnCase,
@RequestParam(value = "interviewer", required = false) String interviewer,
@RequestParam(value = "age", required = false) String age,
@RequestParam(value = "weight", required = false) String weight,
@RequestParam(value = "complexion", required = false) String complexion,
@RequestParam(value = "rating", required = false) String rating) {
try {
GalleryResults input = new GalleryResults();
input.setCaseNo(caseNo);
input.setDate(date);
input.setOffenseIncident(offenseIncident);
input.setNameAKA(nameAKA);
input.setHeight(height);
input.setBuilt(built);
input.setOtherInfo(otherInfo);
input.setDescribedBy(describedBy);
input.setRequestingParty(requestingParty);
input.setInvestOnCase(investOnCase);
input.setInterviewer(interviewer);
input.setAge(age);
input.setWeight(weight);
input.setComplexion(complexion);
input.setRating(rating);
input.setPhoto(photo);
input.setPhotoBytes(photo.getBytes());
input.setPhotoContentType(photo.getContentType());
input.setPhotoName(photo.getOriginalFilename());
galleryService.create(input);
} catch (Exception e) {
}
return "galleryResults";
}
我的POJO
private CommonsMultipartFile photo;
private byte[] photo;
private byte[] photoBytes;
private String photoName;
private String photoContentType;
我做错了什么吗?或者我错过了什么?
答案 0 :(得分:0)
当文件上传时,发送到Web服务器的HTTP请求就像
POST /someUrl
Content-Type: multipart/mixed
--edt7Tfrdusa7r3lNQc79vXuhIIMlatb7PQg7Vp
Content-Disposition: form-data; name="meta-data"
Content-Type: application/json; charset=UTF-8
Content-Transfer-Encoding: 8bit
{
"name": "value"
}
--edt7Tfrdusa7r3lNQc79vXuhIIMlatb7PQg7Vp
Content-Disposition: form-data; name="file-data"; filename="file.properties"
Content-Type: text/xml
Content-Transfer-Encoding: 8bit
... File Data ...
名为"文件数据"代表真实的文件数据流。它被转换为" MultipartFile"通过@RequestPart(" file-data")。处理上传逻辑的方法应该是这样的:
@RequestMapping("/../upload")
public void uploadFile(@RequestPart("file-data") MultipartFile uploadedFile, ..) {
......
}
答案 1 :(得分:0)
添加
的转换策略select Name_UM as EMPLOYEE from Universal_Master2 WHERE Module_UM='EMPL'
select Name_UM as BRANCH from Universal_Master2 WHERE Module_UM='Branch'
豆中的