将参数传递给StringTemplate函数

时间:2018-11-06 23:31:03

标签: java stringtemplate jdbi

假设我有

@SqlQuery("SELECT :someField FROM myTable")
String fetchField(@Bind("someField") final String columnName);

我想使用UseStringTemplate3StatementLocator将其移动到stg文件,然后从那里使用组文件和模板。我需要将此参数传递给另一个函数,即

@SqlQuery
String fetchField(@Bind("someField") final String columnName);

// in the stg file
fetchField() ::= <<
<someOtherMethod(:someField)> <! I need to pass someField to this other function ->
>>

someOtherMethod(columnName) ::= <<
 ... All the query is generated here
>>

这不起作用。我该怎么做?

1 个答案:

答案 0 :(得分:0)

您将需要使用@Define注释来为StringTemplate4提供属性,然后将其用作<someField>。但是,通过这种方式,编写的查询将可以进行SQL注入