日期:2014-05-17 浏览次数:20840 次
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.lang.reflect.Field;
public class kkkk {
private String ma;
private String userpassword;
public String getMa() {
return ma;
}
public void setMa(String ma) {
this.ma = ma;
}
public String getUserpassword() {
return userpassword;
}
public void setUserpassword(String userpassword) {
this.userpassword = userpassword;
}
public static void main(String[] args) throws Exception {
StringBuilder builder=new StringBuilder();
StringBuilder builderxml = new StringBuilder();
builder.append("create table user (");
builderxml.append("<? xml version = '1.0' encode='UTF-8'>");
for(Field a :kkkk.class.getDeclaredFields()){
if(a.getName().equals("ma")){
builder.append(" username varchar(10) , ");
builderxml.append("some username xml file \n");// please asseme xml by yourself
}
if(a.getName().equals("userpassword")){
builder.append(" userpassword varchar(20) ");
builderxml.append("some userpassword xml file");// please asseme xml by yourself
}
}
builder.append(")");
System.out.println(builder.toString());// create table sql by pojo
File hbmfile = new File("/user.hbm.xml");
FileWriter fileWriter = new FileWriter(hbmfile); // create hbm.xml file by pojo
System.out.println(hbmfile.getAbsolutePath());
byte[] a = builderxml.toString().getBytes();
fileWriter.write(builderxml.toString(), 0, builderxml.toString().length());
fileWriter.flush();
fileWriter.close();
}
}