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());
}
}
结束,代码已生成,后面就可以写入磁盘喽