Skip to content

Instantly share code, notes, and snippets.

@digimon1740
Created October 23, 2019 13:40
Show Gist options
  • Save digimon1740/adb5066f6ae50e23e32ee70aeba0494a to your computer and use it in GitHub Desktop.
Save digimon1740/adb5066f6ae50e23e32ee70aeba0494a to your computer and use it in GitHub Desktop.
// 검증이 없는 경우, String 또는 null을 리턴합니다.
var myQpStr = ctx.queryParam("my-qp");
// Integer 또는 throws를 발생시킵니다.
var myQpInt = ctx.pathParam("my-qp", Integer.class).get();
// 이 코드는 if (Integer > 4)와 동일합니다.
var myQpInt = ctx.formParam("my-qp", Integer.class).check(i -> i > 4).get();
// 두개의 의존적인 파라미터의 검증 방법
var fromDate = ctx.queryParam("from", Instant.class).get();
var toDate = ctx.queryParam("to", Instant.class)
.check(it -> it.isAfter(fromDate), "'to' has to be after 'from'")
.get();
// JSON 바디 검증 로직
var myObject = ctx.bodyValidator(MyObject.class)
.check(obj -> obj.myObjectProperty == someValue)
.get();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment