Commit 071beacc authored by Quxl's avatar Quxl

x

parent 79c922a4
...@@ -8,7 +8,9 @@ import java.io.InputStream; ...@@ -8,7 +8,9 @@ import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -30,7 +32,35 @@ import org.apache.poi.ss.usermodel.Row; ...@@ -30,7 +32,35 @@ import org.apache.poi.ss.usermodel.Row;
*/ */
public class ExcelUtil { public class ExcelUtil {
/**
* 生成Excel
* @param os 输出流
* @param args 获取数据的键
* @param titles Excel表头
* @param widths Excel列宽度
* @param list 数据集
*/
public static void excel(OutputStream os, LinkedHashMap<String, String> titleMap, List<Map<String, Object>> list) {
List<String> argsList = new ArrayList<String>();
List<String> titleList = new ArrayList<String>();
for(String key : titleMap.keySet()) {
argsList.add(key);
titleList.add(titleMap.get(key));
}
String[] args = argsList.toArray(new String[argsList.size()]);
String[] titles = titleList.toArray(new String[titleList.size()]);
Object[][] objs = new Object[list.size()+1][args.length];
objs[0] = titles;
for(int i = 0; i < list.size(); i++) {
Map<String, Object> map = list.get(i);
Object[] obj = new Object[args.length];
for(int k = 0; k < obj.length; k++) {
obj[k] = map.get(args[k]);
}
objs[i+1] = obj;
}
ExcelUtil.excel(os, objs, null);
}
/** /**
......
...@@ -1188,5 +1188,5 @@ public class StringUtil { ...@@ -1188,5 +1188,5 @@ public class StringUtil {
} }
return stack; return stack;
} }
} }
...@@ -274,9 +274,28 @@ public class JdbcTemplate extends org.springframework.jdbc.core.JdbcTemplate { ...@@ -274,9 +274,28 @@ public class JdbcTemplate extends org.springframework.jdbc.core.JdbcTemplate {
} }
public int save(String tableName, Map<String, Object> objMap) { public int save(String tableName, Map<String, Object> objMap) {
Sql desc = dialect.argsInsert(tableName, objMap); Sql iSql = dialect.argsInsert(tableName, objMap);
int save_count = this.executeUpdate(desc.getSql(), desc.getArgs()); KeyHolder keyHolder = new GeneratedKeyHolder();
return save_count; int count = super.update(new PreparedStatementCreator() {
public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
PreparedStatement ps = connection.prepareStatement(iSql.getSql(), Statement.RETURN_GENERATED_KEYS);
Object[] args = iSql.getArgs();
for(int i = 0; i <args.length; i++) {
Object argObj = args[i];
if(argObj instanceof java.util.Date) {
java.util.Date argDate = (java.util.Date)argObj;
ps.setObject(i+1, new java.sql.Timestamp(argDate.getTime()));
} else if(argObj.getClass().isEnum()) {
ps.setObject(i+1, args[i].toString());
} else {
ps.setObject(i+1, args[i]);
}
}
return ps;
}
}, keyHolder);
objMap.putAll(keyHolder.getKeys());
return count;
} }
public int delete(Object... objs) { public int delete(Object... objs) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment