{"id":326,"date":"2019-09-09T10:12:47","date_gmt":"2019-09-09T01:12:47","guid":{"rendered":"http:\/\/2019se3.satoshis.jp\/?p=326"},"modified":"2019-09-09T12:55:03","modified_gmt":"2019-09-09T03:55:03","slug":"9%e6%9c%889%e6%97%a5","status":"publish","type":"post","link":"https:\/\/2019se3.satoshis.jp\/?p=326","title":{"rendered":"9\u67089\u65e5"},"content":{"rendered":"<h3>ACID\u7279\u6027<\/h3>\n<p>Atomicity\u30fbConsistency\u30fbIsolation\u30fbDurability\u3092\u8003\u616e\u3057\u3066\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u3057\u3088\u3046\u3002<\/p>\n<p>\u5165\u529b\u30d5\u30a3\u30fc\u30eb\u30c9\u306e\u30c1\u30a7\u30c3\u30af\u3092 username \u3068 password \u3067\u5206\u5272\u3059\u308b\u3002(Atomicity\uff09<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n$(function() {\r\n\t$('[type=submit]').attr('disabled', true);\r\n\t$('[name=username]').on('keyup', function() {\r\n\t\tcheckUserNameField();\r\n\t});\r\n\t$('[type=password]').on('keyup', function() {\r\n\t\tcheckPasswordField();\r\n\t});\r\n});\r\n\r\nfunction checkUserNameField() {\r\n\tvar name = $('[name=username]').val();\r\n\tif (name.length == 0) {\r\n\t\t$('[type=submit]').attr('disabled', true);\r\n\t\t$('div.err').text('\u30e6\u30fc\u30b6\u30fc\u540d\u3092\u5165\u529b\u3057\u3066\u304f\u3060\u3055\u3044\u3002');\r\n\t\treturn;\r\n\t}\r\n\t$('div.err').text('');\r\n\t$('[type=submit]').attr('disabled', false);\r\n}\r\n\r\nfunction checkPasswordField() {\r\n\tvar p1 = $('[name=password]').val();\r\n\tvar p2 = $('[name=password2]').val();\r\n\tif (p1 != p2) {\r\n\t\t$('div.err').text('\u30d1\u30b9\u30ef\u30fc\u30c9\u304c\u4e00\u81f4\u3057\u3066\u3044\u307e\u305b\u3093\u3002');\r\n\t\t$('[type=submit]').attr('disabled', true);\r\n\t\treturn;\r\n\t}\r\n\t$('div.err').text('');\r\n\t$('[type=submit]').attr('disabled', false);\r\n}\r\n<\/pre>\n<h3>\u30ed\u30b0\u30a4\u30f3\u3057\u305f\u30e6\u30fc\u30b6\u30fc\u540d\u3092\u8868\u793a\u3059\u308b<\/h3>\n<p>\u30de\u30a4\u30da\u30fc\u30b8\u3067\u306f\u3001\u30ed\u30b0\u30a4\u30f3\u3057\u305f\u30e6\u30fc\u30b6\u30fc\u540d\u3092\u8868\u793a\u3057\u3066\u307f\u3088\u3046\u3002<br \/>\n\u30e1\u30bd\u30c3\u30c9\u306b Principal \u5f15\u6570\u3092\u8ffd\u52a0\u3059\u308b\u3068\u3001\u30ed\u30b0\u30a4\u30f3\u3057\u305f\u30e6\u30fc\u30b6\u30fc\u306b\u95a2\u3059\u308b\u60c5\u5831\u3092\u3082\u3089\u3048\u308b\u3002<\/p>\n<p>MyController.java<\/p>\n<pre class=\"brush: java; first-line: 51; title: ; notranslate\" title=\"\">\r\n\t@RequestMapping(value = &quot;\/mypage&quot;)\r\n\tpublic ModelAndView top(ModelAndView mav, Principal p) {\r\n\t\tmav.setViewName(&quot;mypage&quot;);\r\n\t\tmav.addObject(&quot;username&quot;, p.getName());\r\n\t\treturn mav;\r\n\t}\r\n<\/pre>\n<p>HTML\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3067\u53d7\u3051\u53d6\u3063\u305f username \u3092\u8868\u793a\u3059\u308b\u3002<\/p>\n<p>mypage.html<\/p>\n<pre class=\"brush: xml; first-line: 7; highlight: [9]; title: ; notranslate\" title=\"\">\r\n&lt;body&gt;\r\n    &lt;h1&gt;\u30de\u30a4\u30da\u30fc\u30b8&lt;\/h1&gt;\r\n    &lt;p&gt;\u3088\u3046\u3053\u305d\u3001&lt;span th:text=&quot;${username}&quot;&gt;&lt;\/span&gt;\u3055\u3093\uff01&lt;\/p&gt;\r\n    &lt;form th:action=&quot;@{\/logout}&quot; method=&quot;post&quot;&gt;\r\n        &lt;input type=&quot;submit&quot; value=&quot;\u30ed\u30b0\u30a2\u30a6\u30c8&quot; \/&gt;\r\n    &lt;\/form&gt;\r\n&lt;\/body&gt;\r\n<\/pre>\n<p>\u30e6\u30fc\u30b6\u30fc\u306e\u60c5\u5831\u3092\u6301\u305f\u305b\u308b\u305f\u3081\u306b Profile \u30af\u30e9\u30b9\u3092\u4f5c\u6210\u3059\u308b\u3002<\/p>\n<p>Profile.java<\/p>\n<pre class=\"brush: java; 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.NotEmpty;\r\nimport javax.validation.constraints.NotNull;\r\n\r\n@Entity\r\npublic class Profile {\r\n    @Id\r\n    @GeneratedValue(strategy = GenerationType.AUTO)\r\n    @Column\r\n    @NotNull\r\n    private long id;\r\n\r\n    @Column(length = 200, nullable = false)\r\n    @NotEmpty\r\n    private String username;\r\n\r\n    @Column\r\n    private String profile;\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 getUsername() {\r\n\t\treturn username;\r\n\t}\r\n\r\n\tpublic void setUsername(String username) {\r\n\t\tthis.username = username;\r\n\t}\r\n\r\n\tpublic String getProfile() {\r\n\t\treturn profile;\r\n\t}\r\n\r\n\tpublic void setProfile(String profile) {\r\n\t\tthis.profile = profile;\r\n\t}\r\n\r\n}\r\n<\/pre>\n<p>\u30a8\u30f3\u30c6\u30a3\u30c6\u30a3\u3092\u4f5c\u3063\u305f\u306e\u3067\u5bfe\u5fdc\u3059\u308b\u30ea\u30dd\u30b8\u30c8\u30ea\u3092\u4f5c\u6210\u3059\u308b\u3002<\/p>\n<p>ProfileRepository.java<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\npackage jp.abc;\r\n\r\nimport org.springframework.data.jpa.repository.JpaRepository;\r\n\r\npublic interface ProfileRepository extends JpaRepository&lt;Profile, Long&gt; {\r\n\r\n}\r\n<\/pre>\n<p>Principal \u304b\u3089\u306f username \u3057\u304b\u53d6\u5f97\u3067\u304d\u306a\u3044\u306e\u3067\u3001 username \u3092\u3082\u3068\u306b Profile \u3092\u53d6\u5f97\u3059\u308b\u30e1\u30bd\u30c3\u30c9\u3092\u30ea\u30dd\u30b8\u30c8\u30ea\u306b\u8ffd\u52a0\u3059\u308b\u3002<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\npackage jp.abc;\r\n\r\nimport java.util.Optional;\r\n\r\nimport org.springframework.data.jpa.repository.JpaRepository;\r\n\r\npublic interface ProfileRepository extends JpaRepository&lt;Profile, Long&gt; {\r\n\tpublic Optional&lt;Profile&gt; findByUsername(String username);\r\n}\r\n<\/pre>\n<p>\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u3067\u3001Profile\u3092\u691c\u7d22\u3057\u3066\u307f\u3066\u3001\u306a\u304b\u3063\u305f\u3089\u65b0\u898f\u767b\u9332\u3059\u308b\u3002<\/p>\n<pre class=\"brush: java; first-line: 54; title: ; notranslate\" title=\"\">\r\n\t@RequestMapping(value = &quot;\/mypage&quot;)\r\n\tpublic ModelAndView top(ModelAndView mav, Principal p) {\r\n\t\tmav.setViewName(&quot;mypage&quot;);\r\n\t\tmav.addObject(&quot;username&quot;, p.getName());\r\n\t\tOptional&lt;Profile&gt; data = repository.findByUsername(p.getName());\r\n\t\tProfile profile = data.get();\r\n\t\tif (profile == null) {\r\n\t\t\tprofile = new Profile();\r\n\t\t\tprofile.setUsername(p.getName());\r\n\t\t\trepository.saveAndFlush(profile);\r\n\t\t}\r\n\t\tmav.addObject(&quot;profile&quot;, profile);\r\n\t\treturn mav;\r\n\t}\r\n<\/pre>\n<p>HTML\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3067\u306f\u3001profile \u306e\u60c5\u5831\u3082\u8868\u793a\u3057\u3066\u307f\u308b\u3002<\/p>\n<pre class=\"brush: xml; highlight: [10]; 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;login&lt;\/title&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n    &lt;h1&gt;\u30de\u30a4\u30da\u30fc\u30b8&lt;\/h1&gt;\r\n    &lt;p&gt;\u3088\u3046\u3053\u305d\u3001&lt;span th:text=&quot;${username}&quot;&gt;&lt;\/span&gt;\u3055\u3093\uff01&lt;\/p&gt;\r\n    &lt;p th:text=&quot;${profile.username}&quot;&gt;&lt;\/p&gt;\r\n    &lt;form th:action=&quot;@{\/logout}&quot; method=&quot;post&quot;&gt;\r\n        &lt;input type=&quot;submit&quot; value=&quot;\u30ed\u30b0\u30a2\u30a6\u30c8&quot; \/&gt;\r\n    &lt;\/form&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<p>\u30b3\u30f3\u30c8\u30ed\u30fc\u30e9\u306e\u30b3\u30fc\u30c9\u304c\u60aa\u304b\u3063\u305f\u3088\u3046\u3067\u3001\u4f8b\u5916\u304c\u767a\u751f\u3057\u305f\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\njava.util.NoSuchElementException: No value present\r\n\tat java.util.Optional.get(Optional.java:135) ~[na:1.8.0_152]\r\n\tat jp.abc.MyController.top(MyController.java:59) ~[classes\/:na]\r\n<\/pre>\n<p>\u5024\u304c\u5b58\u5728\u3057\u306a\u3044\u3068\u304d\u306f Optional#get() \u3092\u547c\u3093\u3067\u306f\u3044\u3051\u306a\u3044\u3089\u3057\u3044\u306e\u3067\u3001\u30b3\u30fc\u30c9\u3092\u66f8\u304d\u63db\u3048\u308b\u3002<\/p>\n<pre class=\"brush: java; first-line: 54; highlight: [59,60,61,62,63,64,65,66]; title: ; notranslate\" title=\"\">\r\n\t@RequestMapping(value = &quot;\/mypage&quot;)\r\n\tpublic ModelAndView top(ModelAndView mav, Principal p) {\r\n\t\tmav.setViewName(&quot;mypage&quot;);\r\n\t\tmav.addObject(&quot;username&quot;, p.getName());\r\n\t\tOptional&lt;Profile&gt; data = repository.findByUsername(p.getName());\r\n\t\tProfile profile;\r\n\t\tif (!data.isPresent()) {\r\n\t\t\tprofile = new Profile();\r\n\t\t\tprofile.setUsername(p.getName());\r\n\t\t\trepository.saveAndFlush(profile);\r\n\t\t} else {\r\n\t\t\tprofile = data.get();\r\n\t\t}\r\n\t\tmav.addObject(&quot;profile&quot;, profile);\r\n\t\treturn mav;\r\n\t}\r\n<\/pre>\n<p>Tweet \u30af\u30e9\u30b9\u3092\u4f5c\u6210\u3059\u308b\u3002<\/p>\n<p>Tweet.java<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\npackage jp.abc;\r\n\r\nimport java.util.Date;\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.persistence.ManyToOne;\r\nimport javax.validation.constraints.NotEmpty;\r\nimport javax.validation.constraints.NotNull;\r\n\r\n@Entity\r\npublic class Tweet {\r\n    @Id\r\n    @GeneratedValue(strategy = GenerationType.AUTO)\r\n    @Column\r\n    @NotNull\r\n    private long id;\r\n\r\n    @Column(length = 200, nullable = false)\r\n    @NotEmpty\r\n    private String content;\r\n\r\n    @Column(nullable = false)\r\n    private Date time;\r\n\r\n    @ManyToOne\r\n    private Profile profile;\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 getContent() {\r\n\t\treturn content;\r\n\t}\r\n\r\n\tpublic void setContent(String content) {\r\n\t\tthis.content = content;\r\n\t}\r\n\r\n\tpublic Date getTime() {\r\n\t\treturn time;\r\n\t}\r\n\r\n\tpublic void setTime(Date time) {\r\n\t\tthis.time = time;\r\n\t}\r\n\r\n\tpublic Profile getProfile() {\r\n\t\treturn profile;\r\n\t}\r\n\r\n\tpublic void setProfile(Profile profile) {\r\n\t\tthis.profile = profile;\r\n\t}\r\n}\r\n<\/pre>\n<p>Profile \u3068 Tweet \u3092\u9023\u643a\u3059\u308b\u3002<\/p>\n<p>Profile.java<\/p>\n<pre class=\"brush: java; highlight: [29,30,56,57,58,59,60,61,62]; title: ; notranslate\" title=\"\">\r\npackage jp.abc;\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.GenerationType;\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 Profile {\r\n    @Id\r\n    @GeneratedValue(strategy = GenerationType.AUTO)\r\n    @Column\r\n    @NotNull\r\n    private long id;\r\n\r\n    @Column(length = 200, nullable = false)\r\n    @NotEmpty\r\n    private String username;\r\n\r\n    @Column\r\n    private String profile;\r\n\r\n    @OneToMany\r\n    private List&lt;Tweet&gt; tweets;\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 getUsername() {\r\n\t\treturn username;\r\n\t}\r\n\r\n\tpublic void setUsername(String username) {\r\n\t\tthis.username = username;\r\n\t}\r\n\r\n\tpublic String getProfile() {\r\n\t\treturn profile;\r\n\t}\r\n\r\n\tpublic void setProfile(String profile) {\r\n\t\tthis.profile = profile;\r\n\t}\r\n\r\n\tpublic List&lt;Tweet&gt; getTweets() {\r\n\t\treturn tweets;\r\n\t}\r\n\r\n\tpublic void setTweets(List&lt;Tweet&gt; tweets) {\r\n\t\tthis.tweets = tweets;\r\n\t}\r\n\r\n}\r\n<\/pre>\n<p>HTML\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u306b\u6295\u7a3f\u7528\u30d5\u30a9\u30fc\u30e0\u3092\u8ffd\u52a0\u3059\u308b\u3002<\/p>\n<p>mypage.html<\/p>\n<pre class=\"brush: xml; first-line: 7; highlight: [11,12,13,14,15]; title: ; notranslate\" title=\"\">\r\n&lt;body&gt;\r\n    &lt;h1&gt;\u30de\u30a4\u30da\u30fc\u30b8&lt;\/h1&gt;\r\n    &lt;p&gt;\u3088\u3046\u3053\u305d\u3001&lt;span th:text=&quot;${username}&quot;&gt;&lt;\/span&gt;\u3055\u3093\uff01&lt;\/p&gt;\r\n    &lt;p th:text=&quot;${profile.username}&quot;&gt;&lt;\/p&gt;\r\n    &lt;form th:action=&quot;@{\/tweet}&quot; th:object=&quot;${tweet}&quot;&gt;\r\n    \t&lt;textarea name=&quot;content&quot; cols=&quot;40&quot; rows=&quot;10&quot;&gt;&lt;\/textarea&gt;\r\n    \t&lt;br \/&gt;\r\n    \t&lt;input type=&quot;submit&quot; value=&quot;\u30c4\u30a4\u30fc\u30c8\u3059\u308b&quot; \/&gt;\r\n    &lt;\/form&gt;\r\n    &lt;form th:action=&quot;@{\/logout}&quot; method=&quot;post&quot;&gt;\r\n        &lt;input type=&quot;submit&quot; value=&quot;\u30ed\u30b0\u30a2\u30a6\u30c8&quot; \/&gt;\r\n    &lt;\/form&gt;\r\n&lt;\/body&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>ACID\u7279\u6027 Atomicity\u30fbConsistency\u30fbIsolation\u30fbDurability\u3092\u8003\u616e\u3057\u3066\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u3057\u3088\u3046\u3002 \u5165\u529b\u30d5\u30a3\u30fc\u30eb\u30c9\u306e\u30c1\u30a7\u30c3\u30af\u3092 username \u3068 password \u3067\u5206\u5272\u3059\u308b\u3002(Ato &hellip; <a href=\"https:\/\/2019se3.satoshis.jp\/?p=326\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;9\u67089\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\/326"}],"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=326"}],"version-history":[{"count":14,"href":"https:\/\/2019se3.satoshis.jp\/index.php?rest_route=\/wp\/v2\/posts\/326\/revisions"}],"predecessor-version":[{"id":340,"href":"https:\/\/2019se3.satoshis.jp\/index.php?rest_route=\/wp\/v2\/posts\/326\/revisions\/340"}],"wp:attachment":[{"href":"https:\/\/2019se3.satoshis.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=326"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/2019se3.satoshis.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=326"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/2019se3.satoshis.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=326"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}