zoukankan      html  css  js  c++  java
  • Bean-Query 一个把对象转换为Map的Java工具库

    刚开源了一个经过完整測试的Java工具类。


    地址例如以下:
    https://github.com/Jimmy-Shi/bean-query
    使用说明例如以下:

    Bean-query

    Click Here for English version.

    BeanQuery 是一个把对象转换为Map的Java工具库。支持选择Bean中的一些属性,对结果进行排序和依照条件查询。不只能够作用于顶层对象,也能够作用于子对象。

    BeanQuery的使用非常easy也非常直接。样例代码例如以下:

    /静态导入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 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();


    在上面的样例中,bookCollection的内容例如以下所看到的(json格式)

    [
      {
        "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"
        }
      }
    ]

    运行完之后。则result的内容例如以下所看到的(json格式)

    [
      {
        "price":60.0,
        "name":"Book14",
        "mainAuthorName":"Book14-MainAuthor"
      },
      {
        "price":53.55,
        "name":"Book13",
        "mainAuthorName":"Book13-MainAuthor"
      },
      {
        "price":55.55,
        "name":"Book1",
        "mainAuthorName":"Book1-MainAuthor"
      }
    ]


  • 相关阅读:
    如何在一台主机上管理自己的多个git repository
    Linux deepin 中Jetbrain Idea等软件中文显示异常
    使用openmp进行并行编程
    使用pthread进行编程
    使用openmp进行共享内存编程
    并行与分布式计算之并行硬件与并行软件
    算法笔记刷题5(PAT A1025)
    算法笔记刷题4(PAT B1009)
    算法笔记刷题3(codeup 5901)
    算法笔记刷题2(codeup 1928)
  • 原文地址:https://www.cnblogs.com/bhlsheji/p/5153548.html
Copyright © 2011-2022 走看看