Skip to content

Instantly share code, notes, and snippets.

@upangka
Created December 17, 2019 08:23
Show Gist options
  • Save upangka/c91e079947f4b3e6b13b8632ed43d4e1 to your computer and use it in GitHub Desktop.
Save upangka/c91e079947f4b3e6b13b8632ed43d4e1 to your computer and use it in GitHub Desktop.
检验,cardId与cardInfo这两个字段其中一个必须传值,也就是不能都是null值
@PostMapping(value = "/api/card/test/getCard")
public JsonResult getCard(@RequestBody @Validated UserCardGetParam param) {
// ...
}
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