取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