|
@@ -1,44 +1,44 @@
|
|
-package cn.com.qmth.examcloud.core.questions.base;
|
|
|
|
-
|
|
|
|
-import com.mongodb.BasicDBObject;
|
|
|
|
-import com.mongodb.DBObject;
|
|
|
|
-import com.mongodb.gridfs.GridFSDBFile;
|
|
|
|
-import com.mongodb.gridfs.GridFSFile;
|
|
|
|
-import org.bson.types.ObjectId;
|
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
-import org.springframework.data.mongodb.core.query.Criteria;
|
|
|
|
-import org.springframework.data.mongodb.core.query.Query;
|
|
|
|
-import org.springframework.data.mongodb.gridfs.GridFsOperations;
|
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
|
-import java.util.List;
|
|
|
|
-
|
|
|
|
-import java.io.InputStream;
|
|
|
|
-
|
|
|
|
-/**
|
|
|
|
- * Created by songyue on 17/2/27.
|
|
|
|
- */
|
|
|
|
-@Service
|
|
|
|
-public final class GridFSUtil {
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- private GridFsOperations gridOperation;
|
|
|
|
-
|
|
|
|
- public String save(InputStream inputStream, String fileName) {
|
|
|
|
- DBObject metaData = new BasicDBObject();
|
|
|
|
- metaData.put("fileName", fileName);
|
|
|
|
- GridFSFile file = gridOperation.store(inputStream, fileName, metaData);
|
|
|
|
- return file.getId().toString();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public GridFSDBFile get(String id) {
|
|
|
|
- return gridOperation.findOne(new Query(Criteria.where("_id").is(new ObjectId(id))));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public List listFiles() {
|
|
|
|
- return gridOperation.find(null);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public GridFSDBFile getByFileName(String fileName) {
|
|
|
|
- return gridOperation.findOne(new Query(Criteria.where("filename").is(fileName)));
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
|
|
+//package cn.com.qmth.examcloud.core.questions.base;
|
|
|
|
+//
|
|
|
|
+//import com.mongodb.BasicDBObject;
|
|
|
|
+//import com.mongodb.DBObject;
|
|
|
|
+//import com.mongodb.gridfs.GridFSDBFile;
|
|
|
|
+//import com.mongodb.gridfs.GridFSFile;
|
|
|
|
+//import org.bson.types.ObjectId;
|
|
|
|
+//import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+//import org.springframework.data.mongodb.core.query.Criteria;
|
|
|
|
+//import org.springframework.data.mongodb.core.query.Query;
|
|
|
|
+//import org.springframework.data.mongodb.gridfs.GridFsOperations;
|
|
|
|
+//import org.springframework.stereotype.Service;
|
|
|
|
+//import java.util.List;
|
|
|
|
+//
|
|
|
|
+//import java.io.InputStream;
|
|
|
|
+//
|
|
|
|
+///**
|
|
|
|
+// * Created by songyue on 17/2/27.
|
|
|
|
+// */
|
|
|
|
+//@Service
|
|
|
|
+//public final class GridFSUtil {
|
|
|
|
+//
|
|
|
|
+// @Autowired
|
|
|
|
+// private GridFsOperations gridOperation;
|
|
|
|
+//
|
|
|
|
+// public String save(InputStream inputStream, String fileName) {
|
|
|
|
+// DBObject metaData = new BasicDBObject();
|
|
|
|
+// metaData.put("fileName", fileName);
|
|
|
|
+// GridFSFile file = gridOperation.store(inputStream, fileName, metaData);
|
|
|
|
+// return file.getId().toString();
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// public GridFSDBFile get(String id) {
|
|
|
|
+// return gridOperation.findOne(new Query(Criteria.where("_id").is(new ObjectId(id))));
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// public List listFiles() {
|
|
|
|
+// return gridOperation.find(null);
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// public GridFSDBFile getByFileName(String fileName) {
|
|
|
|
+// return gridOperation.findOne(new Query(Criteria.where("filename").is(fileName)));
|
|
|
|
+// }
|
|
|
|
+//}
|