Bean-Query a Java tool library that converts an object to Map
A fully tested Java tool class is just open-source. The current Code has undergone a complete test and is being applied to be placed on Maven central Repository.
Bean-query
Click Here for English version.
BeanQuery is a Java tool library that converts objects to Map. You can select attributes in the Bean to sort the results and query the results by conditions. It can not only act on top-level objects, but also on sub-objects.
BeanQuery is very simple and straightforward to use. The example code is as follows:
/Static import BeanQueryimport static cn. jimmyshi. beanquery. beanQuery. *; // use select, from, where, orderBy, desc, and asc to assemble a Query, and then execute the execute method to obtain the result. List
> Result = select (price, name, mainAuthor. name as mainAuthorName ). from (bookCollection ). where (// for books name is Book2 or starts with Book1 anyOf (value (name, startsWith (Book1), value (name, is (Book2 ))), // for books price between (53,65) allOf (value (price, greaterThan (53d), value (price, lessThan (65d )))). orderBy (name ). desc (). execute ();
In the above example, the content of bookCollection is as follows (in json format)
[ { price:55.55, name:Book1, mainAuthor:{ name:Book1-MainAuthor, address:{ address:Shenzhen Guangdong China, postCode:518000 }, birthDate:1982-01-30T14:52:39 } }, { price:52.55, name:Book12, mainAuthor:{ name:Book1-MainAuthor, address:{ address:Shenzhen Guangdong China, postCode:518000 }, birthDate:1982-01-30T14:52:39 } }, { price:53.55, name:Book13, mainAuthor:{ name:Book13-MainAuthor, address:{ address:Shenzhen Guangdong China, postCode:518000 }, birthDate:1982-01-30T14:52:39 } }, { price:60.0, name:Book14, mainAuthor:{ name:Book14-MainAuthor, address:{ address:Shenzhen Guangdong China, postCode:518000 }, birthDate:1982-01-30T14:52:39 } }, { price:50.55, name:Book15, mainAuthor:{ name:Book1-MainAuthor, address:{ address:Shenzhen Guangdong China, postCode:518000 }, birthDate:1982-01-30T14:52:39 } }, { price:77.77, name:Book3, mainAuthor:{ name:Book3-MainAuthor, address:{ address:Shenzhen Guangdong China, postCode:518005 }, birthDate:1982-01-30T14:52:39 } } , { price:66.66, name:Book2, mainAuthor:{ name:Book2-MainAuthor, address:{ address:Shenzhen Guangdong China, postCode:518005 }, birthDate:1982-01-30T14:52:39 } }]
After execution, the result content is as follows (in json format)
[ { price:60.0, name:Book14, mainAuthorName:Book14-MainAuthor }, { price:53.55, name:Book13, mainAuthorName:Book13-MainAuthor }, { price:55.55, name:Book1, mainAuthorName:Book1-MainAuthor }]