简体   繁体   English

如何从控制台读取参数到 groovy 中的方法?

[英]how to read parameters from console to method in groovy?

I am new to groovy.I am reading values for 2 variables from console with below lines of code.我是 groovy 的新手。我正在使用以下代码行从控制台读取 2 个变量的值。

System.in.withReader {   
  println "Version: "  
  version = it.readLine()  
  println "Doc Type:"  
  Doc=it.readLine()  
  call getBillID(version,Doc)
}

getBillid method is as below, getBillid方法如下,

def getBillID(int version,int doc)
{  
  allNodes.BillID.each {
    theregularExpression=/\d+_\d+_\d+_\d_\d+_\d+_\d_${version}_${Doc}_\d+_\d+/
    if(it != "" && it =~ theregularExpression) {
      println "******" + it
    }
  }
}

now i want to use those variable values in my getBILLID method but i am getting error as现在我想在我的getBILLID方法中使用这些变量值,但我收到错误

No signature of method: ReadXML.getBillID() is applicable for argument types: (java.lang.String, java.lang.String) values: [9, ]

where i went wrong.can any one tell me plz..我哪里出错了。谁能告诉我。。

In addition to @Kalarani's answer, you could also do this:除了@Kalarani 的回答,您还可以这样做:

System.in.withReader {
  print "Version: "
  int version = it.readLine() as int
  print "Doc Type: "
  int doc = it.readLine() as int
  getBillID( version, doc )
}

As an aside;作为旁白; I would be careful with your capitalisation and variable names, ie: you have a variable called Doc with a capital letter.我会小心你的大写和变量名,即:你有一个名为Doc的变量,带有一个大写字母。 This is not the standard naming scheme, and you are best using all lowercase for variable names.这不是标准的命名方案,最好使用全小写的变量名。 You can see where it has got confused in the getBillID method.您可以在getBillID方法中看到混淆的地方。 The parameter is called doc (all lowercase), but in the regular expression you reference ${Doc} (uppercase again).该参数称为doc (全部小写),但在正则表达式中您引用${Doc} (再次大写)。

This sort of thing is going to end up causing you a world of pain and bugs that might take you longer to find这种事情最终会给你带来一个痛苦和错误的世界,可能需要你更长的时间才能找到

Where is the getBillId() method defined? getBillId() 方法在哪里定义? and what is the signature of the method?该方法的签名是什么? It would help understanding your problem if you could post that.如果您可以发布它,这将有助于理解您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM