Skip to content

Bean Query reuses Apache Commons BeanUtils, Apache Commons Collections, Java Hamcrest to make sorting, filtering and converting a (collection of) java bean(s) easily. Bean Query 复用Apache Commons BeanUtils, Apache Commons Collections, Java Hamcrest 来简化对Bean(集合)的排序,过滤和转换。

License

Jimmy-Shi/bean-query

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bean-query

Click Here for English version.

Bean Query 复用Apache Commons BeanUtils, Apache Commons Collections, Java Hamcrest 来简化对Bean(集合)的排序,过滤和转换。

文档

快速入门

BeanQuery的使用非常简单也很直接,例子代码如下:

//静态导入BeanQuery
import static cn.jimmyshi.beanquery.BeanQuery.*;


//使用 select、from、where、orderBy、desc和asc来组装一个Query,然后执行execute方法来获得结果。
List<Map<String, Object>> result = select("price,name,mainAuthor.name, authors[1].name as secondAuthor.name")
    .nested()
    .from(bookCollection)
    .where(
        //选择name属性值是"Book2"或者以“Book1”开头
        anyOf(
            value("name", startsWith("Book1")),
            value("name", is("Book2"))
        ),
        //并且prince的值位于区间(53,65)
        allOf(
            value("price", greaterThan(53d)),
            value("price",lessThan(65d))
        )
    )
    .orderBy("name").desc()//根据"name"属性按照倒序对结果进行排列
    .execute();

执行完以上代码后,result列表中的每个Map都是java.util.LinkedHashMap实例,每个Map的都由下面的这三个Entry组成:

  • key=price, value=book.getPrice()
  • key=name, value=book.getName()
  • Key=mainAuthor, value=a map with { key=name, value=book.getMainAuthor().getName() }
  • key=secondsAuthor, value=a map with { key=name, value=book.getAuthors().get(1).getName() }

About

Bean Query reuses Apache Commons BeanUtils, Apache Commons Collections, Java Hamcrest to make sorting, filtering and converting a (collection of) java bean(s) easily. Bean Query 复用Apache Commons BeanUtils, Apache Commons Collections, Java Hamcrest 来简化对Bean(集合)的排序,过滤和转换。

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages