如何从列表结果Groovy中删除方括号?

时间:2021-09-23 21:41:50

I have a query, the results of which I am adding to a list. These results are being passed into another query using $systemTypeQueryResults

我有一个查询,其结果我将添加到列表中。这些结果将使用$ systemTypeQueryResults传递到另一个查询中

The value still has the square brackets around it which is causing the query to fail. My question is how to remove the square brackets in Groovy. If it helps the values are all integers. The population of the list works as follows:

该值仍然具有围绕它的方括号,这导致查询失败。我的问题是如何删除Groovy中的方括号。如果它有助于值全部是整数。该清单的人口如下:

String systemTypeQuery ="SELECT id from system_type where type = '${systemType}';"
    def systemTypeQueryResults = []
    ticketerDb.eachRow(systemTypeQuery) {
      systemTypeQueryResults << it.id
    }

When these results are used in a further query they display as follows: [1] I would like to know how to remove these square brackets?

当这些结果用于进一步的查询时,它们显示如下:[1]我想知道如何删除这些方括号?

1 个解决方案

#1


toString() on a list object produces the string result with the brackets, to avoid the brackets you can use join on the list object as follows:

列表对象上的toString()生成带括号的字符串结果,以避免括号可以在列表对象上使用连接,如下所示:

String systemTypeQuery ="SELECT id from system_type where type = '${systemType}';"
def systemTypeQueryResults = []
ticketerDb.eachRow(systemTypeQuery) {
  systemTypeQueryResults << it.id
}
def queryWithoutBrackets = systemTypeQueryResults.join(",");

This way you have a string with your results separated by commas which you can pass to your next query.

这样,您就会有一个字符串,结果用逗号分隔,您可以将其传递给下一个查询。

Hope this helps,

希望这可以帮助,

#1


toString() on a list object produces the string result with the brackets, to avoid the brackets you can use join on the list object as follows:

列表对象上的toString()生成带括号的字符串结果,以避免括号可以在列表对象上使用连接,如下所示:

String systemTypeQuery ="SELECT id from system_type where type = '${systemType}';"
def systemTypeQueryResults = []
ticketerDb.eachRow(systemTypeQuery) {
  systemTypeQueryResults << it.id
}
def queryWithoutBrackets = systemTypeQueryResults.join(",");

This way you have a string with your results separated by commas which you can pass to your next query.

这样,您就会有一个字符串,结果用逗号分隔,您可以将其传递给下一个查询。

Hope this helps,

希望这可以帮助,