Package org.mybatis.scripting.freemarker
Class MyBatisParamDirective
java.lang.Object
org.mybatis.scripting.freemarker.MyBatisParamDirective
- All Implemented Interfaces:
freemarker.template.TemplateDirectiveModel
,freemarker.template.TemplateModel
public class MyBatisParamDirective
extends Object
implements freemarker.template.TemplateDirectiveModel
Custom FreeMarker directive for generating "#{paramName}" declarations in convenient way. Problem is FreeMarker
supports this syntax natively and there are no chance to disable this (although it is deprecated). And to get
"#{paramName}" we should write ${r"#{paramName}"}. With this directive you can write more simple:
<@p name="paramName"/>
Also directive supports `value` attribute. If it is specified, param will take passed value and create the corresponding #{}-parameter. This is useful in loops:
<#list ids as id> <@p value=id/> <#if id_has_next>,</#if> </#list>
will be translated into
#{_p0},#{_p1},#{_p2}
And MyBatis engine will convert it to `?`-params finally.
- Author:
- elwood
-
Field Summary
Fields inherited from interface freemarker.template.TemplateModel
NOTHING
-
Constructor Summary
-
Method Summary
-
Field Details
-
DEFAULT_KEY
-
DATABASE_ID_KEY
-
-
Constructor Details
-
MyBatisParamDirective
public MyBatisParamDirective()
-
-
Method Details
-
execute
public void execute(freemarker.core.Environment env, Map params, freemarker.template.TemplateModel[] loopVars, freemarker.template.TemplateDirectiveBody body) throws freemarker.template.TemplateException, IOException - Specified by:
execute
in interfacefreemarker.template.TemplateDirectiveModel
- Throws:
freemarker.template.TemplateException
IOException
-