当前位置: 首页 > 工具软件 > Mustache > 使用案例 >

Java mustache生成代码

宰父俊彦
2023-12-01

github上下载 mustache-spring-view-master 然后

在test/resource 写一个模板文件Service.java

public class {{test}}Service {
	public String {{test}}insert(){
		return {{test}}Dao.insert();
	}
}

 然后调用生成代码

public class DDD {
	public static void main(String[] args) {
		MustacheFactory mf = new DefaultMustacheFactory();
		Mustache mustache = mf.compile("Service.java");
		Map<String, Object> content = new HashMap<>();
		content.put("test", "Login");
		StringWriter writer = new StringWriter();
		mustache.execute(writer, content);
		System.out.println(writer.toString());
	}
}

 结束,代码已生成,后面就可以写入磁盘喽

 类似资料: