{"id":14813,"date":"2019-07-21T18:36:30","date_gmt":"2019-07-21T11:36:30","guid":{"rendered":"https:\/\/huongdanjava.com\/?p=14813"},"modified":"2019-07-21T18:36:30","modified_gmt":"2019-07-21T11:36:30","slug":"validate-request-data-in-spring-mvc-with-bean-validation","status":"publish","type":"post","link":"https:\/\/huongdanjava.com\/validate-request-data-in-spring-mvc-with-bean-validation.html","title":{"rendered":"Validate request data in Spring MVC with Bean Validation"},"content":{"rendered":"<p>When building any application, it is necessary to handle all possible behaviors when users use our application. One of the cases you will often face when working with Spring MVC applications is that the request data that the user transmits will not correct the expectation so that our application can handle. To avoid these situations, you can use <a href=\"https:\/\/huongdanjava.com\/introduction-about-bean-validation-in-java.html\" target=\"_blank\" rel=\"noopener noreferrer\">Bean Validation<\/a> with Spring MVC to prevent such data requests. How is it in details? Let&#8217;s find out in this tutorial!<\/p>\n<p>First, I will create a new Spring Boot project with Web Starter dependency for example:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-14815 size-full\" src=\"https:\/\/huongdanjava.com\/wp-content\/uploads\/2019\/07\/validate-request-data-in-spring-mvc-with-bean-validation-1.png\" alt=\"Validate request data in Spring MVC with Bean Validation\" width=\"638\" height=\"492\" \/><\/p>\n<p>Now I will create a new controller with a simple request like this:<\/p>\n<pre class=\"lang:java decode:true \">package com.huongdanjava.springmvcvalidation;\r\n\r\nimport org.springframework.web.bind.annotation.GetMapping;\r\nimport org.springframework.web.bind.annotation.RequestParam;\r\nimport org.springframework.web.bind.annotation.RestController;\r\n\r\n@RestController\r\npublic class HelloController {\r\n\r\n\t@GetMapping(\"\/hello\")\r\n\tpublic String hello(@RequestParam Integer id) {\r\n\t\treturn id + \"\";\r\n\t}\r\n\r\n}\r\n<\/pre>\n<p><strong>Validating the data type of the request parameter &#8220;id&#8221; in the above example<\/strong>, by defaults, Spring MVC handles already:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-14816 size-full\" src=\"https:\/\/huongdanjava.com\/wp-content\/uploads\/2019\/07\/validate-request-data-in-spring-mvc-with-bean-validation-2.png\" alt=\"Validate request data in Spring MVC with Bean Validation\" width=\"700\" height=\"460\" \/><\/p>\n<p>In the above request, I pass the value to the request parameter id as &#8220;Khanh&#8221; but the data type of this parameter must be Integer so Spring MVC will respond to the error message.<\/p>\n<p>But in case, we need the value of the request parameter id from users must be greater than or equal to 10 for example, Spring MVC by default does not help us with this. In that case, we can use the code to do this, for example:<\/p>\n<pre class=\"lang:java decode:true\">package com.huongdanjava.springmvcvalidation;\r\n\r\nimport org.springframework.web.bind.annotation.GetMapping;\r\nimport org.springframework.web.bind.annotation.RequestParam;\r\nimport org.springframework.web.bind.annotation.RestController;\r\n\r\n@RestController\r\npublic class HelloController {\r\n\r\n\t@GetMapping(\"\/hello\")\r\n\tpublic String hello(@RequestParam Integer id) {\r\n\t\tif (id &lt; 10) {\r\n\t\t\treturn \"Not valid id\";\r\n\t\t}\r\n\r\n\t\treturn id + \"\";\r\n\t}\r\n\r\n}\r\n<\/pre>\n<p>or use Java&#8217;s Bean Validation as follows:<\/p>\n<pre class=\"lang:java decode:true \">package com.huongdanjava.springmvcvalidation;\r\n\r\nimport javax.validation.constraints.Min;\r\n\r\nimport org.springframework.validation.annotation.Validated;\r\nimport org.springframework.web.bind.annotation.GetMapping;\r\nimport org.springframework.web.bind.annotation.RequestParam;\r\nimport org.springframework.web.bind.annotation.RestController;\r\n\r\n@RestController\r\n@Validated\r\npublic class HelloController {\r\n\r\n\t@GetMapping(\"\/hello\")\r\n\tpublic String hello(@RequestParam @Min(10) Integer id) {\r\n\t\treturn id + \"\";\r\n\t}\r\n\r\n}\r\n<\/pre>\n<p>In the above code, I used the @Min annotation of the Java Bean Validation to declare the constraint for the value of the request parameter id must be greater than or equal to 10 and it is mandatory that you declare the @Validated annotation of Spring.<\/p>\n<p>If the request with the value of the request parameter id is greater than 10, the result will look like this:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-14817 size-full\" src=\"https:\/\/huongdanjava.com\/wp-content\/uploads\/2019\/07\/validate-request-data-in-spring-mvc-with-bean-validation-3.png\" alt=\"Validate request data in Spring MVC with Bean Validation\" width=\"700\" height=\"467\" \/><\/p>\n<p><strong>Similar to requests with request parameters, if your application uses path variable:<\/strong><\/p>\n<pre class=\"lang:java decode:true \">package com.huongdanjava.springmvcvalidation;\r\n\r\nimport org.springframework.web.bind.annotation.GetMapping;\r\nimport org.springframework.web.bind.annotation.PathVariable;\r\nimport org.springframework.web.bind.annotation.RestController;\r\n\r\n@RestController\r\npublic class HelloController {\r\n\r\n\t@GetMapping(\"\/{id}\")\r\n\tpublic String hello(@PathVariable Integer id) {\r\n\t\treturn id + \"\";\r\n\t}\r\n\r\n}\r\n<\/pre>\n<p>then you can also use Java Bean Validation with @Validated annotation of Spring as follows:<\/p>\n<pre class=\"lang:java decode:true \">package com.huongdanjava.springmvcvalidation;\r\n\r\nimport javax.validation.constraints.Min;\r\n\r\nimport org.springframework.validation.annotation.Validated;\r\nimport org.springframework.web.bind.annotation.GetMapping;\r\nimport org.springframework.web.bind.annotation.PathVariable;\r\nimport org.springframework.web.bind.annotation.RestController;\r\n\r\n@RestController\r\n@Validated\r\npublic class HelloController {\r\n\r\n\t@GetMapping(\"\/{id}\")\r\n\tpublic String hello(@PathVariable @Min(10) Integer id) {\r\n\t\treturn id + \"\";\r\n\t}\r\n\r\n}\r\n<\/pre>\n<p>Result:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-14818 size-full\" src=\"https:\/\/huongdanjava.com\/wp-content\/uploads\/2019\/07\/validate-request-data-in-spring-mvc-with-bean-validation-4.png\" alt=\"Validate request data in Spring MVC with Bean Validation\" width=\"700\" height=\"469\" \/><\/p>\n<p><strong>For requests that request data in the body such as a POST request, we can also apply Bean Validation to the object that holds the information of the request data.<\/strong><\/p>\n<p>For example, I have a POST request that transmits student information:<\/p>\n<pre class=\"lang:java decode:true\">package com.huongdanjava.springmvcvalidation;\r\n\r\nimport org.springframework.web.bind.annotation.PostMapping;\r\nimport org.springframework.web.bind.annotation.RequestBody;\r\nimport org.springframework.web.bind.annotation.RestController;\r\n\r\n@RestController\r\npublic class HelloController {\r\n\r\n\t@PostMapping(\"\/student\")\r\n\tpublic String student(@RequestBody Student student) {\r\n\t\treturn student.getName();\r\n\t}\r\n\r\n}\r\n<\/pre>\n<p>with the student information defined using Bean Validation as follows:<\/p>\n<pre class=\"lang:java decode:true \">package com.huongdanjava.springmvcvalidation;\r\n\r\nimport javax.validation.constraints.Min;\r\nimport javax.validation.constraints.NotNull;\r\n\r\npublic class Student {\r\n\r\n\t@NotNull\r\n\tprivate String name;\r\n\t\r\n\t@Min(value = 18)\r\n\tprivate int age;\r\n\r\n\tpublic String getName() {\r\n\t\treturn name;\r\n\t}\r\n\r\n\tpublic void setName(String name) {\r\n\t\tthis.name = name;\r\n\t}\r\n\r\n\tpublic int getAge() {\r\n\t\treturn age;\r\n\t}\r\n\r\n\tpublic void setAge(int age) {\r\n\t\tthis.age = age;\r\n\t}\r\n\t\r\n\t\r\n}\r\n<\/pre>\n<p>With the above definition, I want the student information to have name and age must be greater than or equal to 18.<\/p>\n<p>To enable Bean Validation in Spring MVC with requests that data is in the body, we will use @Valid annotation of Bean Validation as follows:<\/p>\n<pre class=\"lang:java decode:true \">package com.huongdanjava.springmvcvalidation;\r\n\r\nimport javax.validation.Valid;\r\n\r\nimport org.springframework.web.bind.annotation.PostMapping;\r\nimport org.springframework.web.bind.annotation.RequestBody;\r\nimport org.springframework.web.bind.annotation.RestController;\r\n\r\n@RestController\r\npublic class HelloController {\r\n\r\n\t@PostMapping(\"\/student\")\r\n\tpublic String student(@Valid @RequestBody Student student) {\r\n\t\treturn student.getName();\r\n\t}\r\n\r\n}\r\n<\/pre>\n<p>The result if I request the invalid request will be as follows:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-14819 size-full\" src=\"https:\/\/huongdanjava.com\/wp-content\/uploads\/2019\/07\/validate-request-data-in-spring-mvc-with-bean-validation-5.png\" alt=\"Validate request data in Spring MVC with Bean Validation\" width=\"700\" height=\"734\" \/><\/p>\n\n\n<div class=\"kk-star-ratings kksr-auto kksr-align-right kksr-valign-bottom\"\n    data-payload='{&quot;align&quot;:&quot;right&quot;,&quot;id&quot;:&quot;14813&quot;,&quot;slug&quot;:&quot;default&quot;,&quot;valign&quot;:&quot;bottom&quot;,&quot;ignore&quot;:&quot;&quot;,&quot;reference&quot;:&quot;auto&quot;,&quot;class&quot;:&quot;&quot;,&quot;count&quot;:&quot;0&quot;,&quot;legendonly&quot;:&quot;&quot;,&quot;readonly&quot;:&quot;&quot;,&quot;score&quot;:&quot;0&quot;,&quot;starsonly&quot;:&quot;&quot;,&quot;best&quot;:&quot;5&quot;,&quot;gap&quot;:&quot;4&quot;,&quot;greet&quot;:&quot;&quot;,&quot;legend&quot;:&quot;0\\\/5 - (0 votes)&quot;,&quot;size&quot;:&quot;24&quot;,&quot;title&quot;:&quot;Validate request data in Spring MVC with Bean Validation&quot;,&quot;width&quot;:&quot;0&quot;,&quot;_legend&quot;:&quot;{score}\\\/{best} - ({count} {votes})&quot;,&quot;font_factor&quot;:&quot;1.25&quot;}'>\n            \n<div class=\"kksr-stars\">\n    \n<div class=\"kksr-stars-inactive\">\n            <div class=\"kksr-star\" data-star=\"1\" style=\"padding-right: 4px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"2\" style=\"padding-right: 4px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"3\" style=\"padding-right: 4px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"4\" style=\"padding-right: 4px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"5\" style=\"padding-right: 4px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n    <\/div>\n    \n<div class=\"kksr-stars-active\" style=\"width: 0px;\">\n            <div class=\"kksr-star\" style=\"padding-right: 4px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 4px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 4px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 4px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 4px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n    <\/div>\n<\/div>\n                \n\n<div class=\"kksr-legend\" style=\"font-size: 19.2px;\">\n            <span class=\"kksr-muted\"><\/span>\n    <\/div>\n    <\/div>\n","protected":false},"excerpt":{"rendered":"<p>When building any application, it is necessary to handle all possible behaviors when users use our application. One of the cases you will often face when working with Spring MVC applications is that the request data that the user transmits will not correct the expectation&hellip; <a href=\"https:\/\/huongdanjava.com\/validate-request-data-in-spring-mvc-with-bean-validation.html\">Read More<\/a><\/p>\n","protected":false},"author":1,"featured_media":3220,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[678],"tags":[],"class_list":["post-14813","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-spring-mvc-en","clearfix"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Validate request data in Spring MVC with Bean Validation - Huong Dan Java<\/title>\n<meta name=\"description\" content=\"In this tutorial, I will guide you all how to validate request data in Spring MVC with Bean Validation.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/huongdanjava.com\/validate-request-data-in-spring-mvc-with-bean-validation.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Validate request data in Spring MVC with Bean Validation - Huong Dan Java\" \/>\n<meta property=\"og:description\" content=\"In this tutorial, I will guide you all how to validate request data in Spring MVC with Bean Validation.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/huongdanjava.com\/validate-request-data-in-spring-mvc-with-bean-validation.html\" \/>\n<meta property=\"og:site_name\" content=\"Huong Dan Java\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/nhkhanh2406\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/nhkhanh2406\" \/>\n<meta property=\"article:published_time\" content=\"2019-07-21T11:36:30+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/huongdanjava.com\/wp-content\/uploads\/2017\/07\/spring-framework.png\" \/>\n\t<meta property=\"og:image:width\" content=\"200\" \/>\n\t<meta property=\"og:image:height\" content=\"200\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Khanh Nguyen\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/KhanhNguyenJ\" \/>\n<meta name=\"twitter:site\" content=\"@KhanhNguyenJ\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Khanh Nguyen\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/validate-request-data-in-spring-mvc-with-bean-validation.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/validate-request-data-in-spring-mvc-with-bean-validation.html\"},\"author\":{\"name\":\"Khanh Nguyen\",\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/#\\\/schema\\\/person\\\/dc859d7f8cbea3b593e6738de9cbb82d\"},\"headline\":\"Validate request data in Spring MVC with Bean Validation\",\"datePublished\":\"2019-07-21T11:36:30+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/validate-request-data-in-spring-mvc-with-bean-validation.html\"},\"wordCount\":424,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/#\\\/schema\\\/person\\\/dc859d7f8cbea3b593e6738de9cbb82d\"},\"image\":{\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/validate-request-data-in-spring-mvc-with-bean-validation.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/huongdanjava.com\\\/wp-content\\\/uploads\\\/2017\\\/07\\\/spring-framework.png\",\"articleSection\":[\"Spring MVC\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/huongdanjava.com\\\/validate-request-data-in-spring-mvc-with-bean-validation.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/validate-request-data-in-spring-mvc-with-bean-validation.html\",\"url\":\"https:\\\/\\\/huongdanjava.com\\\/validate-request-data-in-spring-mvc-with-bean-validation.html\",\"name\":\"Validate request data in Spring MVC with Bean Validation - Huong Dan Java\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/validate-request-data-in-spring-mvc-with-bean-validation.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/validate-request-data-in-spring-mvc-with-bean-validation.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/huongdanjava.com\\\/wp-content\\\/uploads\\\/2017\\\/07\\\/spring-framework.png\",\"datePublished\":\"2019-07-21T11:36:30+00:00\",\"description\":\"In this tutorial, I will guide you all how to validate request data in Spring MVC with Bean Validation.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/validate-request-data-in-spring-mvc-with-bean-validation.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/huongdanjava.com\\\/validate-request-data-in-spring-mvc-with-bean-validation.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/validate-request-data-in-spring-mvc-with-bean-validation.html#primaryimage\",\"url\":\"https:\\\/\\\/huongdanjava.com\\\/wp-content\\\/uploads\\\/2017\\\/07\\\/spring-framework.png\",\"contentUrl\":\"https:\\\/\\\/huongdanjava.com\\\/wp-content\\\/uploads\\\/2017\\\/07\\\/spring-framework.png\",\"width\":200,\"height\":200},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/validate-request-data-in-spring-mvc-with-bean-validation.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/huongdanjava.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Validate request data in Spring MVC with Bean Validation\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/#website\",\"url\":\"https:\\\/\\\/huongdanjava.com\\\/\",\"name\":\"Huong Dan Java\",\"description\":\"Java development tutorials\",\"publisher\":{\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/#\\\/schema\\\/person\\\/dc859d7f8cbea3b593e6738de9cbb82d\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/huongdanjava.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/#\\\/schema\\\/person\\\/dc859d7f8cbea3b593e6738de9cbb82d\",\"name\":\"Khanh Nguyen\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/wp-content\\\/uploads\\\/2021\\\/07\\\/CC6FAC58-D227-4DD8-93D1-6D6A795577E3_1_201_a.jpeg\",\"url\":\"https:\\\/\\\/huongdanjava.com\\\/wp-content\\\/uploads\\\/2021\\\/07\\\/CC6FAC58-D227-4DD8-93D1-6D6A795577E3_1_201_a.jpeg\",\"contentUrl\":\"https:\\\/\\\/huongdanjava.com\\\/wp-content\\\/uploads\\\/2021\\\/07\\\/CC6FAC58-D227-4DD8-93D1-6D6A795577E3_1_201_a.jpeg\",\"width\":1267,\"height\":1517,\"caption\":\"Khanh Nguyen\"},\"logo\":{\"@id\":\"https:\\\/\\\/huongdanjava.com\\\/wp-content\\\/uploads\\\/2021\\\/07\\\/CC6FAC58-D227-4DD8-93D1-6D6A795577E3_1_201_a.jpeg\"},\"description\":\"I love Java and everything related to Java.\",\"sameAs\":[\"https:\\\/\\\/huongdanjava.com\",\"https:\\\/\\\/www.facebook.com\\\/nhkhanh2406\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/KhanhNguyenJ\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Validate request data in Spring MVC with Bean Validation - Huong Dan Java","description":"In this tutorial, I will guide you all how to validate request data in Spring MVC with Bean Validation.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/huongdanjava.com\/validate-request-data-in-spring-mvc-with-bean-validation.html","og_locale":"en_US","og_type":"article","og_title":"Validate request data in Spring MVC with Bean Validation - Huong Dan Java","og_description":"In this tutorial, I will guide you all how to validate request data in Spring MVC with Bean Validation.","og_url":"https:\/\/huongdanjava.com\/validate-request-data-in-spring-mvc-with-bean-validation.html","og_site_name":"Huong Dan Java","article_publisher":"https:\/\/www.facebook.com\/nhkhanh2406","article_author":"https:\/\/www.facebook.com\/nhkhanh2406","article_published_time":"2019-07-21T11:36:30+00:00","og_image":[{"width":200,"height":200,"url":"https:\/\/huongdanjava.com\/wp-content\/uploads\/2017\/07\/spring-framework.png","type":"image\/png"}],"author":"Khanh Nguyen","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/KhanhNguyenJ","twitter_site":"@KhanhNguyenJ","twitter_misc":{"Written by":"Khanh Nguyen","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/huongdanjava.com\/validate-request-data-in-spring-mvc-with-bean-validation.html#article","isPartOf":{"@id":"https:\/\/huongdanjava.com\/validate-request-data-in-spring-mvc-with-bean-validation.html"},"author":{"name":"Khanh Nguyen","@id":"https:\/\/huongdanjava.com\/#\/schema\/person\/dc859d7f8cbea3b593e6738de9cbb82d"},"headline":"Validate request data in Spring MVC with Bean Validation","datePublished":"2019-07-21T11:36:30+00:00","mainEntityOfPage":{"@id":"https:\/\/huongdanjava.com\/validate-request-data-in-spring-mvc-with-bean-validation.html"},"wordCount":424,"commentCount":0,"publisher":{"@id":"https:\/\/huongdanjava.com\/#\/schema\/person\/dc859d7f8cbea3b593e6738de9cbb82d"},"image":{"@id":"https:\/\/huongdanjava.com\/validate-request-data-in-spring-mvc-with-bean-validation.html#primaryimage"},"thumbnailUrl":"https:\/\/huongdanjava.com\/wp-content\/uploads\/2017\/07\/spring-framework.png","articleSection":["Spring MVC"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/huongdanjava.com\/validate-request-data-in-spring-mvc-with-bean-validation.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/huongdanjava.com\/validate-request-data-in-spring-mvc-with-bean-validation.html","url":"https:\/\/huongdanjava.com\/validate-request-data-in-spring-mvc-with-bean-validation.html","name":"Validate request data in Spring MVC with Bean Validation - Huong Dan Java","isPartOf":{"@id":"https:\/\/huongdanjava.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/huongdanjava.com\/validate-request-data-in-spring-mvc-with-bean-validation.html#primaryimage"},"image":{"@id":"https:\/\/huongdanjava.com\/validate-request-data-in-spring-mvc-with-bean-validation.html#primaryimage"},"thumbnailUrl":"https:\/\/huongdanjava.com\/wp-content\/uploads\/2017\/07\/spring-framework.png","datePublished":"2019-07-21T11:36:30+00:00","description":"In this tutorial, I will guide you all how to validate request data in Spring MVC with Bean Validation.","breadcrumb":{"@id":"https:\/\/huongdanjava.com\/validate-request-data-in-spring-mvc-with-bean-validation.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/huongdanjava.com\/validate-request-data-in-spring-mvc-with-bean-validation.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/huongdanjava.com\/validate-request-data-in-spring-mvc-with-bean-validation.html#primaryimage","url":"https:\/\/huongdanjava.com\/wp-content\/uploads\/2017\/07\/spring-framework.png","contentUrl":"https:\/\/huongdanjava.com\/wp-content\/uploads\/2017\/07\/spring-framework.png","width":200,"height":200},{"@type":"BreadcrumbList","@id":"https:\/\/huongdanjava.com\/validate-request-data-in-spring-mvc-with-bean-validation.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/huongdanjava.com\/"},{"@type":"ListItem","position":2,"name":"Validate request data in Spring MVC with Bean Validation"}]},{"@type":"WebSite","@id":"https:\/\/huongdanjava.com\/#website","url":"https:\/\/huongdanjava.com\/","name":"Huong Dan Java","description":"Java development tutorials","publisher":{"@id":"https:\/\/huongdanjava.com\/#\/schema\/person\/dc859d7f8cbea3b593e6738de9cbb82d"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/huongdanjava.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/huongdanjava.com\/#\/schema\/person\/dc859d7f8cbea3b593e6738de9cbb82d","name":"Khanh Nguyen","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/huongdanjava.com\/wp-content\/uploads\/2021\/07\/CC6FAC58-D227-4DD8-93D1-6D6A795577E3_1_201_a.jpeg","url":"https:\/\/huongdanjava.com\/wp-content\/uploads\/2021\/07\/CC6FAC58-D227-4DD8-93D1-6D6A795577E3_1_201_a.jpeg","contentUrl":"https:\/\/huongdanjava.com\/wp-content\/uploads\/2021\/07\/CC6FAC58-D227-4DD8-93D1-6D6A795577E3_1_201_a.jpeg","width":1267,"height":1517,"caption":"Khanh Nguyen"},"logo":{"@id":"https:\/\/huongdanjava.com\/wp-content\/uploads\/2021\/07\/CC6FAC58-D227-4DD8-93D1-6D6A795577E3_1_201_a.jpeg"},"description":"I love Java and everything related to Java.","sameAs":["https:\/\/huongdanjava.com","https:\/\/www.facebook.com\/nhkhanh2406","https:\/\/x.com\/https:\/\/twitter.com\/KhanhNguyenJ"]}]}},"_links":{"self":[{"href":"https:\/\/huongdanjava.com\/wp-json\/wp\/v2\/posts\/14813","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/huongdanjava.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/huongdanjava.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/huongdanjava.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/huongdanjava.com\/wp-json\/wp\/v2\/comments?post=14813"}],"version-history":[{"count":3,"href":"https:\/\/huongdanjava.com\/wp-json\/wp\/v2\/posts\/14813\/revisions"}],"predecessor-version":[{"id":14821,"href":"https:\/\/huongdanjava.com\/wp-json\/wp\/v2\/posts\/14813\/revisions\/14821"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/huongdanjava.com\/wp-json\/wp\/v2\/media\/3220"}],"wp:attachment":[{"href":"https:\/\/huongdanjava.com\/wp-json\/wp\/v2\/media?parent=14813"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/huongdanjava.com\/wp-json\/wp\/v2\/categories?post=14813"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/huongdanjava.com\/wp-json\/wp\/v2\/tags?post=14813"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}