以下是我的表格
<form action="/children/${childDetails.person.id}/uploadchildPhotograph"
method="POST"
enctype="multipart/form-data">
<input type="file" name="photograph" />
</form>
在控制器中我写下面的代码
@RequestMapping(value="/{id}/uploadchildPhotograph", method=RequestMethod.POST)
public ResponseEntity<String> uploadPhotograph(@PathVariable("id") Long childId, @RequestParam("photograph") GMultipartFile childPhoto )
{
ICCUserDetails userDetails = null;
try {
userDetails = usersService.getUserDetailsFromContext();
} catch (ICCUserNotLoggedInException e) {
return new ResponseEntity<String>(HttpStatus.UNAUTHORIZED);
}
if (ChildService.doesUserHaveAccessToChild(userDetails,childId)== true){
byte[] incomingImageData = childPhoto.getBytes();
ImagesService imageService = ImagesServiceFactory.getImagesService();
Image incomingImage = ImagesServiceFactory.makeImage(incomingImageData);
com.google.appengine.api.images.Transform transform = ImagesServiceFactory.makeResize(87, 119);
Image storedImage = imageService.applyTransform(transform, incomingImage);
byte[] storedImageData = storedImage.getImageData();
Person child = Person.findPerson(childId);
log.info("child Id is"+childId);
if (child == null)
return new ResponseEntity<String>(HttpStatus.NOT_FOUND);
Blob blob = new Blob(storedImageData);
child.setPhotograph(blob);
child.setImageType(childPhoto.getContentType());
child.merge();
return new ResponseEntity<String>(HttpStatus.OK);
}else{
return new ResponseEntity<String>(HttpStatus.UNAUTHORIZED);
}
}
现在问题是这种方法有时会正常工作,有时它会发现错误404未找到&#34;。它无法调用控制器方法。我认为路径存在一些问题。