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();
            }
  • 相关阅读:
    十二经络容易堵塞穴位
    考研英语词汇-乱序便携版-遗忘曲线
    分享一个硬核理工类科普节目:回到2049(12月17号取消置顶)
    191129
    191130
    191128
    191127
    191126
    191125
    微信公众号自定义菜单中添加图标(转)
  • 原文地址:https://www.cnblogs.com/solq/p/2742390.html
Copyright © 2011-2022 走看看