groovy switch case用表达式替代

def topic = '/SAP/Organization/WMS2020'

switch(topic){
    case { topic.contains('/SAP/Organization/WMS') }:
        println '/SAP/Organization/WMS'
        break;
    case { topic.contains('/SAP/Material/WMS') }:
        println '/SAP/Material/WMS'
        break;
    case { topic.contains('/SAP/VendorMaster') }:
        println '/SAP/VendorMasteric'
        break;
    case { topic.contains('/SAP/CustomerMaster/Material/WMS') }:
        println '/SAP/CustomerMaster/Material/WMS'
        break;
    case { topic.contains('/SAP/CustomerMaster') }:
        println '/SAP/CustomerMaster'
        break;
    default:
        println '其他'
        break
}

 

你可能感兴趣的:(grails,groovy,java)