MongoController.java 2.34 KB
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);


    }

}