MongoController.java
2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package com.subsidy.mongodb;
import com.subsidy.util.MongoUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/mango")
public class MongoController {
@Autowired
private MongoTemplate mongoTemplate;
@Autowired
private MongoUtil mongoUtil;
@PostMapping("getOne")
public void getAll(){
////Query query=new Query();
////MongoDO user = mongoTemplate.getDb(query , MongoDO.class);
////List<MongoDO> mongo= mongoTemplate.findAll(MongoDO.class);
////System.out.println(mongo);
//System.out.println(mongoTemplate.getDb().getName());
//
//Collection mongoDO = mongoTemplate.findById("61de944c5cdc5e3f896c95c7", Collection.class);
//System.out.println(mongoDO);
//
//List<Collection> collections = mongoTemplate.findAll(Collection.class);
//System.out.println(collections);
//
//Query query = new Query(Criteria.where("name").regex("张"));//可累加条件
//List<Collection> entrY = mongoTemplate.find(query,Collection.class);
//System.out.println(entrY);
//添加
//Collection collection = new Collection();
//collection.setName("bbbbbbbb");
//collection.set_id("61de944c5cdc5e3f896c95c7");
//mongoTemplate.save(collection,"collection");
//for (int i = 0 ; i < 100; i++){
// Collection collection1 = new Collection();
// collection1.setName("aaaa"+i);
// mongoTemplate.save(collection1);
//}
//Query query =new Query(new Criteria());
//query.with(Sort.by("name"));
////mongoUtil.start(1,5,query);
//List<Collection> collections = mongoTemplate.find(query,Collection.class);
//for (Collection collection : collections){
// System.out.println(collection+"=========");
//}
//OprAdmDictDO oprAdmDictDO = new OprAdmDictDO();
//oprAdmDictDO.setUserId(1L);
//oprAdmDictDO.setResult(1);
//oprAdmDictDO.setOprType("登录成功");
//mongoTemplate.save(oprAdmDictDO);
}
}