Java 使用spring mvc restful服务提交包含图像的表单

Java 使用spring mvc restful服务提交包含图像的表单,java,spring,rest,spring-mvc,upload,Java,Spring,Rest,Spring Mvc,Upload,我想使用SpringMVC实现一个restful服务,前端是纯javascript restful服务正在提交一个包含图像的基本表单。我可以为DTO使用Java映像类型吗?大概是这样的: @Controller public class PersonController { @RequestMapping(value = "xxx/yyy", method = RequestMethod.POST) public void submitForm(@RequestBody PersonDto pe

我想使用SpringMVC实现一个restful服务,前端是纯javascript

restful服务正在提交一个包含图像的基本表单。我可以为DTO使用Java映像类型吗?大概是这样的:

@Controller
public class PersonController {
@RequestMapping(value = "xxx/yyy", method = RequestMethod.POST)
public void submitForm(@RequestBody PersonDto personDto) {
    String name = personDto.getName();
    int age = personDto.getAge();
    Image image = personDto.getImage();
    service.save(xxxx);
}
}

@XmlRootElement
public class PersonDto {
    private String name;
    private int age;
    ....
    private Image image;
}

我是否可以不使用MultipartFile上传图像而执行上述操作?我不确定什么时候会有请求,实际图像可以通过Spring MVC自动转换为Java图像类型?

我不认为您可以通过服务发送图像类型对象,或者您必须在PC上本地保存图像并通过服务发送图像位置并保存在某个位置,或者您必须像Base64图像编码器那样对图像进行编码,然后通过服务发送编码数据将该数据转换回Java服务要求在数据库中安装映像,而不是存储文件路径。然后,您可以在base64中使用第二个编码/解码选项,并将mage作为blob存储在DB中