Created
December 17, 2019 08:23
-
-
Save upangka/c91e079947f4b3e6b13b8632ed43d4e1 to your computer and use it in GitHub Desktop.
检验,cardId与cardInfo这两个字段其中一个必须传值,也就是不能都是null值
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@PostMapping(value = "/api/card/test/getCard") | |
public JsonResult getCard(@RequestBody @Validated UserCardGetParam param) { | |
// ... | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.validation.constraints.AssertTrue; | |
import lombok.Data; | |
@Data | |
public class UserCardGetParam { | |
private Byte getType; | |
/** card info */ | |
private CardInfo cardInfo; | |
private Integer cardId; | |
@AssertTrue(message="cardId must need.") | |
private boolean isValid() { | |
System.out.println("正在进行校验"); | |
if(cardId != null || cardInfo != null) { | |
return true; | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://stackoverflow.com/questions/1972933/cross-field-validation-with-hibernate-validator-jsr-303