{"id":79,"date":"2020-11-12T15:16:54","date_gmt":"2020-11-12T06:16:54","guid":{"rendered":"http:\/\/kpc2020.satoshis.jp\/?p=79"},"modified":"2020-11-26T14:56:24","modified_gmt":"2020-11-26T05:56:24","slug":"bookshelf%e3%82%a2%e3%83%97%e3%83%aa%e3%82%92%e4%bd%9c%e6%88%90%e3%81%99%e3%82%8b","status":"publish","type":"post","link":"https:\/\/kpc2020.satoshis.jp\/?p=79","title":{"rendered":"Bookshelf\u30a2\u30d7\u30ea\u3092\u4f5c\u6210\u3059\u308b"},"content":{"rendered":"<p>\u65b0\u898f\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\u3059\u308b\u3002<br \/>\n\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u7a2e\u985e\u306f\u3001Spring\u30b9\u30bf\u30fc\u30bf\u30fc\u30fb\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u9078\u629e\u3059\u308b\u3002<\/p>\n<p>\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u540d\u3092\u300cbookshelf\u300d\u306b\u3057\u3066\u6b21\u3078\u3092\u30af\u30ea\u30c3\u30af\u3002<\/p>\n<p>\u4f9d\u5b58\u95a2\u4fc2\u306f\u3001\u4ee5\u4e0b\u306e\u9805\u76ee\u3092\u9078\u629e\u3059\u308b\u3002<\/p>\n<ul>\n<li>HyperSQL Database<\/li>\n<li>Spring Data JPA<\/li>\n<li>Spring Web<\/li>\n<li>Thymeleaf<\/li>\n<\/ul>\n<p>\u300c\u5b8c\u4e86\u300d\u3067bookshelf\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u304c\u3067\u304d\u308b\u3002<\/p>\n<p>pom.xml \u3092\u958b\u3044\u3066\u30018\u884c\u76ee\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u30922.2.1\u306b\u4fee\u6b63\u3059\u308b\u3002<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n\t\t&lt;version&gt;2.2.1.RELEASE&lt;\/version&gt;\r\n<\/pre>\n<p>[\u5b9f\u884c]-[Spring Boot \u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3]\u3092\u9078\u629e\u3059\u308b\u3068\u30b5\u30fc\u30d0\u30fc\u304c\u8d77\u52d5\u3059\u308b\u3002<\/p>\n<p>http:\/\/localhost:8080 \u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3068\u3001Whitelabel Error Page \u304c\u8868\u793a\u3055\u308c\u308b\u3002<\/p>\n<p>IndexControler.java \u3092\u4f5c\u6210\u3059\u308b\u3002<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\npackage jp.kpc;\r\n\r\nimport org.springframework.stereotype.Controller;\r\nimport org.springframework.web.bind.annotation.RequestMapping;\r\n\r\n@Controller\r\npublic class IndexController {\r\n\r\n\t@RequestMapping(&quot;\/&quot;)\r\n\tpublic String index() {\r\n\t\treturn &quot;index&quot;;\r\n\t}\r\n\r\n}\r\n<\/pre>\n<p>example \u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e index.html \u3092\u30b3\u30d4\u30fc\u3057\u3066\u3001src\/main\/resources \u306e templates \u306b\u8cbc\u308a\u4ed8\u3051\u308b\u3002<\/p>\n<p>SpringBoot\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u518d\u8d77\u52d5\u3059\u308b\u3068\u3001\u300c\u6700\u521d\u306e\u30da\u30fc\u30b8\u300d\u304c\u8868\u793a\u3055\u308c\u308b\u3002<\/p>\n<p>application.properties \u306b\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u63a5\u7d9a\u8a2d\u5b9a\u3092\u8ffd\u52a0\u3059\u308b\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nspring.datasource.url=jdbc:hsqldb:hsql:\/\/localhost\/bookshelf\r\nspring.datasource.username=SA\r\nspring.datasource.password=\r\nspring.datasource.driver-class-name=org.hsqldb.jdbc.JDBCDriver\r\nspring.jpa.hibernate.ddl-auto=update\r\n<\/pre>\n<p>hsqldb.bat \u306b bookshelf \u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u8ffd\u52a0\u3059\u308b\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\ncd data\r\njava -classpath ..\/lib\/hsqldb.jar org.hsqldb.server.Server ^\r\n--database.0 db\/shindan --dbname.0 shindan ^\r\n--database.1 db\/bookshelf --dbname.1 bookshelf\r\n<\/pre>\n<p>index.html \u306b\u3001\u65b0\u3057\u3044\u672c\u68da\u3092\u8ffd\u52a0\u3059\u308b\u305f\u3081\u306e\u30d5\u30a9\u30fc\u30e0\u3092\u7528\u610f\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;Bookshelf - \u672c\u68da&lt;\/title&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n\r\n&lt;h1&gt;Bookshelf list&lt;\/h1&gt;\r\n\r\n&lt;hr \/&gt;\r\n\r\n&lt;div&gt;\u65b0\u3057\u3044\u672c\u68da&lt;\/div&gt;\r\n&lt;form action=&quot;\/addshelf&quot; method=&quot;post&quot;&gt;\r\n\t&lt;div&gt;\u306a\u307e\u3048&lt;\/div&gt;\r\n\t&lt;div&gt;&lt;input type=&quot;text&quot; name=&quot;name&quot; \/&gt;&lt;\/div&gt;\r\n\t&lt;div&gt;&lt;input id=&quot;submit&quot; type=&quot;submit&quot; value=&quot;+\u8ffd\u52a0&quot; \/&gt;&lt;\/div&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>IndexController.java \u306b \/addshelf \u306b\u5bfe\u3059\u308b POST \u3092\u53d7\u3051\u53d6\u308b\u7528\u610f\u3092\u3059\u308b\u3002POST\u3092\u53d7\u3051\u53d6\u3063\u305f\u3042\u3068\u306f\u3001URL=&#8221;\/&#8221; \u306b\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u3059\u308b\u3002<\/p>\n<pre class=\"brush: java; highlight: [17,18,19,20,21]; title: ; notranslate\" title=\"\">\r\npackage jp.kpc;\r\n\r\nimport org.springframework.stereotype.Controller;\r\nimport org.springframework.web.bind.annotation.RequestMapping;\r\nimport org.springframework.web.bind.annotation.RequestMethod;\r\nimport org.springframework.web.bind.annotation.RequestParam;\r\nimport org.springframework.web.servlet.ModelAndView;\r\n\r\n@Controller\r\npublic class IndexController {\r\n\r\n\t@RequestMapping(&quot;\/&quot;)\r\n\tpublic String index() {\r\n\t\treturn &quot;index&quot;;\r\n\t}\r\n\r\n\t@RequestMapping(value=&quot;\/addshelf&quot;, method=RequestMethod.POST)\r\n\tpublic ModelAndView formPost(ModelAndView mav,\r\n\t\t\t@RequestParam(&quot;name&quot;) String name) {\r\n\t\treturn new ModelAndView(&quot;redirect:\/&quot;);\r\n\t}\r\n}\r\n<\/pre>\n<p>\u672c\u68da\u306b\u5bfe\u5fdc\u3059\u308b Bookshelf \u30af\u30e9\u30b9\u3092\u4f5c\u6210\u3059\u308b\u3002<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\npackage jp.kpc;\r\n\r\nimport javax.persistence.Column;\r\nimport javax.persistence.Entity;\r\nimport javax.persistence.GeneratedValue;\r\nimport javax.persistence.Id;\r\nimport javax.validation.constraints.NotEmpty;\r\nimport javax.validation.constraints.NotNull;\r\n\r\n@Entity\r\npublic class Bookshelf {\r\n\t@Id\r\n\t@GeneratedValue\r\n\t@Column\r\n\t@NotNull\r\n\tprivate long id;\r\n\r\n\t@Column\r\n\t@NotEmpty\r\n\tprivate String name;\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}\r\n<\/pre>\n<p>\u65b0\u898f\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u3092\u4f5c\u6210\u3059\u308b\u3002<br \/>\nBookshelfRepository.java<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\npackage jp.kpc;\r\n\r\nimport org.springframework.data.jpa.repository.JpaRepository;\r\n\r\npublic interface BookshelfRepository extends JpaRepository&lt;Bookshelf, Long&gt; {\r\n\r\n}\r\n<\/pre>\n<p>IndexController.java \u3067\u3001\u30ea\u30af\u30a8\u30b9\u30c8\u30d1\u30e9\u30e1\u30fc\u30bf\u3067\u6e21\u3055\u308c\u305f\u540d\u524d\u306e\u672c\u68da\u3092\u4fdd\u5b58\u3059\u308b\u51e6\u7406\u3092\u8ffd\u52a0\u3059\u308b\u3002<\/p>\n<pre class=\"brush: java; highlight: [13,14,24,25,26]; title: ; notranslate\" title=\"\">\r\npackage jp.kpc;\r\n\r\nimport org.springframework.beans.factory.annotation.Autowired;\r\nimport org.springframework.stereotype.Controller;\r\nimport org.springframework.web.bind.annotation.RequestMapping;\r\nimport org.springframework.web.bind.annotation.RequestMethod;\r\nimport org.springframework.web.bind.annotation.RequestParam;\r\nimport org.springframework.web.servlet.ModelAndView;\r\n\r\n@Controller\r\npublic class IndexController {\r\n\r\n\t@Autowired\r\n\tprivate BookshelfRepository repository;\r\n\r\n\t@RequestMapping(&quot;\/&quot;)\r\n\tpublic String index() {\r\n\t\treturn &quot;index&quot;;\r\n\t}\r\n\r\n\t@RequestMapping(value=&quot;\/addshelf&quot;, method=RequestMethod.POST)\r\n\tpublic ModelAndView formPost(ModelAndView mav,\r\n\t\t\t@RequestParam(&quot;name&quot;) String name) {\r\n\t\tBookshelf bookshelf = new Bookshelf();\r\n\t\tbookshelf.setName(name);\r\n\t\trepository.saveAndFlush(bookshelf);\r\n\t\treturn new ModelAndView(&quot;redirect:\/&quot;);\r\n\t}\r\n}\r\n<\/pre>\n<p>\u30c8\u30c3\u30d7\u30da\u30fc\u30b8\u306b\u30a2\u30af\u30bb\u30b9\u304c\u3042\u3063\u305f\u3068\u304d\u306b\u3001\u672c\u68da\u30ea\u30b9\u30c8\u3092\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u306b\u6e21\u3059\u3002<\/p>\n<p>IndexController.java<\/p>\n<pre class=\"brush: java; first-line: 12; highlight: [19,20,21,22,23]; title: ; notranslate\" title=\"\">\r\n@Controller\r\npublic class IndexController {\r\n\r\n\t@Autowired\r\n\tprivate BookshelfRepository repository;\r\n\r\n\t@RequestMapping(&quot;\/&quot;)\r\n\tpublic ModelAndView index(ModelAndView mav) {\r\n\t\tmav.setViewName(&quot;index&quot;);\r\n\t\tList&lt;Bookshelf&gt; list = repository.findAll();\r\n\t\tmav.addObject(&quot;list&quot;, list);\r\n\t\treturn mav;\r\n\t}\r\n<\/pre>\n<p>\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3067\u672c\u68da\u306e\u30ea\u30b9\u30c8\u3092\u8868\u793a\u3059\u308b\u3002<\/p>\n<p>index.html<\/p>\n<pre class=\"brush: xml; highlight: [10,11,12,13,14]; 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;Bookshelf - \u672c\u68da&lt;\/title&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n\r\n&lt;h1&gt;Bookshelf list&lt;\/h1&gt;\r\n&lt;table&gt;\r\n\t&lt;tr th:each=&quot;bs : ${list}&quot;&gt;\r\n\t\t&lt;td th:text=&quot;${bs.name}&quot;&gt;&lt;\/td&gt;\r\n\t&lt;\/tr&gt;\r\n&lt;\/table&gt;\r\n\r\n&lt;hr \/&gt;\r\n\r\n&lt;div&gt;\u65b0\u3057\u3044\u672c\u68da&lt;\/div&gt;\r\n&lt;form action=&quot;\/addshelf&quot; method=&quot;post&quot;&gt;\r\n\t&lt;div&gt;\u306a\u307e\u3048&lt;\/div&gt;\r\n\t&lt;div&gt;&lt;input type=&quot;text&quot; name=&quot;name&quot; \/&gt;&lt;\/div&gt;\r\n\t&lt;div&gt;&lt;input id=&quot;submit&quot; type=&quot;submit&quot; value=&quot;+\u8ffd\u52a0&quot; \/&gt;&lt;\/div&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>Book\u30af\u30e9\u30b9\u3092\u4f5c\u6210\u3059\u308b\u3002<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\npackage jp.kpc;\r\n\r\nimport javax.persistence.Column;\r\nimport javax.persistence.Entity;\r\nimport javax.persistence.GeneratedValue;\r\nimport javax.persistence.Id;\r\nimport javax.validation.constraints.NotEmpty;\r\nimport javax.validation.constraints.NotNull;\r\n\r\n@Entity\r\npublic class Book {\r\n\t@Id\r\n\t@GeneratedValue\r\n\t@Column\r\n\t@NotNull\r\n\tprivate long id;\r\n\r\n\t@Column\r\n\t@NotEmpty\r\n\tprivate String title;\r\n\r\n\t@Column\r\n\t@NotEmpty\r\n\tprivate String author;\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 getTitle() {\r\n\t\treturn title;\r\n\t}\r\n\r\n\tpublic void setTitle(String title) {\r\n\t\tthis.title = title;\r\n\t}\r\n\r\n\tpublic String getAuthor() {\r\n\t\treturn author;\r\n\t}\r\n\r\n\tpublic void setAuthor(String author) {\r\n\t\tthis.author = author;\r\n\t}\r\n\r\n\r\n}\r\n<\/pre>\n<p>BookController.java<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\npackage jp.kpc;\r\n\r\nimport org.springframework.stereotype.Controller;\r\nimport org.springframework.web.bind.annotation.RequestMapping;\r\nimport org.springframework.web.servlet.ModelAndView;\r\n\r\n@Controller\r\npublic class BookController {\r\n\t@RequestMapping(&quot;\/books&quot;)\r\n\tpublic ModelAndView index(ModelAndView mav) {\r\n\t\tmav.setViewName(&quot;books&quot;);\r\n\t\treturn mav;\r\n\t}\r\n\r\n}\r\n<\/pre>\n<p>books.html<\/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;Book - \u672c\u306e\u30ea\u30b9\u30c8&lt;\/title&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n\r\n&lt;h1&gt;Book list&lt;\/h1&gt;\r\n&lt;table&gt;\r\n\t&lt;tr th:each=&quot;book : ${list}&quot;&gt;\r\n\t\t&lt;td th:text=&quot;${book.title}&quot;&gt;&lt;\/td&gt;\r\n\t\t&lt;td th:text=&quot;${book.author}&quot;&gt;&lt;\/td&gt;\r\n\t&lt;\/tr&gt;\r\n&lt;\/table&gt;\r\n\r\n&lt;hr \/&gt;\r\n\r\n&lt;div&gt;\u65b0\u3057\u3044\u672c&lt;\/div&gt;\r\n&lt;form action=&quot;\/addbook&quot; method=&quot;post&quot;&gt;\r\n\t&lt;div&gt;\u30bf\u30a4\u30c8\u30eb: &lt;input type=&quot;text&quot; name=&quot;title&quot; \/&gt;&lt;\/div&gt;\r\n\t&lt;div&gt;\u8457\u8005: &lt;input type=&quot;text&quot; name=&quot;author&quot; \/&gt;&lt;\/div&gt;\r\n\t&lt;div&gt;&lt;input id=&quot;submit&quot; type=&quot;submit&quot; value=&quot;+\u8ffd\u52a0&quot; \/&gt;&lt;\/div&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>BookRepository.java<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\npackage jp.kpc;\r\n\r\nimport org.springframework.data.jpa.repository.JpaRepository;\r\n\r\npublic interface BookRepository extends JpaRepository&lt;Book, Long&gt; {\r\n\r\n}\r\n<\/pre>\n<p>\u30ea\u30dd\u30b8\u30c8\u30ea\u3092\u7528\u610f\u3057\u305f\u306e\u3067\u3001\u305d\u308c\u3092BookController\u3067\u4f7f\u3046\u3002<\/p>\n<pre class=\"brush: java; highlight: [14,15,20,21,32]; title: ; notranslate\" title=\"\">\r\npackage jp.kpc;\r\n\r\nimport java.util.List;\r\n\r\nimport org.springframework.beans.factory.annotation.Autowired;\r\nimport org.springframework.stereotype.Controller;\r\nimport org.springframework.web.bind.annotation.RequestMapping;\r\nimport org.springframework.web.bind.annotation.RequestMethod;\r\nimport org.springframework.web.bind.annotation.RequestParam;\r\nimport org.springframework.web.servlet.ModelAndView;\r\n\r\n@Controller\r\npublic class BookController {\r\n\t@Autowired\r\n\tprivate BookRepository repository;\r\n\r\n\t@RequestMapping(&quot;\/books&quot;)\r\n\tpublic ModelAndView index(ModelAndView mav) {\r\n\t\tmav.setViewName(&quot;books&quot;);\r\n\t\tList&lt;Book&gt; list = repository.findAll();\r\n\t\tmav.addObject(&quot;list&quot;, list);\r\n\t\treturn mav;\r\n\t}\r\n\r\n\t@RequestMapping(value=&quot;\/addbook&quot;, method=RequestMethod.POST)\r\n\tpublic ModelAndView formPost(ModelAndView mav,\r\n\t\t\t@RequestParam(&quot;title&quot;) String title,\r\n\t\t\t@RequestParam(&quot;author&quot;) String author) {\r\n\t\tBook book = new Book();\r\n\t\tbook.setTitle(title);\r\n\t\tbook.setAuthor(author);\r\n\t\trepository.saveAndFlush(book);\r\n\t\treturn new ModelAndView(&quot;redirect:\/books&quot;);\r\n\t}\r\n}\r\n<\/pre>\n<p>\u672c\u3068\u672c\u68da\u306e\u95a2\u9023\u4ed8\u3051\u3092\u4f5c\u308b\u3002<\/p>\n<p>Bookshelf.java<\/p>\n<pre class=\"brush: java; highlight: [25,26,44,45,46,47,48,49,50]; title: ; notranslate\" title=\"\">\r\npackage jp.kpc;\r\n\r\nimport java.util.List;\r\n\r\nimport javax.persistence.Column;\r\nimport javax.persistence.Entity;\r\nimport javax.persistence.GeneratedValue;\r\nimport javax.persistence.Id;\r\nimport javax.persistence.OneToMany;\r\nimport javax.validation.constraints.NotEmpty;\r\nimport javax.validation.constraints.NotNull;\r\n\r\n@Entity\r\npublic class Bookshelf {\r\n\t@Id\r\n\t@GeneratedValue\r\n\t@Column\r\n\t@NotNull\r\n\tprivate long id;\r\n\r\n\t@Column\r\n\t@NotEmpty\r\n\tprivate String name;\r\n\r\n\t@OneToMany\r\n\tprivate List&lt;Book&gt; books;\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 List&lt;Book&gt; getBooks() {\r\n\t\treturn books;\r\n\t}\r\n\r\n\tpublic void setBooks(List&lt;Book&gt; books) {\r\n\t\tthis.books = books;\r\n\t}\r\n\r\n}\r\n<\/pre>\n<p>Book.java<\/p>\n<pre class=\"brush: java; highlight: [27,28,54,55,56,57,58,59,60]; title: ; notranslate\" title=\"\">\r\npackage jp.kpc;\r\n\r\nimport javax.persistence.Column;\r\nimport javax.persistence.Entity;\r\nimport javax.persistence.GeneratedValue;\r\nimport javax.persistence.Id;\r\nimport javax.persistence.ManyToOne;\r\nimport javax.validation.constraints.NotEmpty;\r\nimport javax.validation.constraints.NotNull;\r\n\r\n@Entity\r\npublic class Book {\r\n\t@Id\r\n\t@GeneratedValue\r\n\t@Column\r\n\t@NotNull\r\n\tprivate long id;\r\n\r\n\t@Column\r\n\t@NotEmpty\r\n\tprivate String title;\r\n\r\n\t@Column\r\n\t@NotEmpty\r\n\tprivate String author;\r\n\r\n\t@ManyToOne\r\n\tprivate Bookshelf bookshelf;\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 getTitle() {\r\n\t\treturn title;\r\n\t}\r\n\r\n\tpublic void setTitle(String title) {\r\n\t\tthis.title = title;\r\n\t}\r\n\r\n\tpublic String getAuthor() {\r\n\t\treturn author;\r\n\t}\r\n\r\n\tpublic void setAuthor(String author) {\r\n\t\tthis.author = author;\r\n\t}\r\n\r\n\tpublic Bookshelf getBookshelf() {\r\n\t\treturn bookshelf;\r\n\t}\r\n\r\n\tpublic void setBookshelf(Bookshelf bookshelf) {\r\n\t\tthis.bookshelf = bookshelf;\r\n\t}\r\n}\r\n<\/pre>\n<p>\u672c\u3092\u5165\u308c\u308b\u672c\u68da\u3092\u6307\u5b9a\u3059\u308b\u305f\u3081\u306e\u753b\u9762\u3092\u4f5c\u308b\u3002<br \/>\n\u305d\u306e\u305f\u3081\u306b\u3001\/book\/{id} (id\u306fBook\u306eid)\u3068\u3044\u3046URL\u3092\u7528\u610f\u3059\u308b\u3002<\/p>\n<pre class=\"brush: java; highlight: [39,40,41,42,43,44,45,46]; title: ; notranslate\" title=\"\">\r\npackage jp.kpc;\r\n\r\nimport java.util.List;\r\nimport java.util.Optional;\r\n\r\nimport org.springframework.beans.factory.annotation.Autowired;\r\nimport org.springframework.stereotype.Controller;\r\nimport org.springframework.web.bind.annotation.PathVariable;\r\nimport org.springframework.web.bind.annotation.RequestMapping;\r\nimport org.springframework.web.bind.annotation.RequestMethod;\r\nimport org.springframework.web.bind.annotation.RequestParam;\r\nimport org.springframework.web.servlet.ModelAndView;\r\n\r\n@Controller\r\npublic class BookController {\r\n\t@Autowired\r\n\tprivate BookRepository repository;\r\n\r\n\t@RequestMapping(&quot;\/books&quot;)\r\n\tpublic ModelAndView index(ModelAndView mav) {\r\n\t\tmav.setViewName(&quot;books&quot;);\r\n\t\tList&lt;Book&gt; list = repository.findAll();\r\n\t\tmav.addObject(&quot;list&quot;, list);\r\n\t\treturn mav;\r\n\t}\r\n\r\n\t@RequestMapping(value=&quot;\/addbook&quot;, method=RequestMethod.POST)\r\n\tpublic ModelAndView formPost(ModelAndView mav,\r\n\t\t\t@RequestParam(&quot;title&quot;) String title,\r\n\t\t\t@RequestParam(&quot;author&quot;) String author) {\r\n\t\tBook book = new Book();\r\n\t\tbook.setTitle(title);\r\n\t\tbook.setAuthor(author);\r\n\t\trepository.saveAndFlush(book);\r\n\t\treturn new ModelAndView(&quot;redirect:\/books&quot;);\r\n\t}\r\n\r\n\r\n\t@RequestMapping(value = &quot;\/book\/{id}&quot;, method = RequestMethod.GET)\r\n\tpublic ModelAndView book(ModelAndView mav,\r\n\t\t\t@PathVariable long id) {\r\n\t\tmav.setViewName(&quot;book&quot;);\r\n\t\tOptional&lt;Book&gt; data = repository.findById(id);\r\n\t\tmav.addObject(&quot;book&quot;, data.get());\r\n\t\treturn mav;\r\n\t}\r\n\r\n}\r\n<\/pre>\n<p>book.html<\/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;Book - \u672c\u3092\u5165\u308c\u308b\u672c\u68da\u3092\u6307\u5b9a\u3059\u308b&lt;\/title&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n\r\n&lt;h1&gt;Book&lt;\/h1&gt;\r\n&lt;table&gt;\r\n\t&lt;tr&gt;\r\n\t\t&lt;td th:text=&quot;${book.title}&quot;&gt;&lt;\/td&gt;\r\n\t\t&lt;td th:text=&quot;${book.author}&quot;&gt;&lt;\/td&gt;\r\n\t&lt;\/tr&gt;\r\n&lt;\/table&gt;\r\n\r\n&lt;hr \/&gt;\r\n\r\n&lt;div&gt;\u3069\u306e\u672c\u68da\u306b\u5165\u308c\u307e\u3059\u304b\uff1f&lt;\/div&gt;\r\n&lt;form action=&quot;\/book&quot; method=&quot;post&quot;&gt;\r\n\t&lt;input type=&quot;hidden&quot; name=&quot;bookId&quot; th:value=&quot;${book.id}&quot; \/&gt;\r\n\t&lt;div&gt;\u672c\u68daID: &lt;input type=&quot;text&quot; name=&quot;bookshelfId&quot; \/&gt;&lt;\/div&gt;\r\n\t&lt;div&gt;&lt;input id=&quot;submit&quot; type=&quot;submit&quot; value=&quot;\u672c\u68da\u306b\u5165\u308c\u308b&quot; \/&gt;&lt;\/div&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>\u672c\u3068\u672c\u68da\u306e\u95a2\u9023\u4ed8\u3051\u3092\u4fdd\u5b58\u3059\u308b\u3002<\/p>\n<p>BookController.java<\/p>\n<pre class=\"brush: java; first-line: 18; title: ; notranslate\" title=\"\">\r\n\t@Autowired\r\n\tprivate BookshelfRepository bookshelfRepository;\r\n<\/pre>\n<pre class=\"brush: java; first-line: 50; title: ; notranslate\" title=\"\">\r\n\t@RequestMapping(value=&quot;\/book&quot;, method=RequestMethod.POST)\r\n\tpublic ModelAndView save(ModelAndView mav,\r\n\t\t\t@RequestParam(&quot;bookId&quot;) long bookId,\r\n\t\t\t@RequestParam(&quot;bookshelfId&quot;) long bookshelfId) {\r\n\t\tOptional&lt;Book&gt; data = repository.findById(bookId);\r\n\t\tBook book = data.get();\r\n\t\tOptional&lt;Bookshelf&gt; bsData = bookshelfRepository.findById(bookshelfId);\r\n\t\tBookshelf bookshelf = bsData.get();\r\n\t\tbook.setBookshelf(bookshelf);\r\n\t\trepository.saveAndFlush(book);\r\n\t\treturn new ModelAndView(&quot;redirect:\/books&quot;);\r\n\t}\r\n<\/pre>\n<p>books.html<\/p>\n<pre class=\"brush: xml; highlight: [11,12,13,18,19]; 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;Book - \u672c\u306e\u30ea\u30b9\u30c8&lt;\/title&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n\r\n&lt;h1&gt;Book list&lt;\/h1&gt;\r\n&lt;table&gt;\r\n\t&lt;tr&gt;\r\n\t\t&lt;th&gt;ID&lt;\/th&gt;&lt;th&gt;\u30bf\u30a4\u30c8\u30eb&lt;\/th&gt;&lt;th&gt;\u8457\u8005&lt;\/th&gt;&lt;th&gt;\u672c\u68da&lt;\/th&gt;\r\n\t&lt;\/tr&gt;\r\n\t&lt;tr th:each=&quot;book : ${list}&quot;&gt;\r\n\t\t&lt;td th:text=&quot;${book.id}&quot;&gt;&lt;\/td&gt;\r\n\t\t&lt;td th:text=&quot;${book.title}&quot;&gt;&lt;\/td&gt;\r\n\t\t&lt;td th:text=&quot;${book.author}&quot;&gt;&lt;\/td&gt;\r\n\t\t&lt;td th:if=&quot;${book.bookshelf != null}&quot; th:text=&quot;${book.bookshelf.name}&quot;&gt;&lt;\/td&gt;\r\n\t\t&lt;td th:if=&quot;${book.bookshelf == null}&quot; th:text=&quot;\u672c\u68da\u306b\u5165\u308c\u3066\u307e\u305b\u3093&quot;&gt;&lt;\/td&gt;\r\n\t&lt;\/tr&gt;\r\n&lt;\/table&gt;\r\n\r\n&lt;hr \/&gt;\r\n\r\n&lt;div&gt;\u65b0\u3057\u3044\u672c&lt;\/div&gt;\r\n&lt;form action=&quot;\/addbook&quot; method=&quot;post&quot;&gt;\r\n\t&lt;div&gt;\u30bf\u30a4\u30c8\u30eb: &lt;input type=&quot;text&quot; name=&quot;title&quot; \/&gt;&lt;\/div&gt;\r\n\t&lt;div&gt;\u8457\u8005: &lt;input type=&quot;text&quot; name=&quot;author&quot; \/&gt;&lt;\/div&gt;\r\n\t&lt;div&gt;&lt;input id=&quot;submit&quot; type=&quot;submit&quot; value=&quot;+\u8ffd\u52a0&quot; \/&gt;&lt;\/div&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>\u672c\u306e\u30bf\u30a4\u30c8\u30eb\u3092\u30af\u30ea\u30c3\u30af\u3057\u305f\u3089\u3001\/book\/{id} \u306b\u98db\u3079\u308b\u3088\u3046\u306b\u3059\u308b\u3002<\/p>\n<pre class=\"brush: xml; first-line: 9; highlight: [16]; title: ; notranslate\" title=\"\">\r\n&lt;h1&gt;Book list&lt;\/h1&gt;\r\n&lt;table&gt;\r\n\t&lt;tr&gt;\r\n\t\t&lt;th&gt;ID&lt;\/th&gt;&lt;th&gt;\u30bf\u30a4\u30c8\u30eb&lt;\/th&gt;&lt;th&gt;\u8457\u8005&lt;\/th&gt;&lt;th&gt;\u672c\u68da&lt;\/th&gt;\r\n\t&lt;\/tr&gt;\r\n\t&lt;tr th:each=&quot;book : ${list}&quot;&gt;\r\n\t\t&lt;td th:text=&quot;${book.id}&quot;&gt;&lt;\/td&gt;\r\n\t\t&lt;td&gt;&lt;a th:href=&quot;@{'\/book\/' + ${book.id}}&quot; th:text=&quot;${book.title}&quot;&gt;&lt;\/a&gt;&lt;\/td&gt;\r\n\t\t&lt;td th:text=&quot;${book.author}&quot;&gt;&lt;\/td&gt;\r\n\t\t&lt;td th:if=&quot;${book.bookshelf != null}&quot; th:text=&quot;${book.bookshelf.name}&quot;&gt;&lt;\/td&gt;\r\n\t\t&lt;td th:if=&quot;${book.bookshelf == null}&quot; th:text=&quot;\u672c\u68da\u306b\u5165\u308c\u3066\u307e\u305b\u3093&quot;&gt;&lt;\/td&gt;\r\n\t&lt;\/tr&gt;\r\n&lt;\/table&gt;\r\n<\/pre>\n<p>\u672c\u68da\u306b\u5165\u3063\u3066\u3044\u308b\u672c\u306e\u30ea\u30b9\u30c8\u3092\u8868\u793a\u3059\u308b\u753b\u9762\u3092\u4f5c\u308b\u3002<\/p>\n<p>\/bookshelf\/{id} \u3067\u672c\u68da\u5185\u306e\u672c\u306e\u30ea\u30b9\u30c8\u3092\u8868\u793a\u3059\u308b\u3002<\/p>\n<p>bookshelf.html<\/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;Bookshelf - \u672c\u68da\u306b\u5165\u3063\u3066\u3044\u308b\u672c\u306e\u30ea\u30b9\u30c8&lt;\/title&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n\r\n&lt;h1&gt;Bookshelf - \u672c\u68da\u306b\u5165\u3063\u3066\u3044\u308b\u672c\u306e\u30ea\u30b9\u30c8&lt;\/h1&gt;\r\n\r\n&lt;h3 th:text=&quot;${bookshelf.name}&quot;&gt;&lt;\/h3&gt;\r\n\r\n&lt;ul th:each=&quot;book : ${bookshelf.books}&quot;&gt;\r\n\t&lt;li th:text=&quot;${book.title + ' - ' + book.author}&quot;&gt;&lt;\/li&gt;\r\n&lt;\/ul&gt;\r\n\r\n\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<p>Bookshelf.java<\/p>\n<pre class=\"brush: java; first-line: 13; highlight: [25]; title: ; notranslate\" title=\"\">\r\n@Entity\r\npublic class Bookshelf {\r\n\t@Id\r\n\t@GeneratedValue\r\n\t@Column\r\n\t@NotNull\r\n\tprivate long id;\r\n\r\n\t@Column\r\n\t@NotEmpty\r\n\tprivate String name;\r\n\r\n\t@OneToMany(mappedBy = &quot;bookshelf&quot;)\r\n\tprivate List&lt;Book&gt; books;\r\n\r\n<\/pre>\n<p>IndexController.java<\/p>\n<pre class=\"brush: java; first-line: 37; title: ; notranslate\" title=\"\">\r\n\t@RequestMapping(value = &quot;\/bookshelf\/{id}&quot;, method = RequestMethod.GET)\r\n\tpublic ModelAndView bookshelf(ModelAndView mav,\r\n\t\t\t@PathVariable long id) {\r\n\t\tmav.setViewName(&quot;bookshelf&quot;);\r\n\t\tOptional&lt;Bookshelf&gt; data = repository.findById(id);\r\n\t\tmav.addObject(&quot;bookshelf&quot;, data.get());\r\n\t\treturn mav;\r\n\t}\r\n<\/pre>\n<p>index.html\u306e\u30c6\u30fc\u30d6\u30eb\u306b\u5217\u3092\u8ffd\u52a0\u3057\u3066\u3001\u672c\u68da\u306eID\u3092\u8868\u793a\u3059\u308b\u3002<\/p>\n<pre class=\"brush: xml; highlight: [12]; 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;Bookshelf - \u672c\u68da&lt;\/title&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n\r\n&lt;h1&gt;Bookshelf list&lt;\/h1&gt;\r\n&lt;table&gt;\r\n\t&lt;tr th:each=&quot;bs : ${list}&quot;&gt;\r\n\t\t&lt;td th:text=&quot;${bs.id}&quot;&gt;&lt;\/td&gt;\r\n\t\t&lt;td th:text=&quot;${bs.name}&quot;&gt;&lt;\/td&gt;\r\n\t&lt;\/tr&gt;\r\n&lt;\/table&gt;\r\n\r\n&lt;hr \/&gt;\r\n\r\n&lt;div&gt;\u65b0\u3057\u3044\u672c\u68da&lt;\/div&gt;\r\n&lt;form action=&quot;\/addshelf&quot; method=&quot;post&quot;&gt;\r\n\t&lt;div&gt;\u306a\u307e\u3048&lt;\/div&gt;\r\n\t&lt;div&gt;&lt;input type=&quot;text&quot; name=&quot;name&quot; \/&gt;&lt;\/div&gt;\r\n\t&lt;div&gt;&lt;input id=&quot;submit&quot; type=&quot;submit&quot; value=&quot;+\u8ffd\u52a0&quot; \/&gt;&lt;\/div&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>\u672c\u68da\u306e\u540d\u524d\u3092\u30af\u30ea\u30c3\u30af\u3057\u305f\u3089\u3001\u672c\u68da\u306e\u5185\u5bb9\u3092\u8868\u793a\u3059\u308b\u30da\u30fc\u30b8\u306b\u79fb\u52d5\u3067\u304d\u308b\u3088\u3046\u306b\u3059\u308b\u3002<br \/>\n\u672c\u306e\u30ea\u30b9\u30c8\u30da\u30fc\u30b8\uff08\/books\uff09\u3078\u306e\u30ea\u30f3\u30af\u3082\u8ffd\u52a0\u3059\u308b\u3002<\/p>\n<pre class=\"brush: xml; highlight: [13,26]; 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;Bookshelf - \u672c\u68da&lt;\/title&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n\r\n&lt;h1&gt;Bookshelf list&lt;\/h1&gt;\r\n&lt;table&gt;\r\n\t&lt;tr th:each=&quot;bs : ${list}&quot;&gt;\r\n\t\t&lt;td th:text=&quot;${bs.id}&quot;&gt;&lt;\/td&gt;\r\n\t\t&lt;td&gt;&lt;a th:href=&quot;@{'\/bookshelf\/' + ${bs.id}}&quot; th:text=&quot;${bs.name}&quot;&gt;&lt;\/a&gt;&lt;\/td&gt;\r\n\t&lt;\/tr&gt;\r\n&lt;\/table&gt;\r\n\r\n&lt;hr \/&gt;\r\n\r\n&lt;div&gt;\u65b0\u3057\u3044\u672c\u68da&lt;\/div&gt;\r\n&lt;form action=&quot;\/addshelf&quot; method=&quot;post&quot;&gt;\r\n\t&lt;div&gt;\u306a\u307e\u3048&lt;\/div&gt;\r\n\t&lt;div&gt;&lt;input type=&quot;text&quot; name=&quot;name&quot; \/&gt;&lt;\/div&gt;\r\n\t&lt;div&gt;&lt;input id=&quot;submit&quot; type=&quot;submit&quot; value=&quot;+\u8ffd\u52a0&quot; \/&gt;&lt;\/div&gt;\r\n&lt;\/form&gt;\r\n\r\n&lt;a href=&quot;\/books&quot;&gt;\u672c\u306e\u30ea\u30b9\u30c8&lt;\/a&gt;\r\n\r\n\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<p>books.html\u3001book.html\u3001bookshelf.html \u306b\u3001\u30c8\u30c3\u30d7\u30da\u30fc\u30b8\u3078\u306e\u30ea\u30f3\u30af\u3092\u8ffd\u52a0\u3059\u308b\u3002<\/p>\n<p>books.html<\/p>\n<pre class=\"brush: xml; highlight: [11]; 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;Book - \u672c\u306e\u30ea\u30b9\u30c8&lt;\/title&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n\r\n&lt;h1&gt;Book list&lt;\/h1&gt;\r\n\r\n&lt;a href=&quot;\/&quot;&gt;\u30c8\u30c3\u30d7&lt;\/a&gt;\r\n\r\n&lt;table&gt;\r\n:\r\n<\/pre>\n<p>book.html<\/p>\n<pre class=\"brush: xml; highlight: [11]; 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;Book - \u672c\u3092\u5165\u308c\u308b\u672c\u68da\u3092\u6307\u5b9a\u3059\u308b&lt;\/title&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n\r\n&lt;h1&gt;Book&lt;\/h1&gt;\r\n\r\n&lt;a href=&quot;\/&quot;&gt;\u30c8\u30c3\u30d7&lt;\/a&gt;\r\n\r\n&lt;table&gt;\r\n:\r\n<\/pre>\n<p>bookshelf.html<\/p>\n<pre class=\"brush: xml; highlight: [11]; 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;Bookshelf - \u672c\u68da\u306b\u5165\u3063\u3066\u3044\u308b\u672c\u306e\u30ea\u30b9\u30c8&lt;\/title&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n\r\n&lt;h1&gt;Bookshelf - \u672c\u68da\u306b\u5165\u3063\u3066\u3044\u308b\u672c\u306e\u30ea\u30b9\u30c8&lt;\/h1&gt;\r\n\r\n&lt;a href=&quot;\/&quot;&gt;\u30c8\u30c3\u30d7&lt;\/a&gt;\r\n\r\n&lt;h3 th:text=&quot;${bookshelf.name}&quot;&gt;&lt;\/h3&gt;\r\n:\r\n<\/pre>\n<p>\u672c\u68da\u30da\u30fc\u30b8\u5185\u306b\u8868\u793a\u3057\u305f\u672c\u306e\u30ea\u30b9\u30c8\u3067\u3001\u30bf\u30a4\u30c8\u30eb\u3092\u30af\u30ea\u30c3\u30af\u3059\u308b\u3068\u672c\u306e\u30da\u30fc\u30b8\u306b\u79fb\u52d5\u3067\u304d\u308b\u3088\u3046\u306b\u3059\u308b\u3002<\/p>\n<pre class=\"brush: xml; highlight: [16,17,18,19]; 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;Bookshelf - \u672c\u68da\u306b\u5165\u3063\u3066\u3044\u308b\u672c\u306e\u30ea\u30b9\u30c8&lt;\/title&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n\r\n&lt;h1&gt;Bookshelf - \u672c\u68da\u306b\u5165\u3063\u3066\u3044\u308b\u672c\u306e\u30ea\u30b9\u30c8&lt;\/h1&gt;\r\n\r\n&lt;a href=&quot;\/&quot;&gt;\u30c8\u30c3\u30d7&lt;\/a&gt;\r\n\r\n&lt;h3 th:text=&quot;${bookshelf.name}&quot;&gt;&lt;\/h3&gt;\r\n\r\n&lt;ul th:each=&quot;book : ${bookshelf.books}&quot;&gt;\r\n\t&lt;li&gt;\r\n\t\t&lt;a th:href=&quot;@{'\/book\/' + ${book.id}}&quot; th:text=&quot;${book.title}&quot;&gt;&lt;\/a&gt;\r\n\t\t&lt;span th:text=&quot;${' - ' + book.author}&quot;&gt;&lt;\/span&gt;\r\n\t&lt;\/li&gt;\r\n&lt;\/ul&gt;\r\n\r\n\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<p>book.html \u3067\u3001\u672c\u68daID\u3092\u5165\u529b\u3059\u308b\u306e\u3067\u306f\u306a\u304f\u3001select \u3067\u9078\u629e\u3067\u304d\u308b\u3088\u3046\u306b\u3059\u308b\u3002<\/p>\n<p>BookController.java \u3067\u3001\u672c\u68da\u306e\u30ea\u30b9\u30c8\u3092\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u306b\u6e21\u3059\u3088\u3046\u306b\u3059\u308b\u3002<\/p>\n<pre class=\"brush: java; first-line: 41; highlight: [47,48]; title: ; notranslate\" title=\"\">\r\n\t@RequestMapping(value = &quot;\/book\/{id}&quot;, method = RequestMethod.GET)\r\n\tpublic ModelAndView book(ModelAndView mav,\r\n\t\t\t@PathVariable long id) {\r\n\t\tmav.setViewName(&quot;book&quot;);\r\n\t\tOptional&lt;Book&gt; data = repository.findById(id);\r\n\t\tmav.addObject(&quot;book&quot;, data.get());\r\n\t\tList&lt;Bookshelf&gt; list = bookshelfRepository.findAll();\r\n\t\tmav.addObject(&quot;bookshelfList&quot;, list);\r\n\t\treturn mav;\r\n\t}\r\n<\/pre>\n<p>book.html<\/p>\n<pre class=\"brush: xml; highlight: [25,26,27,28,29]; 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;Book - \u672c\u3092\u5165\u308c\u308b\u672c\u68da\u3092\u6307\u5b9a\u3059\u308b&lt;\/title&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n\r\n&lt;h1&gt;Book&lt;\/h1&gt;\r\n\r\n&lt;a href=&quot;\/&quot;&gt;\u30c8\u30c3\u30d7&lt;\/a&gt;\r\n\r\n&lt;table&gt;\r\n\t&lt;tr&gt;\r\n\t\t&lt;td th:text=&quot;${book.title}&quot;&gt;&lt;\/td&gt;\r\n\t\t&lt;td th:text=&quot;${book.author}&quot;&gt;&lt;\/td&gt;\r\n\t&lt;\/tr&gt;\r\n&lt;\/table&gt;\r\n\r\n&lt;hr \/&gt;\r\n\r\n&lt;div&gt;\u3069\u306e\u672c\u68da\u306b\u5165\u308c\u307e\u3059\u304b\uff1f&lt;\/div&gt;\r\n&lt;form action=&quot;\/book&quot; method=&quot;post&quot;&gt;\r\n\t&lt;input type=&quot;hidden&quot; name=&quot;bookId&quot; th:value=&quot;${book.id}&quot; \/&gt;\r\n\t&lt;div&gt;\r\n\t\t&lt;select name=&quot;bookshelfId&quot;&gt;\r\n\t\t\t&lt;option th:each=&quot;bs : ${bookshelfList}&quot; th:value=&quot;${bs.id}&quot; th:selected=&quot;${bs.id == book.id}&quot; th:text=&quot;${bs.name}&quot;&gt;&lt;\/option&gt;\r\n\t\t&lt;\/select&gt;\r\n\t&lt;\/div&gt;\r\n\t&lt;div&gt;&lt;input id=&quot;submit&quot; type=&quot;submit&quot; value=&quot;\u672c\u68da\u306b\u5165\u308c\u308b&quot; \/&gt;&lt;\/div&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>\u672c\u68da\u306b\u5165\u308c\u306a\u3044\u9078\u629e\u80a2\u3092\u8ffd\u52a0\u3059\u308b\u3002<\/p>\n<pre class=\"brush: xml; first-line: 22; highlight: [27]; title: ; notranslate\" title=\"\">\r\n&lt;div&gt;\u3069\u306e\u672c\u68da\u306b\u5165\u308c\u307e\u3059\u304b\uff1f&lt;\/div&gt;\r\n&lt;form action=&quot;\/book&quot; method=&quot;post&quot;&gt;\r\n\t&lt;input type=&quot;hidden&quot; name=&quot;bookId&quot; th:value=&quot;${book.id}&quot; \/&gt;\r\n\t&lt;div&gt;\r\n\t\t&lt;select name=&quot;bookshelfId&quot;&gt;\r\n\t\t\t&lt;option value=&quot;0&quot;&gt;\u672c\u68da\u306b\u5165\u308c\u306a\u3044&lt;\/option&gt;\r\n\t\t\t&lt;option th:each=&quot;bs : ${bookshelfList}&quot; th:value=&quot;${bs.id}&quot; th:selected=&quot;${bs.id == book.id}&quot; th:text=&quot;${bs.name}&quot;&gt;&lt;\/option&gt;\r\n\t\t&lt;\/select&gt;\r\n\t&lt;\/div&gt;\r\n\t&lt;div&gt;&lt;input id=&quot;submit&quot; type=&quot;submit&quot; value=&quot;\u672c\u68da\u306b\u5165\u308c\u308b&quot; \/&gt;&lt;\/div&gt;\r\n&lt;\/form&gt;\r\n<\/pre>\n<p>\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u3067\u306f\u3001\u672c\u68da\u691c\u7d22\u3057\u3066\u898b\u3064\u304b\u3089\u306a\u3044\u3068\u304d\u306f null \u3092\u8a2d\u5b9a\u3059\u308b\u3002<\/p>\n<pre class=\"brush: java; first-line: 52; highlight: [59,60,61,62,63,64]; title: ; notranslate\" title=\"\">\r\n\t@RequestMapping(value=&quot;\/book&quot;, method=RequestMethod.POST)\r\n\tpublic ModelAndView save(ModelAndView mav,\r\n\t\t\t@RequestParam(&quot;bookId&quot;) long bookId,\r\n\t\t\t@RequestParam(&quot;bookshelfId&quot;) long bookshelfId) {\r\n\t\tOptional&lt;Book&gt; data = repository.findById(bookId);\r\n\t\tBook book = data.get();\r\n\t\tOptional&lt;Bookshelf&gt; bsData = bookshelfRepository.findById(bookshelfId);\r\n\t\tif(bsData.isPresent()) {\r\n\t\t\tBookshelf bookshelf = bsData.get();\r\n\t\t\tbook.setBookshelf(bookshelf);\r\n\t\t} else {\r\n\t\t\tbook.setBookshelf(null);\r\n\t\t}\r\n\t\trepository.saveAndFlush(book);\r\n\t\treturn new ModelAndView(&quot;redirect:\/books&quot;);\r\n\t}\r\n<\/pre>\n<!--CusAds0-->\n<div style=\"font-size: 0px; height: 0px; line-height: 0px; margin: 0; padding: 0; clear: both;\"><\/div>","protected":false},"excerpt":{"rendered":"<p>\u65b0\u898f\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\u3059\u308b\u3002 \u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u7a2e\u985e\u306f\u3001Spring\u30b9\u30bf\u30fc\u30bf\u30fc\u30fb\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u9078\u629e\u3059\u308b\u3002 \u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u540d\u3092\u300cbookshelf\u300d\u306b\u3057\u3066\u6b21\u3078\u3092\u30af\u30ea\u30c3\u30af\u3002 \u4f9d\u5b58\u95a2\u4fc2\u306f\u3001\u4ee5\u4e0b\u306e\u9805\u76ee\u3092\u9078\u629e\u3059\u308b\u3002 HyperSQL D &hellip; <a href=\"https:\/\/kpc2020.satoshis.jp\/?p=79\" class=\"more-link\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"screen-reader-text\">Bookshelf\u30a2\u30d7\u30ea\u3092\u4f5c\u6210\u3059\u308b<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,5],"tags":[],"class_list":["post-79","post","type-post","status-publish","format-standard","hentry","category-java","category-springboot"],"views":405,"_links":{"self":[{"href":"https:\/\/kpc2020.satoshis.jp\/index.php?rest_route=\/wp\/v2\/posts\/79","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kpc2020.satoshis.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kpc2020.satoshis.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kpc2020.satoshis.jp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kpc2020.satoshis.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=79"}],"version-history":[{"count":37,"href":"https:\/\/kpc2020.satoshis.jp\/index.php?rest_route=\/wp\/v2\/posts\/79\/revisions"}],"predecessor-version":[{"id":117,"href":"https:\/\/kpc2020.satoshis.jp\/index.php?rest_route=\/wp\/v2\/posts\/79\/revisions\/117"}],"wp:attachment":[{"href":"https:\/\/kpc2020.satoshis.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=79"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kpc2020.satoshis.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=79"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kpc2020.satoshis.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=79"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}