{"id":1336,"date":"2025-04-01T12:08:05","date_gmt":"2025-04-01T03:08:05","guid":{"rendered":"https:\/\/route-zero.com\/recruit\/route\/1336\/"},"modified":"2025-07-01T12:15:18","modified_gmt":"2025-07-01T03:15:18","slug":"1336","status":"publish","type":"route","link":"https:\/\/route-zero.com\/recruit\/route\/1336\/","title":{"rendered":"\u3010\u521d\u5fc3\u8005\u5411\u3051\u3011Spring Boot \u306e\u30d1\u30e9\u30e1\u30fc\u30bf\u53d7\u3051\u53d6\u308a\uff5c@ModelAttribute \u3068 @RequestBody \u306e\u9055\u3044\u3068\u4f7f\u3044\u5206\u3051"},"content":{"rendered":"<div>\n<h2>\u3042\u306a\u305f\u3082\u3053\u3093\u306a\u7d4c\u9a13\u3042\u308a\u307e\u305b\u3093\u304b\uff1f<\/h2>\n<p>Spring Boot \u3092\u4f7f\u3063\u3066 Web \u30a2\u30d7\u30ea\u3092\u4f5c\u3063\u3066\u3044\u308b\u3068\u3001\u300c\u5024\u304c\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u30fc\u306b\u5c4a\u304b\u306a\u3044\u300d\u300cPOST \u3057\u3066\u3082 null \u304c\u8fd4\u3063\u3066\u304f\u308b\u300d\u306a\u3069\u3001\u30d1\u30e9\u30e1\u30fc\u30bf\u53d7\u3051\u53d6\u308a\u3067\u3064\u307e\u305a\u3044\u305f\u3053\u3068\u306f\u3042\u308a\u307e\u305b\u3093\u304b\uff1f<\/p>\n<p>\u305f\u3068\u3048\u3070\u3001\u30d5\u30ed\u30f3\u30c8\u30a8\u30f3\u30c9\u304b\u3089 JSON \u3092 POST \u3057\u3066\u3044\u308b\u306e\u306b\u3001@ModelAttribute \u3092\u4f7f\u3063\u3066\u3082\u3046\u307e\u304f\u5024\u304c\u5165\u3089\u306a\u3044\u3002\u9006\u306b\u3001HTML \u30d5\u30a9\u30fc\u30e0\u304b\u3089\u9001\u3063\u3066\u3044\u308b\u306e\u306b\u3001@RequestBody \u3092\u3064\u3051\u305f\u3089 400 \u30a8\u30e9\u30fc\u306b\u306a\u3063\u305f\u2026\u2026\u3002\u305d\u3093\u306a\u7d4c\u9a13\u3001\u30a8\u30f3\u30b8\u30cb\u30a2\u306b\u306f\u4e00\u5ea6\u306f\u3042\u308b\u306f\u305a\u3067\u3059\u3002<\/p>\n<p>\u3053\u306e\u8a18\u4e8b\u3067\u306f\u3001<\/p>\n<ul>\n<li>\n<p>@ModelAttribute<\/p>\n<\/li>\n<li>\n<p>@RequestParam<\/p>\n<\/li>\n<li>\n<p>@RequestBody<\/p>\n<\/li>\n<\/ul>\n<p>\u306e\u9055\u3044\u3084\u5f79\u5272\u3001\u305d\u308c\u305e\u308c\u304c\u3069\u3046\u3044\u3046\u5834\u9762\u306b\u5411\u3044\u3066\u3044\u308b\u306e\u304b\u3092\u3001\u5b9f\u52d9\u30ec\u30d9\u30eb\u306e\u4f8b\u3068\u3068\u3082\u306b\u6574\u7406\u3057\u3066\u3044\u304d\u307e\u3059\u3002\u8aad\u3081\u3070\u3001\u300c\u3042\u308c\u3001\u3053\u308c\u3069\u308c\u4f7f\u3048\u3070\u3044\u3044\u3093\u3060\u3063\u3051\uff1f\u300d\u3068\u3044\u3046\u8ff7\u3044\u304c\u30b9\u30c3\u30ad\u30ea\u3059\u308b\u306f\u305a\u3067\u3059\u3002<\/p>\n<hr>\n<h2>\u306a\u305c\u3046\u307e\u304f\u53d7\u3051\u53d6\u308c\u306a\u3044\u306e\u304b\uff1f\u305d\u308c\u305e\u308c\u306e\u4ed5\u7d44\u307f\u3092\u7406\u89e3\u3057\u3088\u3046<\/h2>\n<h3>\u9001\u4fe1\u5f62\u5f0f\u3068\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u306e\u5bfe\u5fdc\u8868<\/h3>\n<ul>\n<li>\n<p>HTML \u30d5\u30a9\u30fc\u30e0\u9001\u4fe1\uff08application\/x-www-form-urlencoded\uff09 \u2192 @ModelAttribute<\/p>\n<\/li>\n<li>\n<p>\u30af\u30a8\u30ea\u30d1\u30e9\u30e1\u30fc\u30bf\uff08URL?name=\u301c\uff09 \u2192 @RequestParam<\/p>\n<\/li>\n<li>\n<p>JSON\uff08application\/json\uff09 \u2192 @RequestBody<\/p>\n<\/li>\n<\/ul>\n<p>\u3053\u306e\u5bfe\u5fdc\u8868\u3092\u982d\u306b\u5165\u308c\u3066\u304a\u304f\u3060\u3051\u3067\u3082\u3001\u30c8\u30e9\u30d6\u30eb\u306e\u591a\u304f\u3092\u9632\u3052\u307e\u3059\u3002<\/p>\n<h3>@ModelAttribute \u306e\u4ed5\u7d44\u307f\u3068\u4f7f\u3044\u3069\u3053\u308d<\/h3>\n<p>@ModelAttribute \u306f\u4e3b\u306b HTML \u30d5\u30a9\u30fc\u30e0\u9001\u4fe1\u3067\u4f7f\u308f\u308c\u307e\u3059\u3002Spring MVC \u304c\u30ea\u30af\u30a8\u30b9\u30c8\u306e\u5404\u30d1\u30e9\u30e1\u30fc\u30bf\u3092 Java \u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u306b\u30de\u30c3\u30d4\u30f3\u30b0\u3057\u307e\u3059\u3002<\/p>\n<pre><code><span>@PostMapping<\/span>(<span>\"\/register\"<\/span>)\r\n<span>public<\/span> <span>String<\/span> registerUser(<span>@ModelAttribute<\/span> UserForm form) {\r\n    <span>\/\/ form.getName(), form.getEmail() \u306a\u3069\u304c\u4f7f\u3048\u308b<\/span>\r\n    <span>return<\/span> <span>\"success\"<\/span>;\r\n}<\/code><\/pre>\n<p><strong>\u30dd\u30a4\u30f3\u30c8<\/strong>\uff1a\u30d5\u30a9\u30fc\u30e0\u9001\u4fe1\u3067 null \u306b\u306a\u308b\u306a\u3089\u3001\u307e\u305a @ModelAttribute \u304c\u6b63\u3057\u304f\u4f7f\u308f\u308c\u3066\u3044\u308b\u304b\u3092\u78ba\u8a8d\u3057\u307e\u3057\u3087\u3046\u3002Setter \u304c\u4e0d\u8db3\u3057\u3066\u3044\u305f\u308a\u3001\u30d7\u30ed\u30d1\u30c6\u30a3\u540d\u304c\u4e00\u81f4\u3057\u3066\u3044\u306a\u3044\u3068\u30d0\u30a4\u30f3\u30c9\u3055\u308c\u307e\u305b\u3093\u3002<\/p>\n<h3>@RequestParam \u306e\u4ed5\u7d44\u307f\u3068\u4f7f\u3044\u3069\u3053\u308d<\/h3>\n<p>\u5358\u4e00\u306e\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u53d7\u3051\u53d6\u308a\u305f\u3044\u3068\u304d\u306b\u4f7f\u3044\u307e\u3059\u3002\u305f\u3068\u3048\u3070\u691c\u7d22\u753b\u9762\u3084\u30da\u30fc\u30b8\u30f3\u30b0\u306a\u3069\u306b\u3002<\/p>\n<pre><code><span>@GetMapping<\/span>(<span>\"\/search\"<\/span>)\r\n<span>public<\/span> <span>String<\/span> search(<span>@RequestParam<\/span> <span>String<\/span> keyword) {\r\n    <span>\/\/ URL: \/search?keyword=hello<\/span>\r\n    <span>return<\/span> <span>\"result\"<\/span>;\r\n}<\/code><\/pre>\n<p><strong>\u30dd\u30a4\u30f3\u30c8<\/strong>\uff1a\u5fc5\u8981\u4ee5\u4e0a\u306b DTO \u306b\u30d0\u30a4\u30f3\u30c9\u3057\u306a\u304f\u3066\u3082\u3088\u3044\u5834\u9762\u3067\u306f @RequestParam \u304c\u4fbf\u5229\u3067\u3059\u3002<\/p>\n<h3>@RequestBody \u306e\u4ed5\u7d44\u307f\u3068\u4f7f\u3044\u3069\u3053\u308d<\/h3>\n<p>@RequestBody \u306f JSON \u3092\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u30d0\u30a4\u30f3\u30c9\u3059\u308b\u305f\u3081\u306b\u4f7f\u3044\u307e\u3059\u3002API \u958b\u767a\u3067\u306f\u6700\u3082\u4e00\u822c\u7684\u3067\u3059\u3002<\/p>\n<pre><code>@<span>PostMapping<\/span>(\"\/<span>api<\/span>\/<span>users<\/span>\")\r\npublic ResponseEntity&lt;?&gt; createUser(@RequestBody UserDto user) {\r\n    <span>return<\/span> <span>ResponseEntity<\/span><span>.ok<\/span>()<span>.build<\/span>();\r\n}<\/code><\/pre>\n<p><strong>\u30dd\u30a4\u30f3\u30c8<\/strong>\uff1a\u30ea\u30af\u30a8\u30b9\u30c8\u30d8\u30c3\u30c0\u30fc\u306b Content-Type: application\/json \u3092\u5fc5\u305a\u542b\u3081\u307e\u3057\u3087\u3046\u3002\u542b\u307e\u308c\u3066\u3044\u306a\u3044\u3068 @RequestBody \u304c\u6a5f\u80fd\u3057\u307e\u305b\u3093\u3002<\/p>\n<hr>\n<h2>\u3042\u308a\u304c\u3061\u306a\u3064\u307e\u305a\u304d\u3068\u3001\u6b63\u3057\u3044\u4f7f\u3044\u5206\u3051\u30d1\u30bf\u30fc\u30f3<\/h2>\n<h3>\u30b1\u30fc\u30b9 1\uff1aJSON \u3092\u9001\u3063\u3066\u308b\u306e\u306b @ModelAttribute \u3092\u4f7f\u3063\u3066\u3044\u308b\uff08Spring @ModelAttribute null\uff09<\/h3>\n<p><strong>NG \u4f8b\uff1a<\/strong><\/p>\n<pre><code><span>@PostMapping<\/span>(<span>\"\/api\/users\"<\/span>)\r\n<span>public<\/span> ResponseEntity&lt;?&gt; create(<span>@ModelAttribute<\/span> UserDto user) {\r\n    <span>return<\/span> ResponseEntity.ok().build(); <span>\/\/ user \u306f null<\/span>\r\n}<\/code><\/pre>\n<p><strong>\u6b63\u3057\u3044\u4f7f\u3044\u65b9\uff1a<\/strong><\/p>\n<pre><code>@<span>PostMapping<\/span>(\"\/<span>api<\/span>\/<span>users<\/span>\")\r\npublic ResponseEntity&lt;?&gt; create(@RequestBody UserDto user) {\r\n    <span>return<\/span> <span>ResponseEntity<\/span><span>.ok<\/span>()<span>.build<\/span>();\r\n}<\/code><\/pre>\n<h3>\u30b1\u30fc\u30b9 2\uff1aHTML \u30d5\u30a9\u30fc\u30e0\u306a\u306e\u306b @RequestBody \u3092\u4f7f\u3063\u3066\u3044\u308b\uff08Spring @RequestBody null\uff09<\/h3>\n<p><strong>NG \u4f8b\uff1a<\/strong><\/p>\n<pre><code><span>@PostMapping<\/span>(<span>\"\/register\"<\/span>)\r\n<span>public<\/span> <span>String<\/span> register(<span>@RequestBody<\/span> UserForm form) {\r\n    <span>return<\/span> <span>\"success\"<\/span>; <span>\/\/ 400 Bad Request<\/span>\r\n}<\/code><\/pre>\n<p><strong>\u6b63\u3057\u3044\u4f7f\u3044\u65b9\uff1a<\/strong><\/p>\n<pre><code><span>@PostMapping<\/span>(<span>\"\/register\"<\/span>)\r\n<span>public<\/span> <span>String<\/span> register(<span>@ModelAttribute<\/span> UserForm form) {\r\n    <span>return<\/span> <span>\"success\"<\/span>;\r\n}<\/code><\/pre>\n<h3>\u30b1\u30fc\u30b9 3\uff1a\u30af\u30a8\u30ea\u30d1\u30e9\u30e1\u30fc\u30bf\u3092 DTO \u306b\u30d0\u30a4\u30f3\u30c9\u3057\u3066\u3044\u308b<\/h3>\n<p><strong>NG \u4f8b\uff1a<\/strong><\/p>\n<pre><code><span>@GetMapping<\/span>(<span>\"\/search\"<\/span>)\r\n<span>public<\/span> <span>String<\/span> search(<span>@ModelAttribute<\/span> SearchForm form) {\r\n    <span>return<\/span> <span>\"result\"<\/span>;\r\n}<\/code><\/pre>\n<p><strong>\u6b63\u3057\u3044\u4f7f\u3044\u65b9\uff1a<\/strong><\/p>\n<pre><code><span>@GetMapping<\/span>(<span>\"\/search\"<\/span>)\r\n<span>public<\/span> <span>String<\/span> search(<span>@RequestParam<\/span> <span>String<\/span> keyword) {\r\n    <span>return<\/span> <span>\"result\"<\/span>;\r\n}<\/code><\/pre>\n<hr>\n<h2>\u3053\u306e\u8a18\u4e8b\u306e\u307e\u3068\u3081\u3068\u3001\u6b21\u306b\u5f79\u7acb\u3064\u77e5\u8b58<\/h2>\n<h3>\u25c6 \u8981\u70b9\u307e\u3068\u3081<\/h3>\n<ul>\n<li>\n<p>@ModelAttribute\uff1a\u30d5\u30a9\u30fc\u30e0\u9001\u4fe1\uff08HTML\uff09\u5411\u3051<\/p>\n<\/li>\n<li>\n<p>@RequestParam\uff1aURL \u30af\u30a8\u30ea\u3084\u5358\u4f53\u306e\u5024\u5411\u3051<\/p>\n<\/li>\n<li>\n<p>@RequestBody\uff1aJSON \u3092\u4f7f\u3046 API \u5411\u3051<\/p>\n<\/li>\n<li>\n<p>\u9001\u4fe1\u5f62\u5f0f\u3068\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u306e\u6574\u5408\u6027\u304c\u8d85\u91cd\u8981<\/p>\n<\/li>\n<\/ul>\n<h3>\u25c6 \u6b21\u306b\u5b66\u3076\u3068\u5f79\u7acb\u3064\u30c8\u30d4\u30c3\u30af<\/h3>\n<ul>\n<li>\n<p>@Valid \u3068 BindingResult \u306e\u4f7f\u3044\u65b9<\/p>\n<\/li>\n<li>\n<p>@RequestPart \u306b\u3088\u308b\u30d5\u30a1\u30a4\u30eb\u53d7\u4fe1<\/p>\n<\/li>\n<li>\n<p>Spring Security \u306b\u304a\u3051\u308b CSRF \u8a2d\u5b9a\u3068 JSON API \u306e\u76f8\u6027<\/p>\n<\/li>\n<\/ul>\n<p>\u3053\u306e\u3088\u3046\u306a\u77e5\u8b58\u3092\u7a4d\u307f\u4e0a\u3052\u3066\u3044\u304f\u3053\u3068\u3067\u3001\u3088\u308a\u5805\u7262\u3067\u7406\u89e3\u3057\u3084\u3059\u3044 Web API \u304c\u4f5c\u308c\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u73fe\u5834\u5fd7\u5411\u306e\u30a8\u30f3\u30b8\u30cb\u30a2\u304c\u3001\u4eca\u65e5\u306e\u60a9\u307f\u3092\u660e\u65e5\u306e\u6b66\u5668\u306b\u5909\u3048\u3089\u308c\u308b\u3088\u3046\u3001\u4eca\u5f8c\u3082\u5f79\u7acb\u3064\u6280\u8853\u8a18\u4e8b\u3092\u5c4a\u3051\u3066\u3044\u304d\u307e\u3059\u3002\u307e\u305f\u8aad\u307f\u306b\u6765\u3066\u304f\u3060\u3055\u3044\u306d\uff01<\/p>\n<h3>\u3010\u5916\u90e8\u30ea\u30f3\u30af\u3011<\/h3>\n<p><a href=\"https:\/\/spring.io\/projects\/spring-boot\">Spring Boot\u516c\u5f0f\u30b5\u30a4\u30c8<\/a><\/p>\n<p><a href=\"https:\/\/spring.io\/guides\/gs\/serving-web-content\/\">Spring Framework\u516c\u5f0f\u30ac\u30a4\u30c9 \u2013 Spring MVC<\/a><\/p>\n<h3>\u3010\u5185\u90e8\u30ea\u30f3\u30af\u3011<\/h3>\n<p><a href=\"https:\/\/route-zero.com\/recruit\/route\/1100\/\">\u3010Spring Boot\u5b9f\u8df5\u30ac\u30a4\u30c9\u3011List\u578b\u30fbMap\u578b\u306e\u9055\u3044\u3068Bean\u30af\u30e9\u30b9\u306e\u57fa\u790e\uff06\u5fdc\u7528<\/a><\/p>\n<p><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><\/p>\n<p><a href=\"https:\/\/route-zero.com\/recruit\/route\/1299\/\">Spring Boot\u3067\u7406\u89e3\u3059\u308bGET\u3068POST\u306e\u9055\u3044\uff5cThymeleaf\u5b9f\u88c5\u4f8b\u4ed8\u304d\u3067\u521d\u5fc3\u8005\u306e\u753b\u9762\u9077\u79fb\u30fb\u30a8\u30e9\u30fc\u5bfe\u5fdc\u307e\u3067\u4e01\u5be7\u89e3\u8aac<\/a><\/p>\n<p><a href=\"https:\/\/route-zero.com\/recruit\/route\/1104\/\">Spring Boot\u306e\u3088\u304f\u4f7f\u308f\u308c\u308b\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u3068\u306f\uff1f\u521d\u5fc3\u8005\u5fc5\u898b\u306e\u89e3\u8aac\u3068\u6d3b\u7528\u6cd5<\/a><\/p>\n<p><a href=\"https:\/\/route-zero.com\/recruit\/route\/1269\/\">MVC\u69cb\u6210\u3092\u7406\u89e3\u3059\u308c\u3070\u73fe\u5834\u3067\u8a70\u307e\u3089\u306a\u3044 | Spring Boot\u5b9f\u88c5\u30ac\u30a4\u30c9<\/a><\/p>\n<\/div>\n","protected":false},"featured_media":1337,"template":"","_links":{"self":[{"href":"https:\/\/route-zero.com\/recruit\/wp-json\/wp\/v2\/route\/1336"}],"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\/1337"}],"wp:attachment":[{"href":"https:\/\/route-zero.com\/recruit\/wp-json\/wp\/v2\/media?parent=1336"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}