[英]Using Groovy Strings as SQL select statements
Database Mysql,版本5.5.17.JDBC驅動程序版本5.1.28 Gstring代碼:
def p = "id"
def row = sql.firstRow("select $p from Model")
print row
結果:
[id:id] **!**
沒有Gstring的代碼:
def row = sql.firstRow("select id from Model")
print row
結果:
[id:1]
為什么?
Groovy正在逃避p
,因為它將它視為Sql參數
嘗試使用Sql.expand
如下所示:
def p = 'id'
def row = sql.firstRow( "select ${Sql.expand( p )} from Model" )
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.