很多牛人都在讲Hibernate 的东西,但很少有写具体细节的东西,偶个菜鸟抛砖引玉,写了个SQL组装的方法,希望大家,一起讨论,能写出更好更完美的方法。
写道
/**
*
* @param tableName 表明
* @param map 查询条件 map
* @return 组装好的sql字符串
*/
public static String SqlCombenation(String tableName, Map map) {
StringBuilder sql = new StringBuilder("where 1 = 1 ");
if (map != null) {
Set set = map.keySet();
Iterator it = set.iterator();
while (it.hasNext()) {
String columns = (String) it.next();
sql.append("and tableName." + columns + " = " + "'"
+ map.get(columns) + "' " );
}
}
return sql.toString();
}
*
* @param tableName 表明
* @param map 查询条件 map
* @return 组装好的sql字符串
*/
public static String SqlCombenation(String tableName, Map map) {
StringBuilder sql = new StringBuilder("where 1 = 1 ");
if (map != null) {
Set set = map.keySet();
Iterator it = set.iterator();
while (it.hasNext()) {
String columns = (String) it.next();
sql.append("and tableName." + columns + " = " + "'"
+ map.get(columns) + "' " );
}
}
return sql.toString();
}