/**
* @Description String字符串转换,逗号分隔
* @param str "1,2,"
* @Throws
* @Return java.lang.String 1,2
* @Date 2020-12-10 19:46:19
* @Author WangKun
**/
public static String StrConvert(String str) {
if (StringUtils.isBlank(str)) {
return null;
}
String[] arrList = str.split(",");
StringBuilder sb = new StringBuilder();
for (int i = 0; i < arrList.length; i++) {
String temp = arrList[i];
if (i != arrList.length - 1) {
sb.append(temp)append(",");
} else {
sb.append(temp);
}
}
return sb.toString();
}
/**
* @Description String字符串转换,逗号分隔 作为where in 查询条件
* @param str "1,2,"
* @Throws
* @Return java.lang.String '1','2'
* @Date 2020-12-10 19:46:19
* @Author WangKun
**/
public static String StrConvert(String str) {
if (StringUtils.isBlank(str)) {
return null;
}
String[] arrList = str.split(",");
StringBuilder sb = new StringBuilder();
for (int i = 0; i < arrList.length; i++) {
String temp = arrList[i];
if (i != arrList.length - 1) {
sb.append("'").append(temp).append("'").append(",");
} else {
sb.append("'").append(temp).append("'");
}
}
return sb.toString();
}
/**
* @param list List<String> list = new ArrayList<>();
* list.add("1");
* list.add("2");
* list.add("3");
* @Description List字符串转where in
* @Throws
* @Return java.lang.String
* @Date 2020-12-14 17:31:15
* @Author WangKun
**/
public static String ListStrConvert(List<String> list) {
if (null == list || list.size() <= 0) {
return null;
}
StringBuilder sb = new StringBuilder();
for (int i = 0; i < list.size(); i++) {
String temp = list.get(i);
if (i != list.size() - 1) {
sb.append("'").append(temp).append("'").append(",");
} else {
sb.append("'").append(temp).append("'");
}
}
return sb.toString();
}