1、判断Object对象为空或空字符串
/**
* 判断Object对象为空或空字符串
* @param obj
* @return
*/
public static Boolean isObjectNotEmpty(Object obj) {
String str = ObjectUtils.toString(obj, "");
Boolean flag = StringUtils.isNotBlank(str);
return flag;
}
2、设置Excel表格导出自适应列宽高
Workbook wb = new Workbook();
Worksheet worksheet = wb.getWorksheets().get(0);
worksheet.autoFitRows();// 设置Excel自适应行高
worksheet.autoFitColumns();// 设置Excel自适应列宽
3、CLOB大字段处理
Map<String, Object> khbzMap = new HashMap<String, Object>();
if(selectList.size() > 0){
for(int i = 0;i< selectList.size();i++){
khbzMap.put("GUIDELINEPFBZ",selectList.get(i).get("GUIDELINEPFBZ") == null ? "" : selectList.get(i).get("GUIDELINEPFBZ"));
Map<String, Object> responseMap = formatResponseMap(khbzMap);
String GUIDELINEPFBZ = responseMap.get("GUIDELINEPFBZ") == null ? "" : responseMap.get("GUIDELINEPFBZ").toString();
selectList.get(i).put("GUIDELINEPFBZ", GUIDELINEPFBZ);
}
}
return JSONArray.fromObject(selectList).toString();
public Map<String, Object> formatResponseMap(Map<String, Object> map) {
Set<String> set = map.keySet();
for (Iterator<String> iterator = set.iterator(); iterator.hasNext();) {
String key = iterator.next();
// 判断数据是否是CLOB如果是对字段进行处理
// 2018-01-12 09:56:14 CLOB 修改为Clob 解决框架更换Druid连接池导出CLOB解析错误问题
if (map.get(key) instanceof Clob) {
Clob clob = (Clob) map.get(key);
try {
map.put(key, clob.getSubString((long) 1, (int) clob.length()));
} catch (SQLException e) {
e.printStackTrace();
}
}
if (map.get(key) instanceof CLOB) {
CLOB clob = (CLOB) map.get(key);
try {
map.put(key, clob.getSubString((long) 1, (int) clob.length()));
} catch (SQLException e) {
e.printStackTrace();
}
}
}
return map;
}
4、Springboot项目线程中无法注入Mapper,报空指针的解决方案
PmPskhKhsjdrMapper pmPskhKhsjdrMapper = SpringContextUtil.getBean(PmPskhKhsjdrMapper.class);
// 考核结果等次信息(代码值:好、较好、一般、较差、不确定等次) List<PmPSKH_DM_01> KHDCList = pmPskhKhsjdrMapper.getKHJGDCList(requestMap);
5、设置Excel表格样式
worksheet.autoFitRows();// 设置Excel自适应行高 worksheet.autoFitColumns();// 设置Excel自适应列宽
6、java后台向XML传入拼接的多个值字符串,如A00S,如下
/**
* 将list转换为字符串
* @param list
* @return
*/
public static String listToString(List<String> list) {
StringBuilder sb = new StringBuilder();
if (list != null && list.size() > 0) {
for (int i = 0; i < list.size(); i++) {
if (i < list.size() - 1) {
sb.append(list.get(i) + ",");
} else {
sb.append(list.get(i));
}
}
}
return sb.toString();
}
if(listA00S != null && listA00S.size() > 0){
map.put("A00Arr" , listToString(listA00S));
}
XML接收解析
<choose>
<when test="A00Arr != null and A00Arr != ''">
AND PD.A00 IN (${A00Arr})
</when>
<otherwise>
AND PD.B00 = #{B00}
</otherwise>
</choose>