Maven依赖:
<dependency>
<groupId>org.mongodb.morphia</groupId>
<artifactId>morphia</artifactId>
<version>1.1.0</version>
<exclusions>
<exclusion>
<artifactId>mongo-java-driver</artifactId>
<groupId>org.mongodb</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<artifactId>mongo-java-driver</artifactId>
<groupId>org.mongodb</groupId>
<version>3.0.2</version>
</dependency>
**Controller.java中的Mapping映射:
@RequestMapping(value = "/uploadFileToMongo")
public JSONMessage uploadFileToMongo(MultipartFile file, String id, String filename, String collection){
if (file != null && file.getName() != null && !file.isEmpty()) {
byte[] bytes=null;
try {
bytes = file.getBytes();
} catch (IOException e) {
e.printStackTrace();
}
MongoFileOperationUtil.saveFile(bytes ,id, filename, collection);
return JSONMessage.success();
} else {
return JSONMessage.failure("上传文件为空!");
}
}
@RequestMapping(value = "/downloadFileFromMongo")
public JSONMessage downloadFileFromMongo(String id, String filename, String collection, String contentType) {
try {
response.setHeader("Content-Disposition", "attachment;fileName=" &