简体   繁体   中英

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. 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> . But, in this way, query written will be open for SQL injection

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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