i want to know is there any groovier way of code below:
def dataList = OperLog.createCriteria().list(max:params.max, offset:params.offset) {
if(params.relationId){
eq('relationId',params.long('relationId'))
}
order(params.sort, params.order)
}
such as someVar?.someMethod is there any sugar of don't call a method where it's params i开发者_如何学Pythons null
You could do:
params.relationId?.with { rid ->
println rid
}
And the code inside the with
block will not be executed if params.relationId
is null
...
However, I'd argue that your original code is more obvious in its intentions, and you won't have to try and work out what it is doing when you come to review it at a later date ;-)
is there any groovier style of this?
def list = [vo1,vo2,vo3]
list.each{
someMethod(it)
}
just like
list*.toString()
精彩评论