判断以逗号分隔的字符串是否包含指定的值方法优化

This commit is contained in:
syruan 2025-08-21 13:58:02 +08:00
parent c955981105
commit 48fdebbb5b
1 changed files with 16 additions and 2 deletions

View File

@ -543,9 +543,23 @@ public class SltAgreementInfoServiceImpl implements ISltAgreementInfoService {
* @return true 表示包含false 表示不包含 * @return true 表示包含false 表示不包含
*/ */
public static boolean containsExactValue(String strings, String target) { public static boolean containsExactValue(String strings, String target) {
return strings.matches("(?<![^,])" + Pattern.quote(target) + "(?![^,])"); if (strings == null || target == null) {
return false;
}
if (strings.isEmpty() || target.isEmpty()) {
return false;
}
String[] parts = strings.split(",");
for (String part : parts) {
if (part == null || part.isEmpty()) {
continue;
}
if (part.equals(target)) {
return true;
}
}
return false;
} }
/** /**
* 进行结算审批 * 进行结算审批