数据库的vid存的是varchar类型,实体类中定义的是String
java代码:
List<Integer> vids=new ArrayList<>();
if(planList != null && planList.size() > 0){
for (int i = 0; i < planList.size(); i++) {
VoicePlanListEntity voicePlanListEntity = new VoicePlanListEntity();
voicePlanListEntity.setVpid(voicePlanEntity.getId());
voicePlanListEntity.setVid(Integer.valueOf(planList.get(i).toString()));
voicePlanListEntity.setSort(i);
this.voicePlanListService.insert(voicePlanListEntity);
vids.add(Integer.valueOf(planList.get(i).toString()));
}
voicePlanEntity.setVid(vids.toString());
voicePlanService.update(voicePlanEntity);
//增加语音id
}
list直接调用toString,最后的结果会有[],如图
解决方法1、去除[]:
voicePlanEntity.setVid(vids.toString());
修改为
voicePlanEntity.setVid(StringUtils.strip(vids.toString(),"[]"));
解决方法二:
用StringBuffer的append方法来拼接字符串,再去除最后一个逗号
StringBuffer sb = new StringBuffer();
for (String str: list) {
sb.append(str).append(",");
}
String keywordStr = sb.deleteCharAt(sb.length() - 1).toString();
我用的第一种方法,成功去除括号[]