BACKEND/JAVA & SPRING

@NotBlanck, @NotEmpty, @NotNull ์ฐจ์ด์ 

์ด-ํ”„ 2023. 12. 19. 15:49
๐Ÿš—

@NotBlank, @NotEmpty, @NotNull ์ฐจ์ด์ 

  • javax.validation.constraints ํŒจํ‚ค์ง€์— ํฌํ•จ๋œ ๊ธฐ๋Šฅ
  • API์—์„œ ๊ฐ’์„ ์ž…๋ ฅ๋ฐ›์„ ๋•Œ, validation ์ฒดํฌ๋ฅผ ์œ„ํ•ด ์‚ฌ์šฉ๋˜๋Š” annotaion์ด๋‹ค.

@NotNull

โŒ Null์„ ํ—ˆ์šฉํ•˜์ง€ ์•Š๋Š”๋‹ค.

๐Ÿ†— โ€œ โ€œ, โ€œโ€ ๋Š” ํ—ˆ์šฉํ•œ๋‹ค.

ex) Integer, Long, CharSequence, Collection, Map, Array ํƒ€์ž…์— ์‚ฌ์šฉ

@NotEmpty

โŒ Null์„ ํ—ˆ์šฉํ•˜์ง€ ์•Š๋Š”๋‹ค.

โŒ โ€œโ€๋ฅผ ํ—ˆ์šฉํ•˜์ง€ ์•Š๋Š”๋‹ค.

๐Ÿ†— โ€œ โ€œ์€ ํ—ˆ์šฉํ•œ๋‹ค.

ex) CharSequence, Collection, Map, Array ํƒ€์ž…์— ์‚ฌ์šฉ

@NotBlank

โŒ Null, โ€œ โ€œ, โ€œโ€ ๋ชจ๋‘ ๋‹ค ํ—ˆ์šฉํ•˜์ง€ ์•Š๋Š”๋‹ค.

ex) String ํƒ€์ž…๋งŒ ์‚ฌ์šฉ

โœจ
๊ทธ๋Ÿผ post api์—์„œ ์ ์šฉ์€?
  • tripId : @NotBlank
  • content : @NotEmpty

๐Ÿ”— ์ฐธ๊ณ  url

https://wildeveloperetrain.tistory.com/68


Uploaded by N2T