{"id":6360,"date":"2026-05-24T11:18:37","date_gmt":"2026-05-24T02:18:37","guid":{"rendered":"https:\/\/route-zero.com\/recruit\/?post_type=route&#038;p=6360"},"modified":"2026-09-24T11:18:48","modified_gmt":"2026-09-24T02:18:48","slug":"spring-boot-bindingresult","status":"publish","type":"route","link":"https:\/\/route-zero.com\/recruit\/route\/6360\/","title":{"rendered":"Spring Boot BindingResult\u306e\u4f7f\u3044\u65b9\uff5c@Valid\u30a8\u30e9\u30fc\u51e6\u7406"},"content":{"rendered":"<p>`@Valid` \u3092\u4ed8\u3051\u305f\u30d5\u30a9\u30fc\u30e0\u3067\u5165\u529b\u30a8\u30e9\u30fc\u304c\u8d77\u304d\u305f\u3068\u304d\u3001\u300c\u305d\u306e\u30a8\u30e9\u30fc\u3092Controller\u3067\u3069\u3046\u53d7\u3051\u53d6\u308a\u3001\u3069\u3046\u753b\u9762\u3078\u8fd4\u3059\u306e\u304b\u300d\u3067\u8ff7\u3044\u3084\u3059\u3044\u306e\u304c `BindingResult` \u3067\u3059\u3002\u4f7f\u3044\u65b9\u306e\u8981\u70b9\u306f\u30b7\u30f3\u30d7\u30eb\u3067\u3001\u691c\u8a3c\u5bfe\u8c61\u306e\u5f15\u6570\u306e\u76f4\u5f8c\u306b\u7f6e\u304d\u3001`hasErrors()` \u3092\u78ba\u8a8d\u3057\u3066\u30a8\u30e9\u30fc\u6642\u306f\u540c\u3058\u30d5\u30a9\u30fc\u30e0\u3078\u623b\u3057\u307e\u3059\u3002\u305f\u3060\u3057\u3001BindingResult\u306b\u306fBean Validation\u306e\u5931\u6557\u3060\u3051\u3067\u306a\u304f\u3001\u578b\u5909\u63db\u306a\u3069\u30c7\u30fc\u30bf\u30d0\u30a4\u30f3\u30c9\u6642\u306e\u30a8\u30e9\u30fc\u3082\u5165\u308a\u307e\u3059\u3002\u3053\u3053\u3092\u7406\u89e3\u3059\u308b\u3068\u3001\u5358\u306b `if (result.hasErrors())` \u3068\u66f8\u304f\u3088\u308a\u4e00\u6bb5\u6df1\u304f\u539f\u56e0\u3092\u8ffd\u3048\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h2>\u307e\u305a\u7d50\u8ad6\uff1aBindingResult\u306f\u691c\u8a3c\u5bfe\u8c61\u306e\u76f4\u5f8c\u306b\u7f6e\u304f<\/h2>\n<p>Spring MVC\u3067\u30d5\u30a9\u30fc\u30e0\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092 `@Valid` \u3067\u691c\u8a3c\u3057\u3001Controller\u5185\u3067\u30a8\u30e9\u30fc\u3092\u6271\u3046\u57fa\u672c\u5f62\u306f\u3001\u691c\u8a3c\u5bfe\u8c61\u306e\u76f4\u5f8c\u306b `BindingResult` \u3092\u5ba3\u8a00\u3059\u308b\u3053\u3068\u3067\u3059\u3002\u516c\u5f0f\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u3067\u3082 `Errors` \u307e\u305f\u306f `BindingResult` \u306f\u5bfe\u8c61\u306e\u5f15\u6570\u306e\u76f4\u5f8c\u306b\u7f6e\u304f\u5fc5\u8981\u304c\u3042\u308b\u3068\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre><code>@PostMapping(&quot;\/users&quot;)\r\npublic String create(\r\n        @Valid @ModelAttribute(&quot;userForm&quot;) UserForm form,\r\n        BindingResult result) {\r\n\r\n    if (result.hasErrors()) {\r\n        return &quot;users\/form&quot;;\r\n    }\r\n\r\n    userService.create(form);\r\n    return &quot;redirect:\/users&quot;;\r\n}<\/code><\/pre>\n<table>\n<thead>\n<tr>\n<th>\u78ba\u8a8d\u30dd\u30a4\u30f3\u30c8<\/th>\n<th>\u5f79\u5272<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>`@Valid`<\/td>\n<td>\u30d5\u30a9\u30fc\u30e0\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3078validation\u3092\u9069\u7528\u3059\u308b<\/td>\n<\/tr>\n<tr>\n<td>`BindingResult`<\/td>\n<td>\u30c7\u30fc\u30bf\u30d0\u30a4\u30f3\u30c9\u30fbvalidation\u306e\u30a8\u30e9\u30fc\u7d50\u679c\u3078\u30a2\u30af\u30bb\u30b9\u3059\u308b<\/td>\n<\/tr>\n<tr>\n<td>`hasErrors()`<\/td>\n<td>1\u4ef6\u4ee5\u4e0a\u306e\u30a8\u30e9\u30fc\u304c\u3042\u308b\u304b\u5224\u5b9a\u3059\u308b<\/td>\n<\/tr>\n<tr>\n<td>\u30a8\u30e9\u30fc\u6642\u306b\u540c\u3058View\u3092\u8fd4\u3059<\/td>\n<td>\u5165\u529b\u5024\u3068\u30a8\u30e9\u30fc\u60c5\u5831\u3092\u4f7f\u3063\u3066\u30d5\u30a9\u30fc\u30e0\u3092\u518d\u8868\u793a\u3059\u308b<\/td>\n<\/tr>\n<tr>\n<td>\u6b63\u5e38\u6642\u3060\u3051Service\u3078\u9032\u3080<\/td>\n<td>\u4e0d\u6b63\u306a\u5165\u529b\u3092\u696d\u52d9\u51e6\u7406\u3078\u6e21\u3055\u306a\u3044<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u6700\u521d\u306f\u3053\u306e\u5f62\u3092\u57fa\u6e96\u306b\u3057\u3001\u5fc5\u8981\u306b\u306a\u3063\u305f\u3089\u500b\u5225\u30d5\u30a3\u30fc\u30eb\u30c9\u306e\u30a8\u30e9\u30fc\u3001global error\u3001\u578b\u5909\u63db\u5931\u6557\u307e\u3067\u6398\u308a\u4e0b\u3052\u308b\u3068\u6574\u7406\u3057\u3084\u3059\u304f\u306a\u308a\u307e\u3059\u3002<\/p>\n<hr>\n<h2>BindingResult\u3068\u306f\u4f55\u3092\u6301\u3063\u3066\u3044\u308b\u306e\u304b<\/h2>\n<p>`BindingResult` \u306fSpring\u306e `Errors` \u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u3092\u62e1\u5f35\u3057\u3001\u5bfe\u8c61\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u30c7\u30fc\u30bf\u30d0\u30a4\u30f3\u30c9\u3068validation\u306e\u7d50\u679c\u3092\u8868\u3059\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u3067\u3059\u3002\u5358\u306a\u308b\u300c@Valid\u306e\u30a8\u30e9\u30fc\u4e00\u89a7\u300d\u3067\u306f\u306a\u304f\u3001\u30d5\u30a9\u30fc\u30e0\u3078\u5024\u3092\u30d0\u30a4\u30f3\u30c9\u3059\u308b\u9014\u4e2d\u3067\u8d77\u304d\u305f\u30a8\u30e9\u30fc\u3082\u6271\u3048\u308b\u306e\u304c\u91cd\u8981\u306a\u30dd\u30a4\u30f3\u30c8\u3067\u3059\u3002<\/p>\n<blockquote>\n<p><strong>\u7528\u8a9e\u89e3\u8aac\uff1a\u30c7\u30fc\u30bf\u30d0\u30a4\u30f3\u30c9<\/strong><br \/>HTTP\u30ea\u30af\u30a8\u30b9\u30c8\u306e\u6587\u5b57\u5217\u30d1\u30e9\u30e1\u30fc\u30bf\u306a\u3069\u3092\u3001\u30d5\u30a9\u30fc\u30e0\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u3078\u5909\u63db\u3057\u3066\u8a2d\u5b9a\u3059\u308b\u51e6\u7406\u3067\u3059\u3002\u305f\u3068\u3048\u3070\u6570\u5024\u30d5\u30a3\u30fc\u30eb\u30c9\u3078\u6587\u5b57\u5217\u304c\u5c4a\u304d\u578b\u5909\u63db\u3067\u304d\u306a\u3051\u308c\u3070\u3001validation\u3088\u308a\u524d\u6bb5\u306ebinding error\u3068\u3057\u3066\u8a18\u9332\u3055\u308c\u308b\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<\/blockquote>\n<table>\n<thead>\n<tr>\n<th>\u7a2e\u985e<\/th>\n<th>\u4f8b<\/th>\n<th>\u78ba\u8a8d\u65b9\u6cd5<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>validation error<\/td>\n<td>`@NotBlank`\u3001`@Email` \u306a\u3069\u306e\u5236\u7d04\u9055\u53cd<\/td>\n<td>`getFieldErrors()`\u3001`getAllErrors()`<\/td>\n<\/tr>\n<tr>\n<td>binding error<\/td>\n<td>\u6570\u5024\u9805\u76ee\u306b\u5909\u63db\u3067\u304d\u306a\u3044\u6587\u5b57\u5217\u304c\u9001\u4fe1\u3055\u308c\u305f<\/td>\n<td>`FieldError#isBindingFailure()`<\/td>\n<\/tr>\n<tr>\n<td>global error<\/td>\n<td>\u8907\u6570\u9805\u76ee\u3092\u307e\u305f\u3050\u6574\u5408\u6027\u30a8\u30e9\u30fc\u306a\u3069<\/td>\n<td>`getGlobalErrors()`<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\uff08@Valid\u3084Bean Validation\u306e\u57fa\u672c\u304b\u3089\u78ba\u8a8d\u3057\u305f\u3044\u5834\u5408\u306b\u3064\u3044\u3066\u306f\u300e<a href=\"https:\/\/route-zero.com\/recruit\/route\/1256\/\">Spring Boot\u306e\u30d5\u30a9\u30fc\u30e0\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3068\u306f\uff1f@Valid\u3067\u5b89\u5168\u306a\u5165\u529b\u30c1\u30a7\u30c3\u30af\u3092\u5b9f\u73fe\u3057\u3088\u3046<\/a>\u300f\u3092\u3054\u53c2\u7167\u304f\u3060\u3055\u3044\uff09<\/p>\n<hr>\n<h2>\u30d5\u30a9\u30fc\u30e0\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3092\u5b9f\u88c5\u3059\u308b\u57fa\u672c\u5f62<\/h2>\n<p>\u4f8b\u3068\u3057\u3066\u3001\u540d\u524d\u3068\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u3092\u53d7\u3051\u53d6\u308b\u30d5\u30a9\u30fc\u30e0\u3092\u8003\u3048\u307e\u3059\u3002\u307e\u305a\u30d5\u30a9\u30fc\u30e0\u5c02\u7528\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u5236\u7d04\u3092\u5b9a\u7fa9\u3057\u307e\u3059\u3002<\/p>\n<pre><code>import jakarta.validation.constraints.Email;\r\nimport jakarta.validation.constraints.NotBlank;\r\n\r\npublic class UserForm {\r\n\r\n    @NotBlank(message = &quot;\u540d\u524d\u306f\u5fc5\u9808\u3067\u3059&quot;)\r\n    private String name;\r\n\r\n    @NotBlank(message = &quot;\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u306f\u5fc5\u9808\u3067\u3059&quot;)\r\n    @Email(message = &quot;\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u306e\u5f62\u5f0f\u3067\u5165\u529b\u3057\u3066\u304f\u3060\u3055\u3044&quot;)\r\n    private String email;\r\n\r\n    \/\/ getter \/ setter\r\n}<\/code><\/pre>\n<p>Controller\u3067\u306f `@Valid` \u3092\u4ed8\u3051\u305f `UserForm` \u306e\u76f4\u5f8c\u306b `BindingResult` \u3092\u7f6e\u304d\u307e\u3059\u3002validation\u306b\u5931\u6557\u3057\u3066\u3082\u3001BindingResult\u3067\u53d7\u3051\u53d6\u308c\u308b\u69cb\u6210\u306a\u3089Controller\u5185\u3067 `hasErrors()` \u3092\u78ba\u8a8d\u3057\u3001\u540c\u3058\u30d5\u30a9\u30fc\u30e0View\u3078\u623b\u305b\u307e\u3059\u3002<\/p>\n<pre><code>@PostMapping(&quot;\/users&quot;)\r\npublic String create(\r\n        @Valid @ModelAttribute(&quot;userForm&quot;) UserForm form,\r\n        BindingResult result) {\r\n\r\n    if (result.hasErrors()) {\r\n        return &quot;users\/form&quot;;\r\n    }\r\n\r\n    userService.create(form);\r\n    return &quot;redirect:\/users&quot;;\r\n}<\/code><\/pre>\n<hr>\n<h2>hasErrors\u3060\u3051\u3067\u306a\u304f\u30a8\u30e9\u30fc\u306e\u4e2d\u8eab\u3092\u53d6\u308a\u51fa\u3059<\/h2>\n<p>\u753b\u9762\u3092\u623b\u3059\u3060\u3051\u306a\u3089 `hasErrors()` \u3067\u5341\u5206\u3067\u3059\u304c\u3001\u539f\u56e0\u8abf\u67fb\u3084API\u30ec\u30b9\u30dd\u30f3\u30b9\u6574\u5f62\u306a\u3069\u3067\u306f\u30a8\u30e9\u30fc\u306e\u4e2d\u8eab\u3092\u78ba\u8a8d\u3057\u305f\u304f\u306a\u308a\u307e\u3059\u3002`BindingResult` \u304c\u7d99\u627f\u3059\u308b `Errors` \u306b\u306f\u3001field error\u3068global error\u3092\u53d6\u5f97\u3059\u308b\u30e1\u30bd\u30c3\u30c9\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<table>\n<thead>\n<tr>\n<th>\u30e1\u30bd\u30c3\u30c9<\/th>\n<th>\u4f7f\u3044\u3069\u3053\u308d<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>`hasErrors()`<\/td>\n<td>\u4f55\u3089\u304b\u306e\u30a8\u30e9\u30fc\u304c\u3042\u308b\u304b\u3060\u3051\u78ba\u8a8d\u3059\u308b<\/td>\n<\/tr>\n<tr>\n<td>`getAllErrors()`<\/td>\n<td>field\/global\u3092\u542b\u3080\u5168\u30a8\u30e9\u30fc\u3092\u53d6\u5f97\u3059\u308b<\/td>\n<\/tr>\n<tr>\n<td>`getFieldErrors()`<\/td>\n<td>\u5168field error\u3092\u53d6\u5f97\u3059\u308b<\/td>\n<\/tr>\n<tr>\n<td>`getFieldError(&quot;email&quot;)`<\/td>\n<td>\u7279\u5b9a\u30d5\u30a3\u30fc\u30eb\u30c9\u306e\u5148\u982d\u30a8\u30e9\u30fc\u3092\u53d6\u5f97\u3059\u308b<\/td>\n<\/tr>\n<tr>\n<td>`hasFieldErrors(&quot;email&quot;)`<\/td>\n<td>\u7279\u5b9a\u30d5\u30a3\u30fc\u30eb\u30c9\u306b\u30a8\u30e9\u30fc\u304c\u3042\u308b\u304b\u78ba\u8a8d\u3059\u308b<\/td>\n<\/tr>\n<tr>\n<td>`getGlobalErrors()`<\/td>\n<td>\u7279\u5b9a\u30d5\u30a3\u30fc\u30eb\u30c9\u306b\u5c5e\u3055\u306a\u3044\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u5168\u4f53\u306e\u30a8\u30e9\u30fc\u3092\u53d6\u5f97\u3059\u308b<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<pre><code>for (FieldError error : result.getFieldErrors()) {\r\n    System.out.println(\r\n        error.getField() + &quot; : &quot; + error.getDefaultMessage()\r\n    );\r\n}<\/code><\/pre>\n<p>\u30ed\u30b0\u3084\u30ec\u30b9\u30dd\u30f3\u30b9\u3078\u305d\u306e\u307e\u307e\u51fa\u3059\u524d\u306b\u3001\u500b\u4eba\u60c5\u5831\u3084\u5165\u529b\u5024\u3092\u542b\u307e\u306a\u3044\u304b\u306f\u78ba\u8a8d\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u30a8\u30e9\u30fc\u60c5\u5831\u3092\u53d6\u5f97\u3067\u304d\u308b\u3053\u3068\u3068\u3001\u3059\u3079\u3066\u3092\u5916\u90e8\u3078\u516c\u958b\u3057\u3066\u3088\u3044\u3053\u3068\u306f\u5225\u3067\u3059\u3002<\/p>\n<h2>\u753b\u9762\u3078\u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u623b\u3059<\/h2>\n<p>Thymeleaf\u3092\u4f7f\u3046\u5834\u5408\u3001\u30d5\u30a9\u30fc\u30e0\u306e `th:object` \u3068\u5404\u5165\u529b\u306e `th:field` \u3092\u5bfe\u5fdc\u3055\u305b\u3001`#fields.hasErrors(&#8230;)` \u3084 `th:errors` \u3067\u30a8\u30e9\u30fc\u3092\u8868\u793a\u3067\u304d\u307e\u3059\u3002Controller\u5074\u306f\u30a8\u30e9\u30fc\u6642\u306bredirect\u305b\u305a\u3001\u30d5\u30a9\u30fc\u30e0View\u3092\u305d\u306e\u307e\u307e\u8fd4\u3059\u57fa\u672c\u5f62\u304c\u5206\u304b\u308a\u3084\u3059\u3044\u3067\u3059\u3002<\/p>\n<pre><code>&lt;form th:action=&quot;@{\/users}&quot; th:object=&quot;${userForm}&quot; method=&quot;post&quot;&gt;\r\n    &lt;input type=&quot;text&quot; th:field=&quot;*{name}&quot;&gt;\r\n    &lt;p th:if=&quot;${#fields.hasErrors(&#39;name&#39;)}&quot;\r\n       th:errors=&quot;*{name}&quot;&gt;&lt;\/p&gt;\r\n\r\n    &lt;input type=&quot;email&quot; th:field=&quot;*{email}&quot;&gt;\r\n    &lt;p th:if=&quot;${#fields.hasErrors(&#39;email&#39;)}&quot;\r\n       th:errors=&quot;*{email}&quot;&gt;&lt;\/p&gt;\r\n\r\n    &lt;button type=&quot;submit&quot;&gt;\u4fdd\u5b58&lt;\/button&gt;\r\n&lt;\/form&gt;<\/code><\/pre>\n<p>Spring\u3068Thymeleaf\u306e\u9023\u643a\u3067\u306f\u3001\u30d5\u30a9\u30fc\u30e0\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u7d10\u3065\u304f\u30a8\u30e9\u30fc\u60c5\u5831\u3092\u4f7f\u3063\u3066\u30d5\u30a3\u30fc\u30eb\u30c9\u5358\u4f4d\u306e\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u8868\u793a\u3067\u304d\u307e\u3059\u3002\u753b\u9762\u5074\u3067\u72ec\u81ea\u306b\u540c\u3058validation\u6761\u4ef6\u3092\u518d\u5b9f\u88c5\u305b\u305a\u3001\u30b5\u30fc\u30d0\u30fc\u5074\u306e\u7d50\u679c\u3092\u8868\u793a\u3059\u308b\u5f62\u306b\u5bc4\u305b\u308b\u3068\u6761\u4ef6\u306e\u4e8c\u91cd\u7ba1\u7406\u3092\u6e1b\u3089\u305b\u307e\u3059\u3002<\/p>\n<h2>binding error\u3068validation error\u3092\u5206\u3051\u3066\u898b\u308b<\/h2>\n<p>`BindingResult` \u306e\u5f37\u307f\u306f\u3001\u5236\u7d04\u9055\u53cd\u3060\u3051\u3067\u306a\u304f\u30c7\u30fc\u30bf\u30d0\u30a4\u30f3\u30c9\u5931\u6557\u3082\u540c\u3058\u5165\u53e3\u304b\u3089\u78ba\u8a8d\u3067\u304d\u308b\u3053\u3068\u3067\u3059\u3002\u305f\u3068\u3048\u3070 `Integer age` \u306b `abc` \u304c\u9001\u3089\u308c\u305f\u5834\u5408\u3001`@Min` \u306e\u5224\u5b9a\u4ee5\u524d\u306b\u578b\u5909\u63db\u3067\u5931\u6557\u3059\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<pre><code>for (FieldError error : result.getFieldErrors()) {\r\n    if (error.isBindingFailure()) {\r\n        \/\/ \u578b\u5909\u63db\u306a\u3069\u3001\u30c7\u30fc\u30bf\u30d0\u30a4\u30f3\u30c9\u6bb5\u968e\u306e\u5931\u6557\r\n        System.out.println(&quot;binding error: &quot; + error.getField());\r\n    } else {\r\n        \/\/ Bean Validation\u306a\u3069\u306evalidation failure\r\n        System.out.println(&quot;validation error: &quot; + error.getField());\r\n    }\r\n}<\/code><\/pre>\n<p>\u300c@Valid\u306e\u30e1\u30c3\u30bb\u30fc\u30b8\u304c\u60f3\u5b9a\u3068\u9055\u3046\u300d\u3068\u304d\u306f\u3001\u5236\u7d04\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u3060\u3051\u3092\u898b\u308b\u306e\u3067\u306f\u306a\u304f\u3001\u305d\u3082\u305d\u3082\u5bfe\u8c61\u578b\u3078\u5024\u304c\u5909\u63db\u3067\u304d\u3066\u3044\u308b\u304b\u3082\u78ba\u8a8d\u3059\u308b\u3068\u539f\u56e0\u3092\u5207\u308a\u5206\u3051\u3084\u3059\u304f\u306a\u308a\u307e\u3059\u3002<\/p>\n<h2>rejectValue\u3068reject\u3067\u8ffd\u52a0\u30a8\u30e9\u30fc\u3092\u767b\u9332\u3059\u308b<\/h2>\n<p>Bean Validation\u306e\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u3060\u3051\u3067\u8868\u3057\u306b\u304f\u3044\u30c1\u30a7\u30c3\u30af\u3092Controller\u3084Validator\u3067\u884c\u3044\u3001BindingResult\u3078\u30a8\u30e9\u30fc\u3092\u8ffd\u52a0\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002\u30d5\u30a3\u30fc\u30eb\u30c9\u306b\u7d10\u3065\u3051\u308b\u306a\u3089 `rejectValue`\u3001\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u5168\u4f53\u3078\u4ed8\u3051\u308b\u306a\u3089 `reject` \u3092\u4f7f\u3044\u307e\u3059\u3002<\/p>\n<pre><code>if (!Objects.equals(form.getPassword(), form.getPasswordConfirm())) {\r\n    result.rejectValue(\r\n        &quot;passwordConfirm&quot;,\r\n        &quot;password.mismatch&quot;,\r\n        &quot;\u30d1\u30b9\u30ef\u30fc\u30c9\u304c\u4e00\u81f4\u3057\u307e\u305b\u3093&quot;\r\n    );\r\n}\r\n\r\nif (result.hasErrors()) {\r\n    return &quot;users\/form&quot;;\r\n}<\/code><\/pre>\n<p>\u8907\u96d1\u306a\u696d\u52d9\u30eb\u30fc\u30eb\u3092Controller\u3078\u5927\u91cf\u306b\u66f8\u304f\u306e\u3067\u306f\u306a\u304f\u3001\u8cac\u52d9\u304c\u5927\u304d\u304f\u306a\u3063\u305f\u3089\u5c02\u7528Validator\u3084Service\u5074\u306e\u691c\u8a3c\u3078\u5206\u96e2\u3059\u308b\u5224\u65ad\u3082\u5fc5\u8981\u3067\u3059\u3002BindingResult\u306f\u30a8\u30e9\u30fc\u3092\u4fdd\u6301\u3059\u308b\u5668\u3067\u3042\u308a\u3001\u3059\u3079\u3066\u306evalidation\u30ed\u30b8\u30c3\u30af\u3092Controller\u3078\u96c6\u7d04\u3059\u308b\u7406\u7531\u306b\u306f\u306a\u308a\u307e\u305b\u3093\u3002<\/p>\n<p>\uff08\u30ab\u30b9\u30bf\u30e0\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u3084MVC\u3078\u306evalidation\u7d71\u5408\u3092\u6df1\u6398\u308a\u3057\u305f\u3044\u5834\u5408\u306b\u3064\u3044\u3066\u306f\u300e<a href=\"https:\/\/route-zero.com\/recruit\/route\/1115\/\">Spring Boot \u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u5165\u9580\uff5cMVC\u7d71\u5408\u3068\u30ab\u30b9\u30bf\u30e0\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u5b9f\u8df5\u4f8b<\/a>\u300f\u3092\u3054\u53c2\u7167\u304f\u3060\u3055\u3044\uff09<\/p>\n<h2>BindingResult\u304c\u52b9\u304b\u306a\u3044\u3068\u304d\u306e\u78ba\u8a8d\u9806<\/h2>\n<p>`result.hasErrors()` \u304c\u5e38\u306b `false` \u306b\u306a\u308b\u3001\u307e\u305f\u306fController\u3078\u5165\u308b\u524d\u306b\u4f8b\u5916\u306b\u306a\u308b\u5834\u5408\u306f\u3001\u6b21\u306e\u9806\u3067\u78ba\u8a8d\u3059\u308b\u3068\u5207\u308a\u5206\u3051\u3084\u3059\u304f\u306a\u308a\u307e\u3059\u3002<\/p>\n<ul>\n<li>`@Valid` \u307e\u305f\u306f\u5fc5\u8981\u306a `@Validated` \u304c\u691c\u8a3c\u5bfe\u8c61\u3078\u4ed8\u3044\u3066\u3044\u308b\u304b<\/li>\n<li>`BindingResult` \u304c\u691c\u8a3c\u5bfe\u8c61\u306e\u5f15\u6570\u306e\u76f4\u5f8c\u306b\u7f6e\u304b\u308c\u3066\u3044\u308b\u304b<\/li>\n<li>\u30d5\u30a9\u30fc\u30e0\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b `@NotBlank` \u3084 `@Email` \u306a\u3069\u76ee\u7684\u306e\u5236\u7d04\u304c\u4ed8\u3044\u3066\u3044\u308b\u304b<\/li>\n<li>\u5165\u529b\u5024\u304cvalidation\u4ee5\u524d\u306e\u30c7\u30fc\u30bf\u30d0\u30a4\u30f3\u30c9\u3067\u5931\u6557\u3057\u3066\u3044\u306a\u3044\u304b<\/li>\n<li>Controller\u30e1\u30bd\u30c3\u30c9\u306e\u5225\u30d1\u30e9\u30e1\u30fc\u30bf\u306b\u76f4\u63a5Constraint\u3092\u4ed8\u3051\u3001method validation\u304c\u9069\u7528\u3055\u308c\u308b\u69cb\u6210\u306b\u306a\u3063\u3066\u3044\u306a\u3044\u304b<\/li>\n<li>\u753b\u9762\u306e `th:object` \/ `th:field` \u3068Controller\u306emodel attribute\u540d\u304c\u5bfe\u5fdc\u3057\u3066\u3044\u308b\u304b<\/li>\n<\/ul>\n<p>\u73fe\u5728\u306eSpring MVC\u3067\u306f\u3001\u30e1\u30bd\u30c3\u30c9\u5f15\u6570\u3078\u76f4\u63a5Constraint\u3092\u4ed8\u3051\u308b\u306a\u3069method validation\u304c\u9069\u7528\u3055\u308c\u308b\u3068\u3001\u30a8\u30e9\u30fc\u306e\u6271\u3044\u304c `HandlerMethodValidationException` \u5074\u306b\u306a\u308b\u30b1\u30fc\u30b9\u304c\u3042\u308a\u307e\u3059\u3002BindingResult\u3060\u3051\u3092\u898b\u3066\u539f\u56e0\u3092\u6c7a\u3081\u3064\u3051\u306a\u3044\u3053\u3068\u304c\u5927\u5207\u3067\u3059\u3002<\/p>\n<p>\uff08validation\u81ea\u4f53\u304c\u767a\u706b\u3057\u306a\u3044\u30fb\u671f\u5f85\u901a\u308a\u52b9\u304b\u306a\u3044\u5834\u5408\u306b\u3064\u3044\u3066\u306f\u300e<a href=\"https:\/\/route-zero.com\/recruit\/route\/1894\/\">Spring Boot \u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u52b9\u304b\u306a\u3044\uff1f5\u5206\u3067\u76f4\u3059\u65b9\u6cd5<\/a>\u300f\u3092\u3054\u53c2\u7167\u304f\u3060\u3055\u3044\uff09<\/p>\n<h2>REST API\u3067\u306f\u4f8b\u5916\u51e6\u7406\u3068\u306e\u4f7f\u3044\u5206\u3051\u3092\u8003\u3048\u308b<\/h2>\n<p>`BindingResult` \u306f\u30d5\u30a9\u30fc\u30e0\u3060\u3051\u306e\u4ed5\u7d44\u307f\u3067\u306f\u306a\u304f\u3001Spring MVC\u306emethod argument\u3068\u3057\u3066 `@RequestBody` \u3084 `@RequestPart` \u306evalidation error\u3078\u30a2\u30af\u30bb\u30b9\u3059\u308b\u7528\u9014\u3067\u3082\u4f7f\u3048\u307e\u3059\u3002\u4e00\u65b9\u3001REST API\u3067\u306f\u30a8\u30e9\u30fc\u5f62\u5f0f\u3092\u5168\u30a8\u30f3\u30c9\u30dd\u30a4\u30f3\u30c8\u3067\u7d71\u4e00\u3057\u305f\u3044\u3053\u3068\u304c\u591a\u3044\u305f\u3081\u3001\u4f8b\u5916\u51e6\u7406\u3078\u5bc4\u305b\u308b\u8a2d\u8a08\u3082\u9078\u629e\u80a2\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<table>\n<thead>\n<tr>\n<th>\u7528\u9014<\/th>\n<th>\u6271\u3044\u65b9\u306e\u4f8b<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>HTML\u30d5\u30a9\u30fc\u30e0\u3067\u540c\u3058\u753b\u9762\u3078\u623b\u3059<\/td>\n<td>`BindingResult` \u3092\u76f4\u5f8c\u306b\u7f6e\u304d\u3001Controller\u5185\u3067View\u3092\u5206\u5c90\u3059\u308b<\/td>\n<\/tr>\n<tr>\n<td>REST API\u3067Controller\u3054\u3068\u306b\u500b\u5225\u51e6\u7406\u3057\u305f\u3044<\/td>\n<td>`BindingResult` \u3092\u76f4\u5f8c\u306b\u7f6e\u3044\u3066\u30a8\u30e9\u30fc\u30ec\u30b9\u30dd\u30f3\u30b9\u3092\u7d44\u307f\u7acb\u3066\u308b<\/td>\n<\/tr>\n<tr>\n<td>REST API\u3067\u30a8\u30e9\u30fc\u5f62\u5f0f\u3092\u5171\u901a\u5316\u3057\u305f\u3044<\/td>\n<td>BindingResult\u3092\u7f6e\u304b\u305a\u3001`MethodArgumentNotValidException` \u306a\u3069\u3092 `@ControllerAdvice` \/ `@ExceptionHandler` \u3067\u6271\u3046<\/td>\n<\/tr>\n<tr>\n<td>method validation\u304c\u9069\u7528\u3055\u308c\u308b<\/td>\n<td>`HandlerMethodValidationException` \u3082\u8003\u616e\u3059\u308b<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u3069\u3061\u3089\u304c\u5e38\u306b\u6b63\u89e3\u3068\u3044\u3046\u8a71\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002\u753b\u9762\u9077\u79fb\u3092Controller\u5185\u3067\u6c7a\u3081\u305f\u3044\u306e\u304b\u3001API\u30a8\u30e9\u30fc\u3092\u6a2a\u65ad\u7684\u306b\u7d71\u4e00\u3057\u305f\u3044\u306e\u304b\u3067\u3001\u30a8\u30e9\u30fc\u3092\u53d7\u3051\u53d6\u308b\u5834\u6240\u3092\u6c7a\u3081\u308b\u3068\u8a2d\u8a08\u304c\u3076\u308c\u306b\u304f\u304f\u306a\u308a\u307e\u3059\u3002<\/p>\n<h2>\u307e\u3068\u3081\uff1aBindingResult\u306f\u30a8\u30e9\u30fc\u3092\u6b21\u306e\u51e6\u7406\u3078\u3064\u306a\u3050\u7d50\u679c\u30db\u30eb\u30c0\u30fc<\/h2>\n<ul>\n<li>`BindingResult` \u306fdata binding\u3068validation\u306e\u30a8\u30e9\u30fc\u7d50\u679c\u3078\u30a2\u30af\u30bb\u30b9\u3059\u308b\u305f\u3081\u306e\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9<\/li>\n<li>`@Valid` \u306a\u3069\u3067\u691c\u8a3c\u3059\u308b\u5f15\u6570\u306e\u76f4\u5f8c\u306b\u7f6e\u304f\u306e\u304c\u57fa\u672c<\/li>\n<li>`hasErrors()` \u3060\u3051\u3067\u306a\u304f `getFieldErrors()`\u30fb`getGlobalErrors()` \u3067\u5185\u5bb9\u3092\u78ba\u8a8d\u3067\u304d\u308b<\/li>\n<li>`FieldError#isBindingFailure()` \u3092\u898b\u308b\u3068\u578b\u5909\u63db\u306a\u3069binding\u6bb5\u968e\u306e\u5931\u6557\u3092\u5207\u308a\u5206\u3051\u3089\u308c\u308b<\/li>\n<li>Thymeleaf\u3067\u306f `th:field` \u3068 `th:errors` \u3092\u4f7f\u3044\u3001\u30b5\u30fc\u30d0\u30fc\u5074\u306evalidation\u7d50\u679c\u3092\u753b\u9762\u3078\u8868\u793a\u3067\u304d\u308b<\/li>\n<li>REST API\u3067\u306fBindingResult\u3067\u5c40\u6240\u51e6\u7406\u3059\u308b\u304b\u3001\u4f8b\u5916\u3092\u5171\u901a\u51e6\u7406\u3059\u308b\u304b\u3092\u8a2d\u8a08\u3067\u9078\u3076<\/li>\n<\/ul>\n<p>\u307e\u305a\u306f\u73fe\u5728\u306eController\u3067\u3001\u691c\u8a3c\u5bfe\u8c61\u3068 `BindingResult` \u306e\u4e26\u3073\u9806\u3092\u78ba\u8a8d\u3057\u3001`hasErrors()` \u306e\u4e2d\u3067 `getFieldErrors()` \u3092\u4e00\u5ea6\u898b\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002\u30a8\u30e9\u30fc\u304c\u300c\u5236\u7d04\u9055\u53cd\u300d\u306a\u306e\u304b\u300c\u5024\u3092\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3078\u5909\u63db\u3067\u304d\u306a\u304b\u3063\u305f\u300d\u306e\u304b\u307e\u3067\u5206\u304b\u308b\u3068\u3001validation\u30c8\u30e9\u30d6\u30eb\u306e\u5207\u308a\u5206\u3051\u304c\u4e00\u6c17\u306b\u5177\u4f53\u7684\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n","protected":false},"featured_media":6361,"template":"","meta":{"ssp_meta_title":"Spring Boot\u306eBindingResult\u3068\u306f\uff1f@Valid\u306e\u30a8\u30e9\u30fc\u53d6\u5f97\u3068\u4f7f\u3044\u65b9","ssp_meta_description":"Spring Boot\u306eBindingResult\u3092\u5b9f\u52d9\u30b3\u30fc\u30c9\u3067\u89e3\u8aac\u3002@Valid\u3068\u306e\u95a2\u4fc2\u3001\u7f6e\u304f\u4f4d\u7f6e\u3001hasErrors\u30fbgetFieldErrors\u306e\u4f7f\u3044\u65b9\u3001Thymeleaf\u3067\u306e\u30a8\u30e9\u30fc\u8868\u793a\u3001binding error\u3068validation error\u3001REST API\u3067\u306e\u4f8b\u5916\u51e6\u7406\u3068\u306e\u4f7f\u3044\u5206\u3051\u307e\u3067\u6574\u7406\u3057\u307e\u3059\u3002","ssp_meta_keyword":"Spring Boot BindingResult,BindingResult \u4f7f\u3044\u65b9,Spring Boot @Valid,BindingResult hasErrors,BindingResult getFieldErrors,Spring Boot \u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3 \u30a8\u30e9\u30fc,Thymeleaf th:errors,MethodArgumentNotValidException","ssp_meta_canonical":""},"route_category":[9],"_links":{"self":[{"href":"https:\/\/route-zero.com\/recruit\/wp-json\/wp\/v2\/route\/6360"}],"collection":[{"href":"https:\/\/route-zero.com\/recruit\/wp-json\/wp\/v2\/route"}],"about":[{"href":"https:\/\/route-zero.com\/recruit\/wp-json\/wp\/v2\/types\/route"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/route-zero.com\/recruit\/wp-json\/wp\/v2\/media\/6361"}],"wp:attachment":[{"href":"https:\/\/route-zero.com\/recruit\/wp-json\/wp\/v2\/media?parent=6360"}],"wp:term":[{"taxonomy":"route_category","embeddable":true,"href":"https:\/\/route-zero.com\/recruit\/wp-json\/wp\/v2\/route_category?post=6360"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}