{"id":7666,"date":"2023-03-01T17:33:17","date_gmt":"2023-03-01T08:33:17","guid":{"rendered":"https:\/\/www.skyer9.pe.kr\/wordpress\/?p=7666"},"modified":"2023-03-01T20:15:46","modified_gmt":"2023-03-01T11:15:46","slug":"spring-boot-valid-%ec%99%80-validated","status":"publish","type":"post","link":"https:\/\/www.skyer9.pe.kr\/wordpress\/?p=7666","title":{"rendered":"Spring Boot &#8211; @Valid \uc640 @Validated"},"content":{"rendered":"<h1>Spring Boot &#8211; @Valid \uc640 @Validated<\/h1>\n<h2>@Valid \uc640 @Validated \uc758 \ucc28\uc774\uc810<\/h2>\n<h3>@Valid<\/h3>\n<p>@Valid \ub294 JSR-303 \ud45c\uc900 \uc2a4\ud399(\uc790\ubc14 \uc9c4\uc601 \uc2a4\ud399) \uc5d0\uc11c \ub098\uc628 \uaddc\uc57d\uc774\ub2e4.<\/p>\n<p>\ucee8\ud2b8\ub864\ub7ec\uc5d0\uc11c\ub9cc \uc791\ub3d9\ud55c\ub2e4.<\/p>\n<h3>@Validated<\/h3>\n<p>Spring \ud504\ub808\uc784\uc6cc\ud06c\uc5d0\uc11c \uc81c\uacf5\ud558\ub294 \uc5b4\ub178\ud14c\uc774\uc158 \ubc0f \uae30\ub2a5\uc774\ub2e4.<\/p>\n<p>\ucee8\ud2b8\ub864\ub7ec \ubfd0\ub9cc \uc544\ub2c8\ub77c \uc11c\ube44\uc2a4 \ub808\uc774\uc5b4\uc5d0\uc11c\ub3c4 \uc791\ub3d9\ud55c\ub2e4.<\/p>\n<pre><code class=\"language-java\">@Service\n@Validated\n@RequiredArgsConstructor\npublic class CompanyCompanyService {\n    public void update(@Valid CompanyForm dto) {\n        apiCompanyCompanyHandler.update(dto);\n    }\n}<\/code><\/pre>\n<p>\uadf8\ub8f9\uc744 \uc9c0\uc815\ud560 \uc218 \uc788\ub2e4.<\/p>\n<pre><code class=\"language-java\">public interface CompanyValidationGroup {}\npublic interface AdminValidationGroup {}\n\n@NotEmpty(groups = {CompanyValidationGroup.class, AdminValidationGroup.class} )\nprivate String name;\n\n@NotEmpty(groups = CompanyValidationGroup.class)\nprivate String userId;\n\n@NotEmpty(groups = AdminValidationGroup.class)\nprivate String adminId;\n\n    @PostMapping(&quot;\/admin\/company\/create&quot;)\n    public String doCreate(@LoginInfo LoginInfoDto loginInfo, ModelMap model, @Validated(AdminValidationGroup.class) CompanyForm dto, BindingResult bindingResult) {\n        if (bindingResult.hasErrors()) {\n            setAttribute(loginInfo, model, dto);\n            return &quot;\/admin\/companyModify&quot;;\n        }\n        dto.validate();\n        service.create(dto);\n        return &quot;redirect:\/admin\/company\/&quot;;\n    }<\/code><\/pre>\n<p>ConstraintViolationException \uc744 \ubc1c\uc0dd\uc2dc\ud0a8\ub2e4.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Spring Boot &#8211; @Valid \uc640 @Validated @Valid \uc640 @Validated \uc758 \ucc28\uc774\uc810 @Valid @Valid \ub294 JSR-303 \ud45c\uc900 \uc2a4\ud399(\uc790\ubc14 \uc9c4\uc601 \uc2a4\ud399) \uc5d0\uc11c \ub098\uc628 \uaddc\uc57d\uc774\ub2e4. \ucee8\ud2b8\ub864\ub7ec\uc5d0\uc11c\ub9cc \uc791\ub3d9\ud55c\ub2e4. @Validated Spring \ud504\ub808\uc784\uc6cc\ud06c\uc5d0\uc11c \uc81c\uacf5\ud558\ub294 \uc5b4\ub178\ud14c\uc774\uc158 \ubc0f \uae30\ub2a5\uc774\ub2e4. \ucee8\ud2b8\ub864\ub7ec \ubfd0\ub9cc \uc544\ub2c8\ub77c \uc11c\ube44\uc2a4 \ub808\uc774\uc5b4\uc5d0\uc11c\ub3c4 \uc791\ub3d9\ud55c\ub2e4. @Service @Validated @RequiredArgsConstructor public class CompanyCompanyService { public void update(@Valid CompanyForm dto) { apiCompanyCompanyHandler.update(dto); } } \uadf8\ub8f9\uc744 \uc9c0\uc815\ud560\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.skyer9.pe.kr\/wordpress\/?p=7666\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[29],"tags":[],"class_list":["post-7666","post","type-post","status-publish","format-standard","hentry","category-spring-boot-2-5"],"_links":{"self":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/7666","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7666"}],"version-history":[{"count":3,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/7666\/revisions"}],"predecessor-version":[{"id":7669,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/7666\/revisions\/7669"}],"wp:attachment":[{"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7666"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7666"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.skyer9.pe.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7666"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}