public class DaoUtil{
/**
* 系统字典表
* 适用于列表循环时,根据编码获取汉字
* @param appdicid
* @return
*/
public static Hashtable<String, String> getOptionHashtable(String appdicid){
Connection conn = DBSql.open();
try {
return getOptionHashtable(conn, appdicid);
} finally {
DBSql.close(conn, null, null);
}
}
/**
* 系统字典表
* 适用于列表循环时,根据编码获取汉字
* @param conn
* @param appdicid
* @return
*/
public static Hashtable<String, String> getOptionHashtable(Connection conn, String appdicid){
Hashtable<String, String> ht = new Hashtable<String, String>();
Statement st = null;
ResultSet rs = null;
try {
st = conn.createStatement();
rs = st.executeQuery("select dicname,dicvalue from sys_dic where appdicid='"
+appdicid+"' and isleaf='1'");
while(rs.next()){
ht.put(rs.getString("dicvalue"), rs.getString("dicname"));
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
DBSql.close(st, rs);
}
return ht;
}
}
//从数据库中使用select查出的CONTRACTCONTENT字段存储的是数字,利用for循环,从Hashtable中的使用ht.get("CONTRACTCONTENT")取出来的是数字,此时,无需使用if(){}else{}判断,
调用上述方法即可实线中文的转换:
Hashtable<String, String> contractcontents = DaoUtil.getOptionHashtable("7017");
//展示列表页面:
//使用append追加列表
sb.append("<td width=\"8%\" class=\"t1-12\">").append(DaoUtil.nullToNBSP(contractcontents.get(DaoUtil.nullToString(ht.get("CONTRACTCONTENT"))))).append("</td>");