本文整理匯總了Java中org.beetl.core.Template.binding方法的典型用法代碼示例。如果您正苦於以下問題:Java Template.binding方法的具體用法?Java Template.binding怎麽用?Java Template.binding使用的例子?那麽恭喜您, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.beetl.core.Template的用法示例。
在下文中一共展示了Template.binding方法的44個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於我們的係統推薦出更棒的Java代碼示例。
示例1: generateMappingModel
點讚 4
import org.beetl.core.Template; //導入方法依賴的package包/類
public void generateMappingModel(Object projectId, String templatePath) {
if ( StrKit.isBlank(templatePath) ) templatePath = MAVEN_BASE + "gen/config/4jfinalmappingmodel.btl";
Template t_pojo = gt.getTemplate(templatePath);
List list = Db.find("select a.*, b.name primary_name, b.java_type, c.package, c.module_name from w_db_model a, w_db_model_item b, w_generate c where a.id = b.w_model_id and c.w_model_id = a.id and b.is_primary = 1 and a.project_id = ?", projectId);
t_pojo.binding("models", list);
File file = getConfigGenerateFile(
File.separator + "org" +
File.separator + "hacker" +
File.separator + "core" +
File.separator + "config",
"MappingModel.java");
System.out.println(file.getAbsolutePath());
try {
FileKit.write(t_pojo.render(), file);
} catch ( FileNotFoundException | BeetlException e ) {
e.printStackTrace();
}
System.out.println("############getGenerateConfig success############");
}
開發者ID:slashchenxiaojun,項目名稱:wall.e,代碼行數:20,
示例2: callHtmlTag
點讚 4
import org.beetl.core.Template; //導入方法依賴的package包/類
protected void callHtmlTag(String path)
{
Template t = null;
t = gt.getHtmlFunctionOrTagTemplate(path, this.ctx.getResourceId());
t.binding(ctx.globalVar);
t.dynamic(ctx.objectKeys);
if (args.length == 2)
{
Map map = (Map) args[1];
for (Entry entry : map.entrySet())
{
t.binding(entry.getKey(), entry.getValue());
}
}
BodyContent bodyContent = super.getBodyContent();
t.binding("tagBody", bodyContent);
t.renderTo(ctx.byteWriter);
}
開發者ID:javamonkey,項目名稱:beetl2.0,代碼行數:25,
示例3: generateMappingRoute
點讚 3
import org.beetl.core.Template; //導入方法依賴的package包/類
public void generateMappingRoute(Object projectId, String templatePath) {
if ( StrKit.isBlank(templatePath) ) templatePath = MAVEN_BASE + "gen/config/4jfinalmappingroute.btl";
Template t_pojo = gt.getTemplate(templatePath);
List list = Db.find("select a.*, b.name primary_name, b.java_type, c.package, c.module_name from w_db_model a, w_db_model_item b, w_generate c where a.id = b.w_model_id and c.w_model_id = a.id and b.is_primary = 1 and a.project_id = ?", projectId);
t_pojo.binding("models", list);
File file = getConfigGenerateFile(
File.separator + "org" +
File.separator + "hacker" +
File.separator + "core" +
File.separator + "config",
"MappingRoute.java");
System.out.println(file.getAbsolutePath());
try {
FileKit.write(t_pojo.render(), file);
} catch ( FileNotFoundException | BeetlException e ) {
e.printStackTrace();
}
System.out.println("############getGenerateConfig success############");
}
開發者ID:slashchenxiaojun,項目名稱:wall.e,代碼行數:20,
示例4: test_controller
點讚 3
import org.beetl.core.Template; //導入方法依賴的package包/類
public void test_controller() {
int id = 3;
gt.registerFunction("firstCharToLowerCase", new FirstCharToLowerCase());
DbModel model = DbModel.dao.findById(id);
List columns = DbModelItem.dao.find("select * from w_db_model_item where w_model_id = ? order by serial", id);
Generate generate = Generate.dao.findFirst("select * from w_generate where w_model_id = ?", id);
// 查找出跟model有關的list
List master = Db.find("select b.class_name, a.*, c.package, c.module_name from w_db_model_mapping a, w_db_model b, w_generate c where a.master_id = b.id and a.slaves_id = ? and a.master_id = c.w_model_id", id);
// 查找出跟model相關的從表
List slaves = Db.find("SELECT a.class_name, b.*, c.package, c.module_name FROM w_db_model a, w_db_model_mapping b, w_generate c WHERE a.id = b.slaves_id AND b.master_id = ? and c.w_model_id = b.slaves_id", id);
Template t = gt.getTemplate("gen/web/4Jfinalcontroller.btl");
t.binding("model", model);
t.binding("columns", columns);
t.binding("generate", generate);
t.binding("master", master);
t.binding("slaves", slaves);
// 是否使用駝峰命名
t.binding("camelName", true);
System.out.println(t.render());
}
開發者ID:slashchenxiaojun,項目名稱:wall.e,代碼行數:24,
示例5: test_service
點讚 3
import org.beetl.core.Template; //導入方法依賴的package包/類
public void test_service() {
int id = 3;
gt.registerFunction("firstCharToLowerCase", new FirstCharToLowerCase());
DbModel model = DbModel.dao.findById(id);
List columns = DbModelItem.dao.find("select * from w_db_model_item where w_model_id = ? order by serial", id);
Generate generate = Generate.dao.findFirst("select * from w_generate where w_model_id = ?", id);
// 查找出跟model有關的list
List master = Db.find("select b.class_name, a.*, c.package, c.module_name from w_db_model_mapping a, w_db_model b, w_generate c where a.master_id = b.id and a.slaves_id = ? and a.master_id = c.w_model_id", id);
// 查找出跟model相關的從表
List slaves = Db.find("SELECT a.class_name, b.*, c.package, c.module_name FROM w_db_model a, w_db_model_mapping b, w_generate c WHERE a.id = b.slaves_id AND b.master_id = ? and c.w_model_id = b.slaves_id", id);
Template t = gt.getTemplate("gen/web/4curd&webservice.btl");
t.binding("model", model);
t.binding("columns", columns);
t.binding("generate", generate);
t.binding("master", master);
t.binding("slaves", slaves);
// 是否使用駝峰命名
t.binding("camelName", true);
System.out.println(t.render());
}
開發者ID:slashchenxiaojun,項目名稱:wall.e,代碼行數:24,
示例6: test_sqlmd
點讚 3
import org.beetl.core.Template; //導入方法依賴的package包/類
public void test_sqlmd() {
int id = 3;
gt.registerFunction("firstCharToLowerCase", new FirstCharToLowerCase());
DbModel model = DbModel.dao.findById(id);
List columns = DbModelItem.dao.find("select * from w_db_model_item where w_model_id = ? order by serial", id);
Generate generate = Generate.dao.findFirst("select * from w_generate where w_model_id = ?", id);
// 查找出跟model有關的list
List master = Db.find("select b.class_name, a.*, c.package, c.module_name from w_db_model_mapping a, w_db_model b, w_generate c where a.master_id = b.id and a.slaves_id = ? and a.master_id = c.w_model_id", id);
// 查找出跟model相關的從表
List slaves = Db.find("SELECT a.class_name, b.*, c.package, c.module_name FROM w_db_model a, w_db_model_mapping b, w_generate c WHERE a.id = b.slaves_id AND b.master_id = ? and c.w_model_id = b.slaves_id", id);
Template t = gt.getTemplate("gen/web/4mysqlmd.btl");
t.binding("model", model);
t.binding("columns", columns);
t.binding("generate", generate);
t.binding("master", master);
t.binding("slaves", slaves);
// 是否使用駝峰命名
t.binding("camelName", true);
System.out.println(t.render());
}
開發者ID:slashchenxiaojun,項目名稱:wall.e,代碼行數:24,
示例7: render
點讚 3
import org.beetl.core.Template; //導入方法依賴的package包/類
@Override
public String render(String templatePath, Map data) throws Exception {
GroupTemplate gt = getGroupTemplate();
// set template global shared vars
Map sharedVars = new HashMap<>();
sharedVars.put("REQUEST", HttpContext.request());
Session session = HttpContext.request().session();
sharedVars.put("SESSION", session != null ? session.attributes() : new HashMap());
gt.setSharedVars(sharedVars);
Template template = gt.getTemplate(templatePath);
template.binding(data);
return template.render();
}
開發者ID:thundernet8,項目名稱:Razor,代碼行數:17,
示例8: main
點讚 3
import org.beetl.core.Template; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
String home = System.getProperty("user.dir") + File.separator
+ "template" + File.separator;
Configuration cf = Configuration.defaultConfiguration();
cf.setStatementStart("");
FileResourceLoader rs = new FileResourceLoader(home, cf.getCharset());
GroupTemplate gt = new GroupTemplate(rs, cf);
List list = StockModel.dummyItems();
Template t = gt.getTemplate("/helloworld.html");
t.binding("items", list);
StringWriter sw = new StringWriter();
t.renderTo(sw);
System.out.println(sw.toString());
// 第二次
t = gt.getTemplate("/helloworld.html");
t.binding("items", list);
sw = new StringWriter();
t.renderTo(sw);
System.out.println(sw.toString());
}
開發者ID:javamonkey,項目名稱:beetl2.0,代碼行數:27,
示例9: testCore
點讚 3
import org.beetl.core.Template; //導入方法依賴的package包/類
@Test
public void testCore() throws Exception
{
gt.registerFormat("date.short", new ShortDateFormatter());
Map map = new HashMap();
map.put("a", 1.12);
Template t = gt.getTemplate("/formatter/formatter_template.html");
t.binding(map);
String str = t.render();
AssertJUnit.assertEquals(this.getFileContent("/formatter/formatter_expected.html"), str);
t = gt.getTemplate("/formatter/formatter_template.html");
t.binding(map);
str = t.render();
AssertJUnit.assertEquals(this.getFileContent("/formatter/formatter_expected.html"), str);
}
開發者ID:javamonkey,項目名稱:beetl2.0,代碼行數:19,
示例10: testCore
點讚 3
import org.beetl.core.Template; //導入方法依賴的package包/類
@Test
public void testCore() throws Exception
{
Map map = new HashMap();
map.put("a", "hi");
map.put("b", 1);
Template t = gt.getTemplate("/function/function_template.html");
t.binding(map);
String str = t.render();
AssertJUnit.assertEquals(this.getFileContent("/function/function_expected.html"), str);
t = gt.getTemplate("/function/function_template.html");
t.binding(map);
str = t.render();
AssertJUnit.assertEquals(this.getFileContent("/function/function_expected.html"), str);
}
開發者ID:javamonkey,項目名稱:beetl2.0,代碼行數:19,
示例11: testArrayMap
點讚 3
import org.beetl.core.Template; //導入方法依賴的package包/類
@Test
public void testArrayMap() throws Exception
{
Template t = gt.getTemplate("/exp/set_template.html");
int[] c = new int[]{1,2};
int[][] d = new int[][]{{1,2},{3,4}};
t.binding("c", c);
t.binding("d", d);
String str = t.render();
AssertJUnit.assertEquals(this.getFileContent("/exp/set_expected.html"), str);
t = gt.getTemplate("/exp/set_template.html");
t.binding("c", c);
t.binding("d", d);
str = t.render();
AssertJUnit.assertEquals(this.getFileContent("/exp/set_expected.html"), str);
}
開發者ID:javamonkey,項目名稱:beetl2.0,代碼行數:18,
示例12: testPojo
點讚 3
import org.beetl.core.Template; //導入方法依賴的package包/類
@Test
public void testPojo() throws Exception
{
Template t = gt.getTemplate("/exp/set_pojo_template.html");
User user = new User("joelli");
User lover = new User("lucymiao");
t.binding("user", user);
t.binding("lover", lover);
String str = t.render();
AssertJUnit.assertEquals(this.getFileContent("/exp/set_pojo_expected.html"), str);
t = gt.getTemplate("/exp/set_pojo_template.html");
t.binding("user", user);
t.binding("lover", lover);
str = t.render();
AssertJUnit.assertEquals(this.getFileContent("/exp/set_pojo_expected.html"), str);
}
開發者ID:javamonkey,項目名稱:beetl2.0,代碼行數:18,
示例13: generateModel
點讚 2
import org.beetl.core.Template; //導入方法依賴的package包/類
public void generateModel(DbModel model, String templatePath, Map paras) {
if ( StrKit.isBlank(templatePath) ) templatePath = MAVEN_BASE + "gen/pojo/4ActiveRecordEnhance.btl";
Template t_pojo = gt.getTemplate(templatePath);
t_pojo.binding(paras);
Generate generate = (Generate) paras.get("generate");
File file = getCodeGenerateFile(generate, "model", model.getClassName() + ".java");
System.out.println(file.getAbsolutePath());
try {
FileKit.write(t_pojo.render(), file);
} catch ( FileNotFoundException | BeetlException e ) {
e.printStackTrace();
}
System.out.println("############generateModel success############");
}
開發者ID:slashchenxiaojun,項目名稱:wall.e,代碼行數:16,
示例14: generateController
點讚 2
import org.beetl.core.Template; //導入方法依賴的package包/類
public void generateController(DbModel model, String templatePath, Map paras) {
if ( StrKit.isBlank(templatePath) ) templatePath = MAVEN_BASE + "gen/web/4Jfinalcontroller.btl";
Template t_pojo = gt.getTemplate(templatePath);
t_pojo.binding(paras);
Generate generate = (Generate) paras.get("generate");
File file = getCodeGenerateFile(generate, "controller", model.getClassName() + "Controller.java");
System.out.println(file.getAbsolutePath());
try {
FileKit.write(t_pojo.render(), file);
} catch ( FileNotFoundException | BeetlException e ) {
e.printStackTrace();
}
System.out.println("############generateController success############");
}
開發者ID:slashchenxiaojun,項目名稱:wall.e,代碼行數:16,
示例15: generateService
點讚 2
import org.beetl.core.Template; //導入方法依賴的package包/類
public void generateService(DbModel model, String templatePath, Map paras) {
if ( StrKit.isBlank(templatePath) ) templatePath = MAVEN_BASE + "gen/web/4webservice.btl";
Template t_pojo = gt.getTemplate(templatePath);
t_pojo.binding(paras);
Generate generate = (Generate) paras.get("generate");
File file = getCodeGenerateFile(generate, "service", model.getClassName() + "Service.java");
System.out.println(file.getAbsolutePath());
try {
FileKit.write(t_pojo.render(), file);
} catch ( FileNotFoundException | BeetlException e ) {
e.printStackTrace();
}
System.out.println("############generateService success############");
}
開發者ID:slashchenxiaojun,項目名稱:wall.e,代碼行數:16,
示例16: generateSql
點讚 2
import org.beetl.core.Template; //導入方法依賴的package包/類
public void generateSql(DbModel model, String templatePath, Map paras) {
if ( StrKit.isBlank(templatePath) ) templatePath = MAVEN_BASE + "gen/web/4mysqlmd.btl";
Template t_pojo = gt.getTemplate(templatePath);
t_pojo.binding(paras);
Generate generate = (Generate) paras.get("generate");
File file = getCodeGenerateFile(generate, "model", model.getClassName().toLowerCase() + ".sql.md");
System.out.println(file.getAbsolutePath());
try {
FileKit.write(t_pojo.render(), file);
} catch ( FileNotFoundException | BeetlException e ) {
e.printStackTrace();
}
System.out.println("############generateSql success############");
}
開發者ID:slashchenxiaojun,項目名稱:wall.e,代碼行數:16,
示例17: generateInterfaceMarkdownDoc
點讚 2
import org.beetl.core.Template; //導入方法依賴的package包/類
public void generateInterfaceMarkdownDoc(Object projectId, String templatePath) {
if ( StrKit.isBlank(templatePath) ) templatePath = MAVEN_BASE + "gen/web/4interfaceMarkdownDoc.btl";
Template t_md = gt.getTemplate(templatePath);
Project project = Project.dao.findById(projectId);
if ( project == null ) return;
List folderList = Folder.dao.find("SELECT * FROM w_folder WHERE w_project_id = ?", projectId);
Map> interfaceMap = new HashMap<>();
Map> parameterMap = new HashMap<>();
for ( Folder folder : folderList ) {
List interfaceList = Interface.dao.find("SELECT * FROM w_interface WHERE w_project_id = ? AND w_folder_id = ? order by seq asc", projectId, folder.getId());
interfaceMap.put(folder.getName(), interfaceList);
for ( Interface anInterface : interfaceList ) {
List parameterList = Parameter.dao.find("SELECT * FROM w_parameter WHERE w_interface_id = ? order by seq asc", anInterface.getId());
// 接口返回數據UI優化
// String data = anInterface.getData();
// if ( StrKit.notBlank(data) ) {
// data = data.replaceAll("\\}", " \\}");
// anInterface.setData(data);
// }
parameterMap.put(anInterface.getCode(), parameterList);
}
}
t_md.binding("folderList", folderList);
t_md.binding("interfaceMap", interfaceMap);
t_md.binding("parameterMap", parameterMap);
File file = getConfigGenerateFile("", project.getName() + "-接口文檔.md");
System.out.println(file.getAbsolutePath());
try {
FileKit.write(t_md.render(), file);
} catch ( Exception e ) {
e.printStackTrace();
}
System.out.println("############Generate Interface Markdown Doc success############");
}
開發者ID:slashchenxiaojun,項目名稱:wall.e,代碼行數:39,
示例18: test_pojo
點讚 2
import org.beetl.core.Template; //導入方法依賴的package包/類
public void test_pojo() {
// 基礎目錄
// String basePath = "";
int id = 5;
gt.registerFunction("camelNameConvert", new CamelNameConvert());
gt.registerFunction("firstCharToLowerCase", new FirstCharToLowerCase());
gt.registerFunction("toLowerCase", new ToLowerCase());
DbModel model = DbModel.dao.findById(id);
List columns = DbModelItem.dao.find("select * from w_db_model_item where w_model_id = ? order by serial", id);
Generate generate = Generate.dao.findFirst("select * from w_generate where w_model_id = ?", id);
// 查找出跟model有關的list
List master = Db.find("select b.class_name, a.*, c.package, c.module_name from w_db_model_mapping a, w_db_model b, w_generate c where a.master_id = b.id and a.slaves_id = ? and a.master_id = c.w_model_id", id);
// 查找出跟model相關的從表
List slaves = Db.find("SELECT a.class_name, b.*, c.package, c.module_name FROM w_db_model a, w_db_model_mapping b, w_generate c WHERE a.id = b.slaves_id AND b.master_id = ? and c.w_model_id = b.slaves_id", id);
Template t = gt.getTemplate("gen/pojo/4ActiveRecordEnhance.btl");
t.binding("model", model);
t.binding("columns", columns);
t.binding("importNotNull", true);
t.binding("importLength", true);
t.binding("importNotBlank", true);
t.binding("generate", generate);
t.binding("master", master);
t.binding("slaves", slaves);
// 是否使用駝峰命名
t.binding("camelName", true);
System.out.println(t.render());
}
開發者ID:slashchenxiaojun,項目名稱:wall.e,代碼行數:33,
示例19: process
點讚 2
import org.beetl.core.Template; //導入方法依賴的package包/類
@Override
public WordprocessingMLPackage process(Map variables) throws Exception {
//使用Beetl模板引擎渲染模板
Template template = getEngine().getTemplate(templateKey);
template.binding(variables);
//獲取模板渲染後的結果
String html = template.render();
//使用HtmlTemplate進行渲染
return new WordprocessingMLHtmlTemplate(html , altChunk).process(variables);
}
開發者ID:vindell,項目名稱:docx4j-template,代碼行數:11,
示例20: gen
點讚 2
import org.beetl.core.Template; //導入方法依賴的package包/類
@Override
public List gen(Project project) throws IOException {
Template t = TemplatesLoader.load("templates/pom.xml");
t.binding("project", project);
File pom = Files.createFileIfNoExists(project.getOutput() + "/pom.xml");
Files.write(pom, t.render());
return Lang.array2list(new File[] { pom });
}
開發者ID:Kerbores,項目名稱:Nutz-matic,代碼行數:9,
示例21: gen
點讚 2
import org.beetl.core.Template; //導入方法依賴的package包/類
@Override
public List gen(Project project) throws IOException {
Template t = TemplatesLoader.load("templates/web.xml");
t.binding("project", project);
File webxml = Files.createFileIfNoExists(project.getOutput() + "/" + project.getName() + "/src/main/webapp/WEB-INF/web.xml");
Files.write(webxml, t.render());
return Lang.array2list(new File[] { webxml });
}
開發者ID:Kerbores,項目名稱:Nutz-matic,代碼行數:10,
示例22: gen
點讚 2
import org.beetl.core.Template; //導入方法依賴的package包/類
@Override
public List gen(Project project) throws IOException {
List files = new ArrayList();
for (Table table : project.getTables()) {
// domain
Template t = TemplatesLoader.load("templates/src/main/java/club/zhcs/thunder/bean/Table.java");
t.binding("project", project);
t.binding("table", table);
File domain = Files.createFileIfNoExists(project.getOutput() + "/" + project.getName() + "/src/main/java/" + project.getPackagePath() + "bean/" + table.getClassName()
+ ".java");
Files.write(domain, t.render());
files.add(domain);
// service
t = TemplatesLoader.load("templates/src/main/java/club/zhcs/thunder/service/Service.java");
t.binding("project", project);
t.binding("table", table);
File service = Files.createFileIfNoExists(project.getOutput() + "/" + project.getName() + "/src/main/java/" + project.getPackagePath() + "service/"
+ table.getClassName()
+ "Service.java");
Files.write(service, t.render());
files.add(service);
// module
t = TemplatesLoader.load("templates/src/main/java/club/zhcs/thunder/module/Module.java");
t.binding("project", project);
t.binding("table", table);
File module = Files.createFileIfNoExists(project.getOutput() + "/" + project.getName() + "/src/main/java/" + project.getPackagePath() + "module/"
+ table.getClassName()
+ "Module.java");
Files.write(module, t.render());
files.add(module);
}
return files;
}
開發者ID:Kerbores,項目名稱:Nutz-matic,代碼行數:38,
示例23: gen
點讚 2
import org.beetl.core.Template; //導入方法依賴的package包/類
@Override
public List gen(Project project) throws IOException {
Template t = TemplatesLoader.load("templates/src/main/resources/conf/config.properties");
t.binding("db", project.getDb());
File config = Files.createFileIfNoExists(project.getOutput() + "/" + project.getName() + "/src/main/resources/conf/config.properties");
Files.write(config, t.render());
return Lang.array2list(new File[] { config });
}
開發者ID:Kerbores,項目名稱:Nutz-matic,代碼行數:10,
示例24: exportDatabaseHtml
點讚 2
import org.beetl.core.Template; //導入方法依賴的package包/類
/**
* ����һ�����ݿ��html�ļ�
*
* @param tables
* @param filePath
* @param fileName
* @return
* @throws IOException
*/
public static String exportDatabaseHtml(List tables, String filePath, String fileName) throws IOException {
mkdirs(filePath);
Template t = gt.getTemplate("datebase.html");
t.binding("tables", tables);
t.binding("fileName", fileName);
String path = filePath + File.separator + fileName + ".html";
render(t, path);
return path;
}
開發者ID:abel533,項目名稱:DBMetadata,代碼行數:19,
示例25: exportTableHtml
點讚 2
import org.beetl.core.Template; //導入方法依賴的package包/類
/**
* ����һ��Table��html�ļ�
*
* @param table
* @return
* @throws IOException
*/
public static String exportTableHtml(IntrospectedTable table, String filePath, String fileName) throws IOException {
mkdirs(filePath);
Template t = gt.getTemplate("table.html");
t.binding("table", table);
t.binding("fileName", table.getName());
String path = filePath + File.separator + fileName + ".html";
render(t, path);
return path;
}
開發者ID:abel533,項目名稱:DBMetadata,代碼行數:17,
示例26: render
點讚 2
import org.beetl.core.Template; //導入方法依賴的package包/類
@Override
public void render()
{
if (args.length == 0 || args.length > 3)
{
throw new RuntimeException("參數錯誤,期望child,map");
}
String layoutFile = getRelResourceId();
Template t = this.gt.getTemplate(layoutFile, this.ctx.getResourceId());
t.binding(ctx.globalVar);
t.dynamic(ctx.objectKeys);
if (args.length >= 2)
{
Map map = (Map) args[1];
for (Entry entry : map.entrySet())
{
t.binding(entry.getKey(), entry.getValue());
}
}
BodyContent content = this.getBodyContent();
if (args.length == 3)
{
t.binding((String) args[2], content);
}
else
{
t.binding(defaultLayoutName, content);
}
t.renderTo(ctx.byteWriter);
}
開發者ID:javamonkey,項目名稱:beetl2.0,代碼行數:36,
示例27: render
點讚 2
import org.beetl.core.Template; //導入方法依賴的package包/類
@Override
public void render()
{
String resourceId = getRelResourceId();
;
Template t = gt.getTemplate(resourceId, this.ctx.getResourceId());
//快速複製父模板的變量
t.binding(this.ctx.globalVar);
if (ctx.objectKeys != null && ctx.objectKeys.size() != 0)
{
t.dynamic(ctx.objectKeys);
}
if (this.args.length == 2)
{
Map map = (Map) this.args[1];
for (Entry entry : map.entrySet())
{
Object value = entry.getValue();
if (value instanceof Map || value instanceof Collection)
{
t.binding((String) entry.getKey(), value, true);
}
else
{
t.binding((String) entry.getKey(), value);
}
}
}
ByteWriter bw = ctx.byteWriter;
t.renderTo(bw);
}
開發者ID:javamonkey,項目名稱:beetl2.0,代碼行數:38,
示例28: doExecute
點讚 2
import org.beetl.core.Template; //導入方法依賴的package包/類
protected void doExecute(String locationArg, ActionInvocation invocation) throws Exception
{
ActionContext ctx = invocation.getInvocationContext();
HttpServletRequest req = (HttpServletRequest) ctx.get(ServletActionContext.HTTP_REQUEST);
HttpServletResponse rsp = (HttpServletResponse) ctx.get(ServletActionContext.HTTP_RESPONSE);
if (!locationArg.startsWith("/"))
{
String base = ResourceUtil.getResourceBase(req);
locationArg = base + "/" + locationArg;
}
Object action = invocation.getAction();
Map values = reflectionProvider.getBeanMap(action);
rsp.setContentType(this.pContentType);
WebRender render = new WebRender(groupTemplate) {
protected void modifyTemplate(Template template, String key, HttpServletRequest request,
HttpServletResponse response, Object... args)
{
Map model = (Map) args[0];
for (Object o : model.entrySet())
{
Entry entry = (Entry) o;
String name = (String) entry.getKey();
Object value = entry.getValue();
template.binding(name, value);
}
}
};
render.render(locationArg, req, rsp, values);
}
開發者ID:javamonkey,項目名稱:beetl2.0,代碼行數:36,
示例29: testSimple
點讚 2
import org.beetl.core.Template; //導入方法依賴的package包/類
@Test
public void testSimple() throws Exception
{
Configuration conf = Configuration.defaultConfiguration();
CompositeResourceLoader loader = new CompositeResourceLoader();
String home = System.getProperty("user.dir");
String path1 = home + "/src/test/resources/template/resourceloader/var1";
String path2 = home + "/src/test/resources/template/resourceloader/var2";
FileResourceLoader fileLoader1 = new FileResourceLoader(path1);
FileResourceLoader fileLoader2 = new FileResourceLoader(path2);
Map data = getData();
// 根據id加載
MapResourceLoader mapLoader = new MapResourceLoader(data);
loader.addResourceLoader(new StartsWithMatcher("http:").withoutPrefix(), fileLoader2);
loader.addResourceLoader(new StartsWithMatcher("db:").withoutPrefix(), mapLoader);
loader.addResourceLoader(new AllowAllMatcher(), fileLoader1);
GroupTemplate gt = new GroupTemplate(loader, conf);
Template t = gt.getTemplate("/xxx.html");
t.binding("a", "hello");
String result = t.render();
;
AssertJUnit.assertEquals("hellohello--file2:hello--db=hello", result);
}
開發者ID:javamonkey,項目名稱:beetl2.0,代碼行數:29,
示例30: testExtraLoader
點讚 2
import org.beetl.core.Template; //導入方法依賴的package包/類
@Test
public void testExtraLoader() throws Exception
{
Map data = getData();
MapResourceLoader strLoader = new MapResourceLoader(data);
Template t = gt.getTemplate("db:1", strLoader);
t.binding("a", "abc");
String result = t.render();
AssertJUnit.assertEquals("abc", result);
}
開發者ID:javamonkey,項目名稱:beetl2.0,代碼行數:13,
示例31: testHolderInAttr
點讚 2
import org.beetl.core.Template; //導入方法依賴的package包/類
@Test
public void testHolderInAttr() throws Exception
{
Template t = gt.getTemplate("/tag/html8_template.html");
t.binding("a", 1);
String str = t.render();
AssertJUnit.assertEquals(this.getFileContent("/tag/html8_expected.html"), str);
t = gt.getTemplate("/tag/html8_template.html");
t.binding("a", 1);
str = t.render();
AssertJUnit.assertEquals(this.getFileContent("/tag/html8_expected.html"), str);
}
開發者ID:javamonkey,項目名稱:beetl2.0,代碼行數:16,
示例32: testInt
點讚 2
import org.beetl.core.Template; //導入方法依賴的package包/類
@Test
public void testInt() throws Exception
{
Template t = gt.getTemplate("/exp/array/int_array_template.html");
int[] array = new int[]
{ 1, 2 };
t.binding("array", array);
String str = t.render();
AssertJUnit.assertEquals(this.getFileContent("/exp/array/int_array_expected.html"), str);
t = gt.getTemplate("/exp/array/int_array_template.html");
t.binding("array", array);
str = t.render();
AssertJUnit.assertEquals(this.getFileContent("/exp/array/int_array_expected.html"), str);
}
開發者ID:javamonkey,項目名稱:beetl2.0,代碼行數:16,
示例33: testAsign
點讚 2
import org.beetl.core.Template; //導入方法依賴的package包/類
@Test
public void testAsign() throws Exception
{
Template t = gt.getTemplate("/exp/assign/assign_template.html");
t.binding("d", 100);
String str = t.render();
AssertJUnit.assertEquals(this.getFileContent("/exp/assign/assign_expected.html"), str);
t = gt.getTemplate("/exp/assign/assign_template.html");
t.binding("d", 100);
str = t.render();
AssertJUnit.assertEquals(this.getFileContent("/exp/assign/assign_expected.html"), str);
}
開發者ID:javamonkey,項目名稱:beetl2.0,代碼行數:14,
示例34: testLeftAsign
點讚 2
import org.beetl.core.Template; //導入方法依賴的package包/類
@Test
public void testLeftAsign() throws Exception
{
Template t = gt.getTemplate("/exp/assign/left_template.html");
t.binding("d", 100);
String str = t.render();
AssertJUnit.assertEquals(this.getFileContent("/exp/assign/left_expected.html"), str);
t = gt.getTemplate("/exp/assign/left_template.html");
t.binding("d", 100);
str = t.render();
AssertJUnit.assertEquals(this.getFileContent("/exp/assign/left_expected.html"), str);
}
開發者ID:javamonkey,項目名稱:beetl2.0,代碼行數:14,
示例35: main
點讚 2
import org.beetl.core.Template; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
StringTemplateResourceLoader resourceLoader = new StringTemplateResourceLoader();
Configuration cfg = Configuration.defaultConfiguration();
GroupTemplate gt = new GroupTemplate(resourceLoader, cfg);
Template t = gt.getTemplate("hello,${name}");
t.binding("name", "beetl");
String str = t.render();
System.out.println(str);
}
開發者ID:javamonkey,項目名稱:beetl2.0,代碼行數:11,
示例36: testSimple
點讚 2
import org.beetl.core.Template; //導入方法依賴的package包/類
@Test
public void testSimple() throws Exception
{
Pojo p = new Pojo();
Template t = gt.getTemplate("/lang/pojo_template.html");
t.binding("p",p);
String str = t.render();
AssertJUnit.assertEquals(this.getFileContent("/lang/pojo_expected.html"), str);
}
開發者ID:javamonkey,項目名稱:beetl2.0,代碼行數:12,
示例37: testWrongSimple
點讚 2
import org.beetl.core.Template; //導入方法依賴的package包/類
@Test
public void testWrongSimple() throws Exception
{
Pojo2 p = new Pojo2();
Template t = gt.getTemplate("/lang/pojo2_template.html");
t.binding("p",p);
String str = t.render();
AssertJUnit.assertEquals(this.getFileContent("/lang/pojo2_expected.html"), str);
}
開發者ID:javamonkey,項目名稱:beetl2.0,代碼行數:12,
示例38: generateDB
點讚 2
import org.beetl.core.Template; //導入方法依賴的package包/類
/**
* 生成db數據庫文件
*
* 默認模板路徑: gen/db/4mysqldb.btl
*
* @param model
* @param templatePath 代碼生成的模板路徑
* @param dbName 需要創建表的數據庫名
*/
public void generateDB(DbModel model, String templatePath, String dbName) {
if ( model == null || model.getId() == null )
throw new GenerateException("Oop~ model is null.");
if ( StrKit.isBlank(templatePath) ) templatePath = MAVEN_BASE + "gen/db/4mysqldb.btl";
Object id = model.getId();
List columns = DbModelItem.dao.find("select * from w_db_model_item where w_model_id = ? order by serial", id);
List slaves = DbModelMapping.dao.find("select * from w_db_model_mapping where master_id = ?", id);
// List master = Db.find("select t1.*, b.length, b.type from (select * from w_db_model_mapping where slaves_id = ?) t1, w_db_model_item b where b.w_model_id = t1.master_id and b.`name` = t1.mapping_foreign_key", id);
// 修改數據結構,現在所有的關係,均使用中間表來表示
// 當且僅當相關從表中含有ManyToMany關係時生成中間表
// List mapping = new ArrayList<>();
// for(DbModelMapping mm : slaves) {
// if(mm.getMappingSchema().equals("ManyToMany")) {
// mapping.add(mm);
// }
// }
// 當且僅當相關主表中含有oneToMany關係時需要生成外鍵
// List foreign = new ArrayList<>();
// for(Record mm : master) {
// if(mm.getStr("mapping_schema").equals("oneToMany")) {
// foreign.add(mm);
// }
// }
Generate generate = Generate.dao.findFirst("select * from w_generate where w_model_id = ?", id);
Map paras = new HashMap<>();
paras.put("db", dbName);
paras.put("model", model);
paras.put("columns", columns);
paras.put("mapping", slaves);
// 添加生成信息
paras.put("generate", generate);
// paras.put("foreign", foreign);
Template template = gt.getTemplate(templatePath);
template.binding(paras);
String[] sqls = template.render().split(";");
try {
for ( String sql : sqls ) {
if ( StrKit.isBlank(sql) ) continue;
Db.update(sql);
}
} finally {
// 返回walle的數據庫
Db.update("USE `" + generateDbName + "`");
}
System.out.println("############generateDB success############");
}
開發者ID:slashchenxiaojun,項目名稱:wall.e,代碼行數:65,
示例39: generateInterfaceControllerCode
點讚 2
import org.beetl.core.Template; //導入方法依賴的package包/類
public void generateInterfaceControllerCode(Object projectId, String classPath, String beanClassPath, String templatePath) {
if ( StrKit.isBlank(templatePath) ) templatePath = MAVEN_BASE + "gen/web/4interfaceControllerTemp00.btl";
Template t_controller = gt.getTemplate(templatePath);
Project project = Project.dao.findById(projectId);
if ( project == null ) return;
List folderList = Folder.dao.find("SELECT * FROM w_folder WHERE w_project_id = ?", projectId);
if ( folderList == null ) return;
// 一個目錄相當於一個controller
for ( Folder folder : folderList ) {
String moduleName = folder.getName().toLowerCase();
String className = StrKit.firstCharToUpperCase(folder.getName()) + "Controller";
String controllerClassPath = classPath +
File.separator + "module" +
File.separator + moduleName +
File.separator + "controller";
File file = getConfigGenerateFile(controllerClassPath, className + ".java");
t_controller.binding("classPath", classPath.replaceAll(Matcher.quoteReplacement(File.separator), "."));
t_controller.binding("moduleName", moduleName);
t_controller.binding("className", className);
t_controller.binding("beanClassPath", beanClassPath.replaceAll(Matcher.quoteReplacement(File.separator), "."));
// 獲取接口
List interfaceList = Interface.dao.find("SELECT * FROM w_interface WHERE w_project_id = ? AND w_folder_id = ? order by seq asc", projectId, folder.getId());
List beanNameList = new ArrayList<>();
// 特殊的沒有bean的接口,使用接口code -> 參數名字來做存儲
/**
* @ActionKey("/root/xx/${hhId}")
* public void xx() {}
* xx -> hhId
*
* xx 就是接口的code
*/
Map interfaceParamMap = new HashMap<>();
// 沒有參數的接口map
Map noParaminterfaceMap = new HashMap<>();
for ( Interface anInterface : interfaceList ) {
boolean hasBean = Db.findFirst("SELECT COUNT(1) FROM w_parameter WHERE w_interface_id = ?", anInterface.getId()).getLong("COUNT(1)") > 0;
if ( StrKit.notBlank(anInterface.getCode()) && hasBean ) {
beanNameList.add(StrKit.firstCharToUpperCase(anInterface.getCode()) + "Bean");
} else {
noParaminterfaceMap.put(anInterface.getCode(), "no bean");
}
// 沒有參數
boolean isUrlParam = false;
String url = anInterface.getRelativeUrl();
if ( StrKit.isBlank(url) ) {
System.err.println(String.format("接口[%s:(%s)]沒有填寫url", anInterface.getName(), anInterface.getCode()));
continue;
}
isUrlParam = url.matches(".*/\\$\\{[A-Za-z_]+\\}$");
if ( StrKit.notBlank(anInterface.getCode()) && isUrlParam ) {
int start = url.indexOf("/${");
int end = url.indexOf("}");
url = url.substring(start + 3, end);
// 將${}中的東西寫入
interfaceParamMap.put(anInterface.getCode(), url);
}
}
t_controller.binding("interfaceParamMap", interfaceParamMap);
t_controller.binding("beanNameList", beanNameList);
t_controller.binding("interfaceList", interfaceList);
t_controller.binding("noParaminterfaceMap", noParaminterfaceMap);
System.out.println(file.getAbsolutePath());
try {
FileKit.write(t_controller.render(), file);
} catch ( Exception e ) {
e.printStackTrace();
}
}
System.out.println("############Generate interface controller code success############");
}
開發者ID:slashchenxiaojun,項目名稱:wall.e,代碼行數:77,
示例40: generateInterfaceServiceCode
點讚 2
import org.beetl.core.Template; //導入方法依賴的package包/類
/**
* 用戶編寫業務代碼的service,為了防止生成controller和bean代碼不被覆蓋
* 這個方法在被調用時,需要做一次密碼身份認證,以免菜鳥勿用
*
* @param projectId 項目id
* @param folderId 如果有該數據,隻生成當前的目錄接口的service,其他忽略
* @param classPath 生成代碼的路徑
* @param beanClassPath 相關bean代碼的路徑
* @param templatePath 使用的模版
*/
public void generateInterfaceServiceCode(Object projectId, Object folderId, String classPath, String beanClassPath, String templatePath) {
if ( StrKit.isBlank(templatePath) ) templatePath = MAVEN_BASE + "gen/web/4interfaceServiceTemp00.btl";
Template t_service = gt.getTemplate(templatePath);
Project project = Project.dao.findById(projectId);
if ( project == null ) return;
List folderList = Folder.dao.find("SELECT * FROM w_folder WHERE w_project_id = ?", projectId);
if ( folderList == null ) return;
// 一個目錄相當於一個controller
for ( Folder folder : folderList ) {
// 忽略其他folder目錄下的service生成請求
if ( !( folderId != null && folderId.equals(folder.getId()) ) ) {
continue;
}
String moduleName = folder.getName().toLowerCase();
String className = "__" + StrKit.firstCharToUpperCase(folder.getName()) + "ControllerService__";
String serviceClassPath = classPath +
File.separator + "module" +
File.separator + moduleName +
File.separator + "service";
File file = getConfigGenerateFile(serviceClassPath, className + ".java");
t_service.binding("classPath", classPath.replaceAll(Matcher.quoteReplacement(File.separator), "."));
t_service.binding("moduleName", moduleName);
t_service.binding("className", className);
t_service.binding("beanClassPath", beanClassPath.replaceAll(Matcher.quoteReplacement(File.separator), "."));
// 獲取接口
List interfaceList = Interface.dao.find("SELECT * FROM w_interface WHERE w_project_id = ? AND w_folder_id = ? order by seq asc", projectId, folder.getId());
List beanNameList = new ArrayList<>();
Map interfaceParamMap = new HashMap<>();
for ( Interface anInterface : interfaceList ) {
boolean hasBean = Db.findFirst("SELECT COUNT(1) FROM w_parameter WHERE w_interface_id = ?", anInterface.getId()).getLong("COUNT(1)") > 0;
if ( StrKit.notBlank(anInterface.getCode()) && hasBean )
beanNameList.add(StrKit.firstCharToUpperCase(anInterface.getCode()) + "Bean");
// 沒有參數
boolean isUrlParam = false;
String url = anInterface.getRelativeUrl();
isUrlParam = url.matches(".*/\\$\\{[A-Za-z_]+\\}$");
if ( StrKit.notBlank(anInterface.getCode()) && isUrlParam ) {
int start = url.indexOf("/${");
int end = url.indexOf("}");
url = url.substring(start + 3, end);
// 將${}中的東西寫入
interfaceParamMap.put(anInterface.getCode(), url);
}
}
t_service.binding("interfaceParamMap", interfaceParamMap);
t_service.binding("beanNameList", beanNameList);
t_service.binding("interfaceList", interfaceList);
System.out.println(file.getAbsolutePath());
try {
FileKit.write(t_service.render(), file);
} catch ( Exception e ) {
e.printStackTrace();
}
}
System.out.println("############Generate interface service code success############");
}
開發者ID:slashchenxiaojun,項目名稱:wall.e,代碼行數:72,
示例41: generate
點讚 2
import org.beetl.core.Template; //導入方法依賴的package包/類
public static void generate(RunPlanBean rpb) {
try {
System.out.println(rpb.toString());
String root = TPController.class.getClassLoader().getResource("").getPath() + "beetl";
FileResourceLoader resourceLoader = new FileResourceLoader(root, "utf-8");
Configuration cfg = Configuration.defaultConfiguration();
GroupTemplate gt = new GroupTemplate(resourceLoader, cfg);
Template t = gt.getTemplate("/http_request.jmx");
t.binding("v_duration", rpb.getDuration());
t.binding("v_users_num", rpb.getUsersNum());
t.binding("v_ramp_up", rpb.getRampUp());
TestPlanBean tpb = rpb.getTestPlanBean(); // TODO: [email protected]/3/13 不夠優雅,改成解析成map,直接binding map
if (null != tpb) {
t.binding("v_server_name", tpb.getServerNameIp());
t.binding("v_port", tpb.getPortNum());
t.binding("v_prol", tpb.getProtocol());
t.binding("v_path", tpb.getPath());
} else {
t.binding("v_server_name", "111");
t.binding("v_port", "222");
t.binding("v_prol", "333");
t.binding("v_path", "444");
}
String jmxRoot = System.getProperty("user.dir")+JMX_PATH;//係統(項目)路徑,結尾無斜杠
//jmx在係統(項目)中的存在路徑,斜杠開頭,結尾無斜杠
String fullPath = jmxRoot+StringUtils.creAndGetDir(jmxRoot); //返回的應該是 c:/jmx/2017/03 ,並創建這個目錄
//文件名,斜杠開頭
String fileName = new StringBuilder(File.separator)
.append(JMX_NAME_PREFIX)
.append(StringUtils.getDate("yyyyMMddHHmmssSSS"))
.append(JMX_NAME_SUFFIX)
.toString();
String jmxFilePath = fullPath+fileName;
rpb.setJmxPath(jmxFilePath);
OutputStream ops = new FileOutputStream(jmxFilePath);
t.renderTo(ops);
} catch (Exception e) {
e.printStackTrace();
}
}
開發者ID:wang153723482,項目名稱:testing_platform,代碼行數:49,
示例42: render
點讚 2
import org.beetl.core.Template; //導入方法依賴的package包/類
public void render(String key, HttpServletRequest request, HttpServletResponse response, Object... args) {
PrintWriter writer = null;
ServletOutputStream os = null;
String ajaxId = null;
Template template = null;
try {
int e = key.lastIndexOf("#");
if(e != -1) {
ajaxId = key.substring(e + 1);
key = key.substring(0, e);
template = this.gt.getAjaxTemplate(key, ajaxId);
} else {
template = this.gt.getTemplate(key);
}
Enumeration attrs = request.getAttributeNames();
while(attrs.hasMoreElements()) {
String webVariable = (String)attrs.nextElement();
template.binding(webVariable, request.getAttribute(webVariable));
}
WebVariable webVariable1 = new WebVariable();
webVariable1.setRequest(request);
webVariable1.setResponse(response);
template.binding("session", new SessionWrapper(webVariable1.getRequest(),webVariable1.getSession()));
template.binding("servlet", webVariable1);
template.binding("request", request);
template.binding("ctxPath", request.getContextPath());
this.modifyTemplate(template, key, request, response, args);
if(this.gt.getConf().isDirectByteOutput()) {
os = response.getOutputStream();
template.renderTo(os);
} else {
writer = response.getWriter();
template.renderTo(writer);
}
} catch (IOException var22) {
this.handleClientError(var22);
} catch (BeetlException var23) {
this.handleBeetlException(var23);
}
}
開發者ID:T-baby,項目名稱:ICERest-plugin,代碼行數:45,
示例43: main
點讚 2
import org.beetl.core.Template; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
ClasspathResourceLoader resourceLoader = new ClasspathResourceLoader("org/beetl/core/lab/");
Configuration cfg = Configuration.defaultConfiguration();
cfg.setDirectByteOutput(true);
cfg.getResourceMap().put("tagRoot", "/");
cfg.getPkgList().add("org.beetl.core.lab.");
GroupTemplate gt = new GroupTemplate(resourceLoader, cfg);
//cfg.setStatementStart("@");
//cfg.setStatementEnd(null);
// cfg.setPlaceholderStart("{{");
// cfg.setPlaceholderEnd("}}");
//
gt.registerFunction("test", new TestFun());
gt.registerTag("test", TestTag.class);
List list = new ArrayList();
list.add(null);
list.add(new TestUser("abc"));
HashMap map = new HashMap();
map.put("key", 123);
for (int i = 0; i < 1; i++) {
Template t = gt.getTemplate("/hello.txt");
t.binding("user", new TestUser("jo"));
t.binding("id", 2);
ByteArrayOutputStream bs = new ByteArrayOutputStream();
try {
t.renderTo(bs);
} catch (Exception ex) {
ex.printStackTrace();
}
//TestUser test = new TestUser("a");
//test.setLover(new TestUser("b"));
//t.binding("user", test);
System.out.println(t.render());
}
}
開發者ID:javamonkey,項目名稱:beetl2.0,代碼行數:49,
示例44: getTemplateToString
點讚 1
import org.beetl.core.Template; //導入方法依賴的package包/類
/**
* 將寫好的template轉化為String(接受參數)
*
* @param templatePath 模板路徑(包含模板全名)
* @param param 參數
* **/
public static String getTemplateToString(String templatePath, Map, ?> param){
Template t = groupTemplate.getTemplate(templatePath);
t.binding(param);
return t.render();
}
開發者ID:slashchenxiaojun,項目名稱:wall.e,代碼行數:12,
注:本文中的org.beetl.core.Template.binding方法示例整理自Github/MSDocs等源碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。