java拼接字符串时去掉最后一个多余逗号的方法
@RequestMapping(value = "bind", method = RequestMethod.POST)
@ResponseBody
public ErrorObject bindStyleDetailedList(String ids, String billNo) {
if (StringUtils.isNotBlank(billNo)) {
Expenditure entity = expenditureService.findByBillNo(billNo);
String[] strs = ids.split(",");
String styleIds = "";
if (StringUtils.isNotBlank(entity.getStyleIds())) {
for (int i = 0; i < strs.length; i++) {
if (!entity.getStyleIds().contains(strs[i])) {
styleIds = strs[i] + ",";
}
}
if (StringUtils.isNotBlank(styleIds)) {
entity.setStyleIds(entity.getStyleIds() + "," + styleIds.substring(0, styleIds.length() - 1)); //去逗号
}
} else {
entity.setStyleIds(ids);
}
return expenditureService.save(entity);
} else {
return null;
}
}