简体   繁体   English

将参数传递给StringTemplate函数

[英]Passing arguments to StringTemplate function

Let's say I have 假设我有

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

I want to move this into a stg file using UseStringTemplate3StatementLocator and then from there, use group files and templates. 我想使用UseStringTemplate3StatementLocator将其移动到stg文件,然后从那里使用组文件和模板。 I need to pass this argument to another function, ie 我需要将此参数传递给另一个函数,即

@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
>>

This is not working. 这是行不通的。 How do I do this? 我该怎么做呢?

You would need to use @Define annotation to provide attributes to StringTemplate4 , and then, you would use it as <someField> . 你可能会需要使用@Define注释提供属性StringTemplate4 ,然后,你可以使用它作为<someField> But, in this way, query written will be open for SQL injection 但是,这样,编写的查询将可以进行SQL注入

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM