diff --git a/manager/src/main/java/org/dromara/hertzbeat/manager/controller/MonitorsController.java b/manager/src/main/java/org/dromara/hertzbeat/manager/controller/MonitorsController.java index 81c0b1e84b1..be76d877908 100644 --- a/manager/src/main/java/org/dromara/hertzbeat/manager/controller/MonitorsController.java +++ b/manager/src/main/java/org/dromara/hertzbeat/manager/controller/MonitorsController.java @@ -29,6 +29,7 @@ import org.springframework.data.domain.Sort; import org.springframework.data.jpa.domain.Specification; import org.springframework.http.ResponseEntity; +import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -80,7 +81,7 @@ public ResponseEntity>> getMonitors( } andList.add(inPredicate); } - if (app != null && !app.chars().allMatch(Character::isSpaceChar)) { + if (StringUtils.hasText(app)) { Predicate predicateApp = criteriaBuilder.equal(root.get("app"), app); andList.add(predicateApp); } @@ -92,11 +93,11 @@ public ResponseEntity>> getMonitors( Predicate andPredicate = criteriaBuilder.and(andList.toArray(andPredicates)); List orList = new ArrayList<>(); - if (host != null && !host.chars().allMatch(Character::isSpaceChar)) { + if (StringUtils.hasText(host)) { Predicate predicateHost = criteriaBuilder.like(root.get("host"), "%" + host + "%"); orList.add(predicateHost); } - if (name != null && !name.chars().allMatch(Character::isSpaceChar)) { + if (StringUtils.hasText(name)) { Predicate predicateName = criteriaBuilder.like(root.get("name"), "%" + name + "%"); orList.add(predicateName); } diff --git a/manager/src/main/java/org/dromara/hertzbeat/manager/service/impl/AppServiceImpl.java b/manager/src/main/java/org/dromara/hertzbeat/manager/service/impl/AppServiceImpl.java index e4623820dd7..26e53a2688e 100644 --- a/manager/src/main/java/org/dromara/hertzbeat/manager/service/impl/AppServiceImpl.java +++ b/manager/src/main/java/org/dromara/hertzbeat/manager/service/impl/AppServiceImpl.java @@ -69,7 +69,7 @@ public class AppServiceImpl implements AppService, CommandLineRunner { @Override public List getAppParamDefines(String app) { - if (app == null || app.chars().allMatch(Character::isSpaceChar)) { + if (!StringUtils.hasText(app)) { return Collections.emptyList(); } Job appDefine = appDefines.get(app.toLowerCase()); @@ -82,7 +82,7 @@ public List getAppParamDefines(String app) { @Override public Job getAppDefine(String app) throws IllegalArgumentException { - if (app == null || app.chars().allMatch(Character::isSpaceChar)) { + if (!StringUtils.hasText(app)) { throw new IllegalArgumentException("The app can not null."); } Job appDefine = appDefines.get(app.toLowerCase()); diff --git a/manager/src/main/java/org/dromara/hertzbeat/manager/service/impl/MonitorServiceImpl.java b/manager/src/main/java/org/dromara/hertzbeat/manager/service/impl/MonitorServiceImpl.java index 5b99030189a..070f84871e4 100644 --- a/manager/src/main/java/org/dromara/hertzbeat/manager/service/impl/MonitorServiceImpl.java +++ b/manager/src/main/java/org/dromara/hertzbeat/manager/service/impl/MonitorServiceImpl.java @@ -46,6 +46,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; +import org.springframework.util.StringUtils; import java.time.LocalDateTime; import java.util.*; @@ -273,7 +274,7 @@ public void validate(MonitorDto monitorDto, Boolean isModify) throws IllegalArgu param.setType(CommonConstants.PARAM_TYPE_NUMBER); break; case "textarea": - if (param.getValue().chars().allMatch(Character::isSpaceChar)){ + if (StringUtils.hasText(param.getValue())){ throw new IllegalArgumentException("Params field " + field + " type " + paramDefine.getType() + " over limit " + param.getValue()); }