一、导入maven依赖
-
<dependency>
-
<groupId>org.freemarker</groupId>
-
<artifactId>freemarker</artifactId>
-
<version>2.3.23</version>
-
</dependency>
二、新建com.freemarker.hello.templates包,并在该包下编写模板文件test.ftl
-
package ${classPath};
-
-
public class ${className} {
-
-
private Integer ${Id};
-
-
private String ${userName};
-
-
private String ${password};
-
-
-
public Integer get${Id}(){
-
-
return ${Id};
-
-
}
-
-
-
public void set${Id}(Integer ${Id}){
-
-
this.${Id}=${Id};
-
-
}
-
-
-
public String get${userName}(){
-
-
return ${userName};
-
-
}
-
-
public void set${userName}(String ${userName}){
-
-
this.${userName}=${userName};
-
-
}
-
-
-
public String get${password}(){
-
-
return ${password};
-
-
}
-
-
-
public void set${password}(String ${password}){
-
-
this.${password}=${password};
-
-
}
-
-
}
三、编写运行生成对应Java代码类
四、步骤三成功,刷新(refresh)项目即可,看到com.freemark.hello有一个User类。
阅读(1856) | 评论(0) | 转发(0) |