标签:
http://blog.csdn.net/liu826710/article/details/9001254
Map<String, Object> oldMap = beanToMap(object);
Map<String, Object> map = new HashMap<String, Object>();
List<String> validateParm = getValidateParm(conn, tableName,config);
for (String stringKey : validateParm) {
if(oldMap.containsKey(stringKey)) {
map.put(stringKey, oldMap.get(stringKey));
}
}
StringBuilder sql = new StringBuilder();
sql.append("UPDATE ");
sql.append(" " + tableName + " ");
sql.append(" SET ");
List<Object> list = new ArrayList<Object>();
Iterator<Entry<String, Object>> it = map.entrySet().iterator();
while (it.hasNext()){
Map.Entry<String, Object> pairs = (Map.Entry<String, Object>)it.next();
sql.append(" " + pairs.getKey() + "=?,");
list.add(pairs.getValue());
}
sql.deleteCharAt(sql.length()-1);
if (sWhere != null && !"".equals(sWhere)) {
sql.append(" ");
sql.append(sWhere);
} else {
sql.append(" where 1=2");
}
QueryRunner queryRunner = new QueryRunner(DATABASE_TYPE_ORACLE.equals(config.getDriverType()));
return queryRunner.update(conn, sql.toString(), list.toArray());
标签:
原文地址:http://www.cnblogs.com/zshboke-2015/p/5387907.html