{"id":168,"date":"2019-06-18T10:37:28","date_gmt":"2019-06-18T01:37:28","guid":{"rendered":"http:\/\/2019se3.satoshis.jp\/?p=168"},"modified":"2019-06-18T13:01:44","modified_gmt":"2019-06-18T04:01:44","slug":"6%e6%9c%8818%e6%97%a5","status":"publish","type":"post","link":"https:\/\/2019se3.satoshis.jp\/?p=168","title":{"rendered":"6\u670818\u65e5"},"content":{"rendered":"<h3>MyData\u306e\u66f4\u65b0<\/h3>\n<p>MyData\u3092\u66f4\u65b0\u3059\u308b\u6a5f\u80fd\u3092\u8ffd\u52a0\u3059\u308b\u3002<br \/>\n\u307e\u305a\u3001HTML\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3068\u3057\u3066 edit.html \u3092\u7528\u610f\u3057\u305f\uff08\u524d\u56de\uff09\u3002<\/p>\n<p>\u6b21\u306b\u30ea\u30dd\u30b8\u30c8\u30ea\u306b findById() \u30e1\u30bd\u30c3\u30c9\u3092\u8ffd\u52a0\u3059\u308b\u3002<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\npackage jp.abc.repositories;\r\n\r\nimport java.util.Optional;\r\n\r\nimport org.springframework.data.jpa.repository.JpaRepository;\r\nimport org.springframework.stereotype.Repository;\r\n\r\nimport jp.abc.MyData;\r\n\r\n@Repository\r\npublic interface MyDataRepository extends JpaRepository&lt;MyData, Long&gt; {\r\n\tpublic Optional&lt;MyData&gt; findById(Long id);\r\n}\r\n<\/pre>\n<p>\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u306b URL \/edit\/ \u3092\u53d7\u3051\u4ed8\u3051\u308b\u30e1\u30bd\u30c3\u30c9\u3092\u8ffd\u52a0\u3059\u308b\u3002<\/p>\n<pre class=\"brush: java; first-line: 43; title: ; notranslate\" title=\"\">\r\n\t@RequestMapping(value = &quot;\/edit\/{id}&quot;, method = RequestMethod.GET)\r\n\tpublic ModelAndView edit(@ModelAttribute MyData mydata,\r\n\t\t\t@PathVariable int id,\r\n\t\t\tModelAndView mav) {\r\n\t\tmav.setViewName(&quot;edit&quot;);\r\n\t\tmav.addObject(&quot;title&quot;, &quot;edit mydata&quot;);\r\n\t\tOptional&lt;MyData&gt; data = repository.findById((long)id);\r\n\t\tmav.addObject(&quot;formModel&quot;, data.get());\r\n\t\treturn mav;\r\n\t}\r\n\r\n\t@RequestMapping(value = &quot;\/edit\/{id}&quot;, method = RequestMethod.POST)\r\n\t@Transactional(readOnly = false)\r\n\tpublic ModelAndView update(@ModelAttribute MyData mydata,\r\n\t\t\tModelAndView mav) {\r\n\t\trepository.saveAndFlush(mydata);\r\n\t\treturn new ModelAndView(&quot;redirect:\/mydata&quot;);\r\n\t}\r\n<\/pre>\n<h3>\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u306e\u524a\u9664<\/h3>\n<p>HTML\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8 delete.html \u3092\u8ffd\u52a0\u3059\u308b\u3002<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;!DOCTYPE html&gt;\r\n&lt;html xmlns:th=&quot;http:\/\/www.thymeleaf.org&quot;&gt;\r\n&lt;head&gt;\r\n&lt;meta charset=&quot;UTF-8&quot;&gt;\r\n&lt;title&gt;top page&lt;\/title&gt;\r\n&lt;meta http-equiv=&quot;Content-type&quot; content=&quot;text\/html; charset=UTF-8&quot; \/&gt;\r\n&lt;style type=&quot;text\/css&quot;&gt;\r\nh1 {\r\n  font-size: 18pt;\r\n  font-weight: bold;\r\n  color: gray;\r\n}\r\nbody {\r\n  font-size: 13pt;\r\n  color: gray;\r\n  margin: 5px 25px;\r\n}\r\npre {\r\n  border: solid 3px #ddd;\r\n  padding: 10px;\r\n}\r\ntr {\r\n  margin: 5px;\r\n}\r\nth {\r\n  padding: 5px;\r\n  color: white;\r\n  background: darkgray;\r\n}\r\ntd {\r\n  padding: 5px;\r\n  color: black;\r\n  background: #f0f0f0;\r\n}\r\n&lt;\/style&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n\r\n&lt;h1&gt;MyData delete page&lt;\/h1&gt;\r\n\r\n&lt;form method=&quot;post&quot; action=&quot;\/delete&quot; th:object=&quot;${formModel}&quot;&gt;\r\n  &lt;input type=&quot;hidden&quot; name=&quot;id&quot; th:value=&quot;*{id}&quot; \/&gt;\r\n  &lt;table&gt;\r\n    &lt;tr&gt;&lt;td&gt;&lt;p th:text=&quot;|\u540d\u524d : *{name}|&quot;&gt;&lt;\/p&gt;&lt;\/td&gt;&lt;\/tr&gt;\r\n    &lt;tr&gt;&lt;td&gt;&lt;p th:text=&quot;|\u5e74\u9f62 : *{age}|&quot;&gt;&lt;\/p&gt;&lt;\/td&gt;&lt;\/tr&gt;\r\n    &lt;tr&gt;&lt;td&gt;&lt;p th:text=&quot;*{mail}&quot;&gt;&lt;\/p&gt;&lt;\/td&gt;&lt;\/tr&gt;\r\n    &lt;tr&gt;&lt;td&gt;&lt;p th:text=&quot;*{memo}&quot;&gt;&lt;\/p&gt;&lt;\/td&gt;&lt;\/tr&gt;\r\n    &lt;tr&gt;&lt;td&gt;&lt;input type=&quot;submit&quot; value=&quot;\u524a\u9664&quot; \/&gt;&lt;\/td&gt;&lt;\/tr&gt;\r\n  &lt;\/table&gt;\r\n&lt;\/form&gt;\r\n\r\n\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<p>\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u306b\u3001\u524a\u9664\u95a2\u9023\u306e\u30ea\u30af\u30a8\u30b9\u30c8\u3092\u53d7\u3051\u53d6\u308b\u30e1\u30bd\u30c3\u30c9\u3092\u8ffd\u52a0\u3059\u308b\u3002<\/p>\n<pre class=\"brush: java; first-line: 64; title: ; notranslate\" title=\"\">\r\n\t@RequestMapping(value = &quot;\/delete\/{id}&quot;, method = RequestMethod.GET)\r\n\tpublic ModelAndView delete(@PathVariable int id,\r\n\t\t\tModelAndView mav) {\r\n\t\tmav.setViewName(&quot;delete&quot;);\r\n\t\tmav.addObject(&quot;title&quot;, &quot;delete mydata&quot;);\r\n\t\tOptional&lt;MyData&gt; data = repository.findById((long)id);\r\n\t\tmav.addObject(&quot;formModel&quot;, data.get());\r\n\t\treturn mav;\r\n\t}\r\n\r\n\t@RequestMapping(value = &quot;\/delete&quot;, method = RequestMethod.POST)\r\n\t@Transactional(readOnly = false)\r\n\tpublic ModelAndView remove(@RequestParam long id,\r\n\t\t\tModelAndView mav) {\r\n\t\trepository.deleteById(id);\r\n\t\treturn new ModelAndView(&quot;redirect:\/mydata&quot;);\r\n\t}\r\n<\/pre>\n<h3>\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u306e\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3<\/h3>\n<p>\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u306f\u3001\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u306e\u30d5\u30a3\u30fc\u30eb\u30c9\u306b\u30a2\u30ce\u30c6\u30fc\u30b7\u30e7\u30f3\u3092\u8ffd\u52a0\u3059\u308b\u3053\u3068\u3067\u5165\u529b\u5024\u306e\u5236\u9650\u304c\u3067\u304d\u308b\u3002<\/p>\n<pre class=\"brush: java; highlight: [20,24,28,32,33]; title: ; notranslate\" title=\"\">\r\npackage jp.abc;\r\n\r\nimport javax.persistence.Column;\r\nimport javax.persistence.Entity;\r\nimport javax.persistence.GeneratedValue;\r\nimport javax.persistence.GenerationType;\r\nimport javax.persistence.Id;\r\nimport javax.validation.constraints.Email;\r\nimport javax.validation.constraints.Max;\r\nimport javax.validation.constraints.Min;\r\nimport javax.validation.constraints.NotEmpty;\r\nimport javax.validation.constraints.NotNull;\r\n\r\n\r\n@Entity\r\npublic class MyData {\r\n\t@Id\r\n\t@GeneratedValue(strategy = GenerationType.AUTO)\r\n\t@Column\r\n\t@NotNull\r\n\tprivate long id;\r\n\r\n\t@Column(length = 50, nullable = false)\r\n\t@NotEmpty\r\n\tprivate String name;\r\n\r\n\t@Column(length = 200, nullable = true)\r\n\t@Email\r\n\tprivate String mail;\r\n\r\n\t@Column(nullable = true)\r\n\t@Min(0)\r\n\t@Max(200)\r\n\tprivate Integer age;\r\n\r\n\t@Column(nullable = true)\r\n\tprivate String memo;\r\n\r\n\tpublic long getId() {\r\n\t\treturn id;\r\n\t}\r\n\r\n\tpublic void setId(long id) {\r\n\t\tthis.id = id;\r\n\t}\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 String getMail() {\r\n\t\treturn mail;\r\n\t}\r\n\r\n\tpublic void setMail(String mail) {\r\n\t\tthis.mail = mail;\r\n\t}\r\n\r\n\tpublic Integer getAge() {\r\n\t\treturn age;\r\n\t}\r\n\r\n\tpublic void setAge(Integer age) {\r\n\t\tthis.age = age;\r\n\t}\r\n\r\n\tpublic String getMemo() {\r\n\t\treturn memo;\r\n\t}\r\n\r\n\tpublic void setMemo(String memo) {\r\n\t\tthis.memo = memo;\r\n\t}\r\n\r\n}\r\n<\/pre>\n<p>\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u306e\u5f15\u6570\u3067\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u306e\u7d50\u679c\u3092\u53d7\u3051\u53d6\u308b\u3002<\/p>\n<pre class=\"brush: java; first-line: 39; highlight: [41,42,44]; title: ; notranslate\" title=\"\">\r\n\t@RequestMapping(value = &quot;\/mydata&quot;, method = RequestMethod.POST)\r\n\tpublic ModelAndView form(\r\n\t\t\t@ModelAttribute(&quot;formModel&quot;) @Validated MyData mydata,\r\n\t\t\tBindingResult result,\r\n\t\t\tModelAndView mav) {\r\n\t\tif (!result.hasErrors()) {\r\n\t\t\trepository.saveAndFlush(mydata);\r\n\t\t\treturn new ModelAndView(&quot;redirect:\/mydata&quot;);\r\n\t\t}\r\n\t\tmav.setViewName(&quot;mydata&quot;);\r\n\t\tmav.addObject(&quot;msg&quot;, &quot;sorry, error is occured...&quot;);\r\n\t\tIterable&lt;MyData&gt; list = repository.findAll();\r\n\t\tmav.addObject(&quot;datalist&quot;, list);\r\n\t\treturn mav;\r\n\t}\r\n<\/pre>\n<p>HTML\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3067\u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u8868\u793a\u3059\u308b\u3002<\/p>\n<pre class=\"brush: xml; first-line: 30; highlight: [35,36,37,43,45,46,47,48]; title: ; notranslate\" title=\"\">\r\ntd {\r\n  padding: 5px;\r\n  color: black;\r\n  background: #f0f0f0;\r\n}\r\n.err {\r\n  color: red;\r\n}\r\n&lt;\/style&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n\r\n&lt;h1&gt;MyData page&lt;\/h1&gt;\r\n&lt;p th:text=&quot;${msg}&quot;&gt;&lt;\/p&gt;\r\n&lt;form method=&quot;post&quot; action=&quot;\/mydata&quot; th:object=&quot;${formModel}&quot;&gt;\r\n&lt;ul&gt;\r\n  &lt;li th:each=&quot;error : ${#fields.detailedErrors()}&quot; class=&quot;err&quot;\r\n      th:text=&quot;${error.message}&quot; \/&gt;\r\n&lt;\/ul&gt;\r\n  &lt;table&gt;\r\n    &lt;tr&gt;\r\n      &lt;td&gt;&lt;label for=&quot;name&quot;&gt;\u540d\u524d&lt;\/label&gt;&lt;\/td&gt;\r\n      &lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;name&quot; th:value=&quot;*{name}&quot; \/&gt;&lt;\/td&gt;\r\n    &lt;\/tr&gt;\r\n<\/pre>\n\n<div style=\"font-size: 0px; height: 0px; line-height: 0px; margin: 0; padding: 0; clear: both;\"><\/div>","protected":false},"excerpt":{"rendered":"<p>MyData\u306e\u66f4\u65b0 MyData\u3092\u66f4\u65b0\u3059\u308b\u6a5f\u80fd\u3092\u8ffd\u52a0\u3059\u308b\u3002 \u307e\u305a\u3001HTML\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3068\u3057\u3066 edit.html \u3092\u7528\u610f\u3057\u305f\uff08\u524d\u56de\uff09\u3002 \u6b21\u306b\u30ea\u30dd\u30b8\u30c8\u30ea\u306b findById() \u30e1\u30bd\u30c3\u30c9\u3092\u8ffd\u52a0\u3059\u308b\u3002 \u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u306b URL &hellip; <a href=\"https:\/\/2019se3.satoshis.jp\/?p=168\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;6\u670818\u65e5&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[],"_links":{"self":[{"href":"https:\/\/2019se3.satoshis.jp\/index.php?rest_route=\/wp\/v2\/posts\/168"}],"collection":[{"href":"https:\/\/2019se3.satoshis.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/2019se3.satoshis.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/2019se3.satoshis.jp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/2019se3.satoshis.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=168"}],"version-history":[{"count":6,"href":"https:\/\/2019se3.satoshis.jp\/index.php?rest_route=\/wp\/v2\/posts\/168\/revisions"}],"predecessor-version":[{"id":175,"href":"https:\/\/2019se3.satoshis.jp\/index.php?rest_route=\/wp\/v2\/posts\/168\/revisions\/175"}],"wp:attachment":[{"href":"https:\/\/2019se3.satoshis.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=168"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/2019se3.satoshis.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=168"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/2019se3.satoshis.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=168"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}