首页 文章

Groovy Script错误没有这样的属性:customerId for class

提问于
浏览
-2

在执行脚本时我收到错误,即groovy.lang.MissingPropertyException:没有这样的属性:customerId for class

脚本是

import org.w3c.dom.Node
import org.w3c.dom.NodeList
NodeList nodes = employeeServiceResponse.getFirstChild().getChildNodes()
String firstName = null
String lastName = null
for (int i = 0 i < nodes.getLength() i++) {
  Node node = nodes.item(i)
  if ("firstName".equals(node.getLocalName()))
    firstName = node.getFirstChild().getNodeValue()
  else if ("lastName".equals(node.getLocalName()))
    lastName = node.getFirstChild().getNodeValue()
}
if (firstName != null && lastName != null){
  println 'Found employee: ' + firstName + ' ' + lastName
  discountPercent = 10
  return true
} else {
  println 'Employee not found: ' + customerId
  discountPercent = 0
  return false
}

我是groovy脚本的新手,任何人都可以帮助我 . 该脚本解析数据 .

1 回答

  • 2

    你写的(最后一行):

    println 'Employee not found: ' + customerId
    

    但是 customerId 未在此脚本中定义 . 当您在脚本中寻找任何员工时,您应该写:

    println 'Employee not found'
    

相关问题