no message
Showing
1 changed file
with
6 additions
and
2 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,8 +33,11 @@ public class AtLeastOneNonNullValidator implements ConstraintValidator<AtLeastOn | ... | @@ -32,8 +33,11 @@ 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)); |
| 36 | return true; // 如果至少一个字段非空,返回true | 37 | if(StringUtils.isNotEmpty(value)) { |
| 38 | System.out.println(field.getName() + "============" + field.get(object) + "&"); | ||
| 39 | return true; // 如果至少一个字段非空,返回true | ||
| 40 | } | ||
| 37 | } | 41 | } |
| 38 | } catch (NoSuchFieldException | IllegalAccessException e) { | 42 | } catch (NoSuchFieldException | IllegalAccessException e) { |
| 39 | // 处理异常,例如记录日志等 | 43 | // 处理异常,例如记录日志等 | ... | ... |
-
Please register or sign in to post a comment