[英]Using Groovy Strings as SQL select statements
Database Mysql , version 5.5.17.JDBC driver version 5.1.28 Code with Gstring: Database Mysql,版本5.5.17.JDBC驱动程序版本5.1.28 Gstring代码:
def p = "id"
def row = sql.firstRow("select $p from Model")
print row
result: 结果:
[id:id] **!**
Code without Gstring: 没有Gstring的代码:
def row = sql.firstRow("select id from Model")
print row
result: 结果:
[id:1]
Why? 为什么?
Groovy is escaping the p
as it treats it as a Sql parameter Groovy正在逃避
p
,因为它将它视为Sql参数
Try using Sql.expand
like so: 尝试使用
Sql.expand
如下所示:
def p = 'id'
def row = sql.firstRow( "select ${Sql.expand( p )} from Model" )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.