public class Test8 {
class UserBean {
private String userName;
private String account;
private String roleName;
public UserBean(String userName, String account, String roleName) {
super();
this.userName = userName;
this.account = account;
this.roleName = roleName;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getAccount() {
return account;
}
public void setAccount(String account) {
this.account = account;
}
public String getRoleName() {
return roleName;
}
public void setRoleName(String roleName) {
this.roleName = roleName;
}
public String toString() {
return "" + "" + userName + "" + "" + account + ""
+ "" + roleName + "" + "\n";
}
}
public void printXml() {
//获取数据库数据
List list = new ArrayList();
for (int i = 0; i < 10; i++) {
UserBean user = new UserBean("User " + i, "U0000" + i, (i % 2 == 0 ? "管理员" : "普通用户"));
list.add(user);
}
//转XML
StringBuffer xml = new StringBuffer();
xml.append("\n");
xml.append("\n");
for(UserBean user : list){
xml.append(user);
}
xml.append("");
System.out.println(xml.toString());
}
/**
* @param args
*/
public static void main(String[] args) {
Test8 test = new Test8();
test.printXml();
}
}