今天又被groovy的高效吓到了。
想提取所有的itemCodes,两种玩法
一、常规方法:遍历组装
RestResult items = getListPager() def temp = [] items.data.data.each { temp.push(it.itemCode) }
println(temp)
[DP180929155952858, DP180511114211610, DP1539683378800, DP1539682576227, DP1539681917164, DP1539681882632, DP1539681460929, DP1539681297697, DP1539679354755]
二、直接拿值,简直不能再高效了
RestResult items = getListPager() def itemCodes = items.data.data.itemCode
println(itemCodes)
[DP180929155952858, DP180511114211610, DP1539683378800, DP1539682576227, DP1539681917164, DP1539681882632, DP1539681460929, DP1539681297697, DP1539679354755]
{ "code" : "ok", "data" : { "data" : [ { "itemCode" : "DP180929155952858", "itemName" : "成本测试专用-勿动", "itemType" : "SINGLE", "itemTypeName" : "单品", "purchaseSpecName" : "箱", "tax" : 1 }, { "itemCode" : "DP180511114211610", "itemName" : "百事", "itemType" : "SINGLE", "itemTypeName" : "单品", "purchaseSpecName" : "箱", "tax" : 1 }, { "itemCode" : "DP1539683378800", "itemName" : "自动合成品20181016164446", "itemType" : "MATERIAL", "itemTypeName" : "原材料", "purchaseSpecName" : "箱", "tax" : 1 }, { "itemCode" : "DP1539682576227", "itemName" : "自动合成品20181016164446", "itemType" : "MATERIAL", "itemTypeName" : "原材料", "purchaseSpecName" : "箱", "tax" : 1 }, { "itemCode" : "DP1539681917164", "itemName" : "自动合成品20181016164446", "itemType" : "MATERIAL", "itemTypeName" : "原材料", "purchaseSpecName" : "箱", "tax" : 1 }, { "itemCode" : "DP1539681882632", "itemName" : "自动合成品20181016164446", "itemType" : "MATERIAL", "itemTypeName" : "原材料", "purchaseSpecName" : "箱", "tax" : 1 }, { "itemCode" : "DP1539681460929", "itemName" : "自动单品20181016171741", "itemType" : "SINGLE", "itemTypeName" : "单品", "purchaseSpecName" : "箱", "tax" : 1 }, { "itemCode" : "DP1539681297697", "itemName" : "自动单品20181016171457", "itemType" : "SINGLE", "itemTypeName" : "单品", "purchaseSpecName" : "箱", "tax" : 1 }, { "itemCode" : "DP1539679354755", "itemName" : "自动原材料20181016164234", "itemType" : "MATERIAL", "itemTypeName" : "原材料", "purchaseSpecName" : "箱", "tax" : 8 } ], "page" : { "endPage" : 19, "offset" : 0, "pageNo" : 1, "pageSize" : 20, "totalPage" : 1, "totalRecord" : 9 } }, "message" : "成功" }
---
开心工作,认真生活;回望来时路,脚印三两,笑声无数...
开心工作,认真生活;回望来时路,脚印三两,笑声无数...