groovy中list转map,map转bean实体类,根据List中某个元素的值过滤List中的元素

取List中每个元素的属性,重新组成一个map

String sql = """
        select * from location where warehouseCode = '${scrapDetail.warehouseCode}' and code in (${locationCodeList.join(',')})
"""
            List<Location> locationList = template(sess).query(sql,new BeanPropertyRowMapper<Location>(Location.class))

            //将location的bean转成以货位code为key,区域为value的map
            Map locationMap = locationList.collectEntries({[(it.code):it.zoneCode]})

map转实体类

//ScrapDetailVO是一个List,里面的元素是map

List<ScrapDetailVO> scrapDetailVOList = dataDetails.collect({JSON.convertValue(it,ScrapDetailVO)})

查找集合中某个值

a:使用find()方法. 找到第一个元素匹配标准

def list = [1, 2, 3]
        println(list.find { it > 1 })	//这个结果是2

找到集合中所有匹配的元素

b:使用findAll()

def list = [1, 2, 3]
        println(list.findAll{ it > 1 })		//这个是[2,3]

查找第一个元素匹配标准的索引

使用findIndexOf()

def strList =  ['a', 'b', 'c', 'd', 'e']
       def index =  strList.findIndexOf {
            it in ['c', 'e', 'g']
        }
        println(index)		//这index的结果为2
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值