sql转java代码 sql文件转换
如何利用SQL中数据使用FreeMarker生成JAVA实体bean代码
利用freemarker生成JAVA BEAN
安丘网站制作公司哪家好,找创新互联公司!从网页设计、网站建设、微信开发、APP开发、成都响应式网站建设公司等网站项目制作,到程序开发,运营维护。创新互联公司自2013年起到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选创新互联公司。
Freemarker模板代码如下:
package ${packageName};
/**
* #if author == "adams" @author adams /#if
*/
pulic class ${className} {
#list attrs as a
private ${a.type} ${a.field};
/#list
#list attrs as a
public void set${a.field?cap_first}(${a.type} ${a.field}){
this.${a.field} = ${a.field};
}
public ${a.type} get${a.field?cap_first}(){
return this.${a.field};
}
/#list
}
Java代码如下
package com.my.learn.freemarker;
public class Attr{
public String field;
public String type;
public Attr(String field, String type){
this.field = field;
this.type = type;
}
public String getField(){
return this.field;
}
public String getType(){
return this.type;
}
public void setField(String field){
this.field = field;
}
public void setType(String type){
this.type = type;
}
}
package com.my.learn.freemarker;
import java.io.File; import java.io.IOException; import java.io.StringWriter; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map;
import freemarker.template.Configuration; import freemarker.template.Template; import freemarker.template.TemplateException;
public class FmAppUseage {
public static void main(String[] args){
ListObject list = new ArrayListObject();
list.add(new Attr("username", "String"));
list.add(new Attr("password", "String"));
list.add(new Attr("age", "int"));
list.add(new Attr("hobby", "String"));
MapString,Object root = new HashMapString, Object();
root.put("packageName", "com.my.learn.freemarker");
root.put("className", "User");
root.put("attrs", list);
root.put("author", "adams");
Configuration cfg = new Configuration();
String path = FmAppUseage.class.getResource("/").getPath()+"template";
try {
cfg.setDirectoryForTemplateLoading(new File(path));
Template template = cfg.getTemplate("/demo.ftl");
StringWriter out = new StringWriter();
template.process(root, out);
System.out.println(out.toString());
} catch (IOException e) {
System.out.println("Cause==" + e.getCause());
} catch (TemplateException e) {
System.out.println("Cause==" + e.getCause());
}
}
}
输出结果如下:
package com.my.learn.freemarker;
/**
* @author adams
*/
pulic class User {
private String username;
private String password;
private int age;
private String hobby;
public void setUsername(String username){
this.username = username;
}
public String getUsername(){
return this.username;
}
public void setPassword(String password){
this.password = password;
}
public String getPassword(){
return this.password;
}
public void setAge(int age){
this.age = age;
}
public int getAge(){
return this.age;
}
public void setHobby(String hobby){
this.hobby = hobby;
}
public String getHobby(){
return this.hobby;
}
}
当在笔者刚做测试时,将Attr的类定义在了FmAppUseage类的内部,导致不能正常运行,只能将其移除单独成一个类时,便能正常运行了。 转载仅供参考,版权属于原作者。祝你愉快,满意请采纳哦
怎么把pl/sql代码转换成java代码
js全称是javascript看着像java,但是跟java基本上没有半毛钱关系,转不了
如何将一句很长的SQL语句转换为java语句,以下(1)在MySQL中可运行出结果,(2)为本人转换的,好像不行
mysql的时间字段类型为char(20),
String sql = "select t.* from t_book t where insert_date to_date( ' "+timeStr + " ', 'yyyy-mm-dd hh:mi:ss ') ";
这段语句我该成
String sql = "select t.* from t_book t where insert_date to_date( ' "+timeStr + " ', 'yyyy-mm-dd hh:mi:ss ') ";
当前名称:sql转java代码 sql文件转换
本文URL:http://myzitong.com/article/dohdgpi.html