Bean-Query a Java tool library that converts an object to Map

Source: Internet
Author: User
Tags maven central

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  }]


 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.