Collection using join method on empty values

后端 未结 2 1741
心在旅途
心在旅途 2021-01-23 01:49

I\'ve got a simple method that looks at the request parameters coming through from a form and displays the values in a string. This method is working just fine but when an empty

相关标签:
2条回答
  • 2021-01-23 02:03

    You could make use of subMap:

    request.requestParameterMap
           .subMap(products)
           .findResults { k, v -> v ?: null }
           .join(':')
    
    0 讨论(0)
  • 2021-01-23 02:04

    Another way to handle this would be:

    products.collect { request.requestParameterMap[it] }.findAll().join(':')
    

    Thanks to Tim Yates for the tap on my wrist to make me realize that I was becoming too generic about beef, mozzarella and milk when thinking of meat, cheese and dairy. ;-) (See comments on Tim's answer to notice my blatant ignorance)

    0 讨论(0)
提交回复
热议问题