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;
    }
  }

猜你喜欢

转载自blog.csdn.net/xiao297328/article/details/82349388
今日推荐