代码之家  ›  专栏  ›  技术社区  ›  Saikat SHASHANK HONRAO

对于整数比较,Groovy方法返回false

  •  0
  • Saikat SHASHANK HONRAO  · 技术社区  · 6 年前

    false (即使两个查询结果都是 0

    boolean checkObjects() {
        Sql.withInstance("jdbc:oracle:thin:@//${db_host}:${db_port}/${db_servicename}", "${db_username}", "${db_password}") { sql ->
            result1 = sql.firstRow('select count(status) as count from all_objects where status=\'INVALID\'')
            result2 = sql.firstRow('select count(status) as count from user_objects where status=\'INVALID\'')
    
            boolean output = ("${result1.count}".toString() == "0") && ("${result2.count}".toString() == "0")
            println output // prints true
            return output
        }
    }
    
    println checkObjects() // prints false
    
    0 回复  |  直到 6 年前
        1
  •  2
  •   Jorge Aguilera Gonzalez    6 年前

    在groovy中使用闭包时,这是一个常见的错误: 输出是闭包的返回,但函数的返回是withInstance

    尝试在闭包外部声明输出,并将其作为函数的结果返回