Solo  当前访客:1 开始使用

Spring中访问MongoDB


1、导入依赖
2、接口定义

public interface CommonGatherFormEntityRepository extends MongoRepository<CommonGatherFormEntityMongo, String>, QuerydslPredicateExecutor<CommonGatherFormEntityMongo> {

    @Query("{'entEnterpriseBaseInfo.entName' : ?0}")
    List<CommonGatherFormEntityMongo> findByEntName(String entName);

    @Query("{ $and : [ { 'entEnterpriseBaseInfo.entName' :?0} , { '_id' : ?1}]}")
    CommonGatherFormEntityMongo findByEntNameAndOrderNo(String entName, String orderNo);

    @Query(fields = "{'personInfos.$':1}")
    List<CommonGatherFormEntityMongo> findByPersonInfosPersonName(String personName);


    @Query("{'_id' : ?0}")
    List<CommonGatherFormEntityMongo> findByOrderNo(String orderNo);


    @Query("{'createdDate': {$gte: ?0}}")
    List<CommonGatherFormEntityMongo> findByCreatedDateBetweens(DateTime lastTime);

    @Query(value = "{'createdDate': {$gte: ?0}}")
    List<CommonGatherFormEntityMongo> findByCreatedDateBetween(Date datefrom);

}

3、使用

  @Autowired
    private CommonGatherFormEntityMongoService commonGatherFormEntityMongoService;


标题:Spring中访问MongoDB
作者:Nick1407
地址:https://nick1407.com/articles/2019/07/08/1562577428255.html

0 0