org.tenio.interstellar.dao.mybatis.FreeMarkerSqlTemplate Maven / Gradle / Ivy
Show all versions of interstellar-ext-mybatis Show documentation
package org.tenio.interstellar.dao.mybatis;
import freemarker.template.Configuration;
import freemarker.template.Template;
import java.io.StringWriter;
import java.util.Map;
/**
* TODO
*
* @author: Ban Tenio
* @version: 1.0
*/
public class FreeMarkerSqlTemplate implements SqlTemplate {
private final Configuration cfg;
/**
*
* TODO
*
* @param cfg TODO
*/
public FreeMarkerSqlTemplate(Configuration cfg) {
this.cfg = cfg;
}
@Override
public String executeSqlTemplate(String templateFlag, Map params) {
try {
Template template = cfg.getTemplate(templateFlag);
StringWriter out = new StringWriter();
template.process(params, out);
return out.toString();
} catch (Exception e) {
throw new RuntimeException("generated the flag '" + templateFlag + "' sql occurred error.", e);
}
}
}