zoukankan      html  css  js  c++  java
  • mongodb spring anno 查询

    public interface LogTaskBuilderRepository extends MongoRepository<LogTaskBuilder, String>  {
    
        @Query(value="{ 'type': {'$in' : ?0} }",fields="{ 'type' : 1}")
        public List<LogTaskBuilder> findTest(String[] name);
            
        @Query(value="{?0:?1}")  
        public List<LogTaskBuilder> findTest2(Object field,Object Value);
        
        //正则测试
        @Query(value="{ 'type' :{'$regex' :?0, '$options': 'i'} }")    
        public List<LogTaskBuilder> findTest3(String name); 
        
        //日期查询
    
        @Query(value="{ 'executeDate' :{'$gt' : ?0 } }")    
        public List<LogTaskBuilder> findTest4(Date date);  
        
        //内部查询 findBy{字段}{条件}
        public List<LogTaskBuilder> findByTypeLike(String name); 
        public List<LogTaskBuilder> findByTypeLike(String name, Sort sort); 
        public List<LogTaskBuilder> findByTypeLike(String name, Pageable pageable); 
        
    }
    public class LogTaskBuilder {
    
    @Id
    private String name;
    
    private RecordType type; 
    private Date executeDate;
    
    }

    test

    System.out.println(logTaskBuilderRepository.findByTypeLike("SoulRecord").size());
            System.out.println(logTaskBuilderRepository.findTest3("Record").size());
            System.out.println(logTaskBuilderRepository.findByTypeLike("Record",new Sort("type", Order.DESCENDING)).size());
            
            System.out.println(logTaskBuilderRepository.findTest(new String[]{"SoulRecord","ItemRecord"}).size());
            System.out.println(logTaskBuilderRepository.findTest2("name","SoulRecord").size());
            
            DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
            
            try {
                System.out.println(logTaskBuilderRepository.findTest4(dateFormat.parse("2012-10-26")).size());
            } catch (ParseException e) {
                e.printStackTrace();
            }
  • 相关阅读:
    python实战===用python调用jar包
    Django连接数据库写入数据报错
    Niginx主配置文件参数详解
    uwsgi参数详解
    JSON序列化和反序列化
    ServiceBroker创建流程
    WCF和WebService中获取当前请求报文的方法
    python 关于文件的操作
    关于函数对象的理解
    python,关于用户登录与注册问题
  • 原文地址:https://www.cnblogs.com/solq/p/2742390.html
Copyright © 2011-2022 走看看