no message
Showing
1 changed file
with
5 additions
and
1 deletions
| 1 | package com.lego.common.annotation; | 1 | package com.lego.common.annotation; |
| 2 | 2 | ||
| 3 | import com.lego.common.annotation.AtLeastOneNonNull; | 3 | import com.lego.common.annotation.AtLeastOneNonNull; |
| 4 | import com.lego.common.utils.StringUtils; | ||
| 4 | 5 | ||
| 5 | import javax.validation.ConstraintValidator; | 6 | import javax.validation.ConstraintValidator; |
| 6 | import javax.validation.ConstraintValidatorContext; | 7 | import javax.validation.ConstraintValidatorContext; |
| ... | @@ -32,9 +33,12 @@ public class AtLeastOneNonNullValidator implements ConstraintValidator<AtLeastOn | ... | @@ -32,9 +33,12 @@ public class AtLeastOneNonNullValidator implements ConstraintValidator<AtLeastOn |
| 32 | field.setAccessible(true); // 设置私有字段可访问,以便读取值 | 33 | field.setAccessible(true); // 设置私有字段可访问,以便读取值 |
| 33 | System.out.println(field.getName()+"============"+field.get(object)+"!"); | 34 | System.out.println(field.getName()+"============"+field.get(object)+"!"); |
| 34 | if (Objects.nonNull(field.get(object))) { // 检查字段是否非空 | 35 | if (Objects.nonNull(field.get(object))) { // 检查字段是否非空 |
| 35 | System.out.println(field.getName()+"============"+field.get(object)+"&"); | 36 | String value = String.valueOf(field.get(object)); |
| 37 | if(StringUtils.isNotEmpty(value)) { | ||
| 38 | System.out.println(field.getName() + "============" + field.get(object) + "&"); | ||
| 36 | return true; // 如果至少一个字段非空,返回true | 39 | return true; // 如果至少一个字段非空,返回true |
| 37 | } | 40 | } |
| 41 | } | ||
| 38 | } catch (NoSuchFieldException | IllegalAccessException e) { | 42 | } catch (NoSuchFieldException | IllegalAccessException e) { |
| 39 | // 处理异常,例如记录日志等 | 43 | // 处理异常,例如记录日志等 |
| 40 | return false; // 出现异常时,保守起见返回false,实际中应更细致处理异常情况 | 44 | return false; // 出现异常时,保守起见返回false,实际中应更细致处理异常情况 | ... | ... |
-
Please register or sign in to post a comment