FreeMarker_模板引擎_代码自动生成器_源码下载
运行代码:
运行代码:
生成的User.java文件:

==================================================================
代码部分: ? 你可以了解一下velocity(也是一个模板引擎):利用Velocity自动生成自定义代码_java版_源码下载
==================================================================
/freemarker/src/com/b510/freemarker/Bean.java
;121 File filePath = new File(beanPath);122 if (!filePath.exists()) {123 filePath.mkdirs();124 }125 126 String filePathOfBean = beanPath + "/User.java";127 File file = new File(filePathOfBean);128 if (!file.exists()) {129 file.createNewFile();130 }131 132 // 显示生成的数据133 writer = new FileWriter(file);134 template.process(root, writer);135 writer.flush();136 writer.close();137 }138 }/freemarker/ftls/hongten-helloworld.ftl
1 ${message}/freemarker/ftls/hongten-myJavaFile.ftl
1 package ${bean.beanUrl}; 2 3 import java.util.Date; 4 5 /** 6 * @author ${annotation.authorName}(${annotation.authorMail})<br> 7 * @date ${annotation.date} 8 * 9 * @version ${annotation.version}10 */11 public class ${bean.name} {12 13 /**14 * id号15 */16 private Integer id;17 /**18 * 姓名19 */20 private String name;21 /**22 * 性别23 */24 private String sex;25 /**26 * 生日27 */28 private Date birthday;29 30 public Integer getId() {31 return id;32 }33 34 public void setId(Integer id) {35 this.id = id;36 }37 38 public String getName() {39 return name;40 }41 42 public void setName(String name) {43 this.name = name;44 }45 46 public String getSex() {47 return sex;48 }49 50 public void setSex(String sex) {51 this.sex = sex;52 }53 54 public Date getBirthday() {55 return birthday;56 }57 58 public void setBirthday(Date birthday) {59 this.birthday = birthday;60 }61 62 }源码下载:http://files.cnblogs.com/hongten/freemarker_file.zip