**
java 代码截取,逗号分割,mysql分割方法
**
public List<Long> stringToList(String str) {
String[] result = str.split(",");
List<Long> list = new ArrayList<>();
for (String s : result) {
list.add(Long.parseLong(s));
}
return list;
}
调用
ProjectDetails projectDetails = projectDetailsMapper.selectByproId((Long) item.get("proId"));
String projectPic = projectDetails.getProjectPic();
if (projectPic != null && !"".equals(projectPic)) {
List<Long> pics1 = stringToList(projectPic);
List<String> urlList = new ArrayList<String>();
for (Long long1 : pics1) {
Attachments picAttachments = attachmentsMapper.selectByPrimaryKey(long1);
urlList.add(picAttachments == null ? "" : openBosUrl + picAttachments.getUrl());
}
String urlString = "";
for (String url : urlList) {
urlString = urlString.concat("," + url);
}
String[] strs = urlString.split(",");
for (int i = 0, len = strs.length; i < len; i++) {
String pic = strs[i].toString();
item.put("projectPicUrl", pic);
}
} else {
item.put("projectPicUrl", "");
}
sql截取方法
SELECT
IFNULL(a1.url, '') projectPicUrl
FROM
gongyi_project_support s,
project_details d,
attachments a1
WHERE
1 = 1
AND SUBSTRING_INDEX(d.project_pic, ',', 1) = a1.attach_id
GROUP BY
PROJECT_ID
ORDER BY
loveValue DESC