{"id":785,"date":"2025-04-26T23:05:56","date_gmt":"2025-04-26T14:05:56","guid":{"rendered":"https:\/\/hirabay.net\/?p=785"},"modified":"2025-04-27T15:40:52","modified_gmt":"2025-04-27T06:40:52","slug":"%e3%80%90mybatis%e3%80%911%e5%af%be%e5%a4%9a%e3%81%ae%e3%83%86%e3%83%bc%e3%83%96%e3%83%ab%e7%b5%90%e5%90%88%e7%b5%90%e6%9e%9c%e3%82%92%e6%a7%8b%e9%80%a0%e5%8c%96%e3%81%97%e3%81%a6%e5%8f%97%e3%81%91","status":"publish","type":"post","link":"https:\/\/hirabay.net\/?p=785","title":{"rendered":"\u3010MyBatis\u30111\u5bfe\u591a\u306e\u30c6\u30fc\u30d6\u30eb\u7d50\u5408\u7d50\u679c\u3092\u69cb\u9020\u5316\u3057\u3066\u53d7\u3051\u53d6\u308b"},"content":{"rendered":"\n<p>\uff11\u5bfe\u591a\u306e\u30c6\u30fc\u30d6\u30eb\u7d50\u5408\u3092\u884c\u3046\u3068SQL\u306e\u7d50\u679c\u3068\u3057\u3066\u306f\u3001\uff11\u5074\u306e\u30c6\u30fc\u30d6\u30eb\u306e\u91cd\u8907\u3057\u305f\u30c7\u30fc\u30bf\u3068\u3001\u591a\u5074\u306e\u30c7\u30fc\u30bf\u304c\u30d5\u30e9\u30c3\u30c8\u306b\u8fd4\u3063\u3066\u304d\u3066\u3057\u307e\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u305f\u3060\u3001\u696d\u52d9\u30ed\u30b8\u30c3\u30af\u3067\u6271\u3046\u306b\u306f\u968e\u5c64\u304c\u660e\u78ba\u306b\u306a\u3063\u3066\u3044\u305f\u65b9\u304c\u826f\u3044\u3053\u3068\u304c\u3042\u308a\u3001<br>\u968e\u5c64\u5316\u3059\u308b\u305f\u3081\u306b\u30eb\u30fc\u30d7\u3067\u30b0\u30eb\u30fc\u30d4\u30f3\u30b0\u3057\u3066\u30fc\u3068\u3044\u3046\u51e6\u7406\u304c\u5fc5\u8981\u306b\u306a\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u3002\u3002\u3002<\/p>\n\n\n\n<p>\u3068\u601d\u3063\u3066\u3044\u305f\u3089\u3001MyBatis\u5074\u3067\u3053\u3093\u306a\u3053\u3068\u3057\u306a\u304f\u3066\u6a5f\u80fd\u304c\u63d0\u4f9b\u3055\u308c\u3066\u3044\u307e\u3057\u305f\uff01<\/p>\n\n\n\n<div class=\"toc\"><br \/>\n<b>Warning<\/b>:  Undefined array key \"is_admin\" in <b>\/home\/c4179872\/public_html\/hirabay.net\/wp-content\/themes\/sango-theme\/library\/gutenberg\/dist\/classes\/Toc.php<\/b> on line <b>110<\/b><br \/>\n<br \/>\n<b>Warning<\/b>:  Undefined array key \"is_category_top\" in <b>\/home\/c4179872\/public_html\/hirabay.net\/wp-content\/themes\/sango-theme\/library\/gutenberg\/dist\/classes\/Toc.php<\/b> on line <b>115<\/b><br \/>\n<br \/>\n<b>Warning<\/b>:  Undefined array key \"is_top\" in <b>\/home\/c4179872\/public_html\/hirabay.net\/wp-content\/themes\/sango-theme\/library\/gutenberg\/dist\/classes\/Toc.php<\/b> on line <b>122<\/b><br \/>\n    <div id=\"toc_container\" class=\"sgb-toc--bullets js-smooth-scroll\">\n      <p class=\"toc_title\">\u76ee\u6b21 <\/p>\n      <ul class=\"toc_list\">\n  <li class=\"first\">\n    <a href=\"#i-0\">\u524d\u63d0<\/a>\n  <\/li>\n  <li>\n    <a href=\"#i-1\">\u5b9f\u73fe\u65b9\u6cd5<\/a>\n  <\/li>\n  <li class=\"last\">\n    <a href=\"#i-2\">\u304a\u307e\u3051\uff081\u5bfe1\u306e\u5834\u5408\uff09<\/a>\n  <\/li>\n<\/ul>\n\n      \n    <\/div><\/div><h2 class=\"wp-block-heading\" id=\"i-0\">\u524d\u63d0<\/h2>\n\n\n\n<p>\u4ee5\u4e0b\u306e\u30c6\u30fc\u30d6\u30eb\u69cb\u6210\u3067\u3084\u3063\u3066\u307f\u307e\u3059\uff01<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism undefined-numbers lang-sql\" data-lang=\"SQL\"><code>CREATE TABLE IF NOT EXISTS TODO_LIST (\n    id    VARCHAR(10) NOT NULL,\n    title VARCHAR(10),\n    created_by VARCHAR(10), -- \u4f5c\u6210\u8005\n    created_at TIMESTAMP, -- \u4f5c\u6210\u65e5\u6642\n    PRIMARY KEY(id)\n);\n\nCREATE TABLE IF NOT EXISTS TODO_ITEM_COMMENT (\n    todo_list_id VARCHAR(10) NOT NULL,\n    comment_id VARCHAR(10) NOT NULL,\n    comment VARCHAR(100),\n    PRIMARY KEY(todo_list_id, comment_id)\n);<\/code><\/pre><\/div>\n\n\n\n<p>TODO\u30ea\u30b9\u30c8\u3068\u3001\u30ea\u30b9\u30c8\u306e\u30a2\u30a4\u30c6\u30e0\u305d\u308c\u305e\u308c\u306b\u30b3\u30e1\u30f3\u30c8\u304c\u8907\u6570\u4ef6\u7d10\u3065\u304f\u307f\u305f\u3044\u306a\u30a4\u30e1\u30fc\u30b8\u3067\u3059\uff01<\/p>\n\n\n\n<p>\u76ee\u6a19\u306f\u3053\u3093\u306aEntity\u30af\u30e9\u30b9\u3067\u7d50\u679c\u3092\u53d7\u3051\u53d6\u308b\u3053\u3068<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism undefined-numbers lang-java\" data-lang=\"Java\"><code>public class TodoList {\n    private String title;\n    private String id;\n    private String updatedBy;\n    private List&lt;TodoItemComment&gt; comments;\n}\n\npublic class TodoItemComment {\n    private String todoListId;\n    private String commentId;\n    private String comment;\n}<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"i-1\">\u5b9f\u73fe\u65b9\u6cd5<\/h2>\n\n\n\n<p>Mybatis\u306e\u30de\u30c3\u30d1\u30fc\u5411\u3051\u306exml\u306b <code>&lt;resultMap&gt;<\/code>\u3068\u3044\u3046\u5b9a\u7fa9\u3092\u3059\u308b\u3053\u3068\u3067\u5b9f\u73fe\u3067\u304d\u307e\u3059\uff01<\/p>\n\n\n\n<p>\u4ee5\u4e0b<code>&lt;resultMap&gt;<\/code>\u542b\u3081\u305f\u5168\u6587\u3067\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism undefined-numbers lang-plain\"><code>&lt;?xml version=\"1.0\" encoding=\"UTF-8\" ?&gt;\n&lt;!DOCTYPE mapper\n        PUBLIC \"-\/\/mybatis.org\/\/DTD Mapper 3.0\/\/EN\"\n        \"http:\/\/mybatis.org\/dtd\/mybatis-3-mapper.dtd\"&gt;\n&lt;mapper namespace=\"hirabay.mybatis.mapper.TodoListMapper\"&gt;\n  &lt;resultMap id=\"todoListWithComment\" type=\"hirabay.mybatis.entity.TodoList\" autoMapping=\"true\"&gt;\n    &lt;id column=\"id\" property=\"id\" \/&gt;\n    &lt;collection property=\"comments\" ofType=\"hirabay.mybatis.entity.TodoItemComment\" autoMapping=\"true\"\/&gt;\n  &lt;\/resultMap&gt;\n\n  &lt;select id=\"findByIdWithComment\" resultMap=\"todoListWithComment\"&gt;\n    select tl.id, tl.title, tic.todo_list_id, tic.comment_id as comment_id, tic.comment\n    from todo_list tl\n    left join todo_item_comment tic on tic.todo_list_id = tl.id\n    where tl.id = #{id}\n  &lt;\/select&gt;\n&lt;\/mapper&gt;<\/code><\/pre><\/div>\n\n\n\n<p>\u30dd\u30a4\u30f3\u30c8<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>&lt;id&gt;\u3067\u30b0\u30eb\u30fc\u30d4\u30f3\u30b0\u3059\u308b\u30ab\u30e9\u30e0\u3092\u6307\u5b9a\u3059\u308b\n<ul class=\"wp-block-list\">\n<li>\u3053\u3053\u3067\u306f <code>ID<\/code> \u30ab\u30e9\u30e0\u3092\u6307\u5b9a\u3057\u3066\u3044\u308b\u305f\u3081\u3001ID\u306e\u5024\u304c\u540c\u3058\u3060\u3068\u540c\u3058\u30b0\u30eb\u30fc\u30d7\u3060\u3068\u8a8d\u8b58\u3057\u3066\u51e6\u7406\u304c\u5b9f\u884c\u3055\u308c\u308b<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>&lt;collection&gt;\u3067\u30ea\u30b9\u30c8\u3067\u53d7\u3051\u53d6\u308a\u305f\u3044\u30af\u30e9\u30b9\u3092\u6307\u5b9a\u3059\u308b<\/li>\n\n\n\n<li><code>autoMapping=\"true\"<\/code> \u5909\u306b\u5909\u63db\u304c\u5fc5\u8981\u306a\u30b1\u30fc\u30b9\u3092\u306e\u305e\u3044\u3066\u3001\u3053\u306e\u8a2d\u5b9a\u3092\u3057\u3066\u304a\u304f\u3068\u52dd\u624b\u306b\u30ab\u30e9\u30e0\u3068\u30d5\u30a3\u30fc\u30eb\u30c9\u3092\u30de\u30c3\u30d4\u30f3\u30b0\u3057\u3066\u304f\u308c\u308b<\/li>\n<\/ul>\n\n\n\n<p>\u7d50\u679c\u6ce2\u3053\u3093\u306a\u611f\u3058<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism undefined-numbers lang-json\" data-lang=\"JSON\"><code>{\n  \"title\": \"title1\",\n  \"id\": \"1\",\n  \"updatedBy\": null,\n  \"comments\": [\n    {\n      \"todoListId\": \"1\",\n      \"commentId\": \"1\",\n      \"comment\": \"comment1-1\"\n    },\n    {\n      \"todoListId\": \"1\",\n      \"commentId\": \"2\",\n      \"comment\": \"comment1-2\"\n    },\n    {\n      \"todoListId\": \"1\",\n      \"commentId\": \"3\",\n      \"comment\": \"comment1-3\"\n    }\n  ]\n}<\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"i-2\">\u304a\u307e\u3051\uff081\u5bfe1\u306e\u5834\u5408\uff09<\/h2>\n\n\n\n<p>\u3053\u3093\u306a\u30b9\u30c6\u30fc\u30bf\u30b9\u7ba1\u7406\u3059\u308b\u30c6\u30fc\u30d6\u30eb\u304c\u3042\u308b\u3068\u3057\u307e\u3059\uff08TODO_LIST\u3068\u4e00\u7dd2\u3067\u3044\u3044\u3058\u3083\u3093\u3068\u304b\u306f\u3054\u5bb9\u8d66\u3092\u301c\uff09<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism undefined-numbers lang-plain\"><code>CREATE TABLE IF NOT EXISTS TODO_LIST_STATUS (\n    id    VARCHAR(10) NOT NULL,\n    status VARCHAR(10),\n    PRIMARY KEY(id)\n);<\/code><\/pre><\/div>\n\n\n\n<p>\u3053\u308c\u3092\u4ee5\u4e0b\u306eEntity\u3067\u53d7\u3051\u53d6\u308a\u305f\u3044\u3068\u3057\u307e\u3059<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism undefined-numbers lang-java\" data-lang=\"Java\"><code>public class TodoList {\n    private String title;\n    private String id;\n    private String updatedBy;\n    private TodoListStatus status;\n}\n\npublic class TodoListStatus {\n    private String id;\n    private String status;\n}<\/code><\/pre><\/div>\n\n\n\n<p>\u305d\u3093\u306a\u3068\u304d\u306f <code>&lt;association&gt;<\/code>\u3092\u4f7f\u3048\u3070OK\uff01<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism undefined-numbers lang-xml\" data-lang=\"XML\"><code>  &lt;resultMap id=\"todoListWithComment\" type=\"hirabay.mybatis.entity.TodoList\" autoMapping=\"true\"&gt;\n    &lt;id column=\"id\" property=\"id\" \/&gt;\n    &lt;association property=\"status\" javaType=\"hirabay.mybatis.entity.TodoListStatus\" autoMapping=\"true\"\/&gt;\n  &lt;\/resultMap&gt;<\/code><\/pre><\/div>\n\n\n\n<p>\u30dd\u30a4\u30f3\u30c8<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>property\u306bEntity\u30af\u30e9\u30b9\u306e\u30d5\u30a3\u30fc\u30eb\u30c9\u540d\u3092\u6307\u5b9a\u3059\u308b<\/li>\n\n\n\n<li>javaType\u306bEntity\u30af\u30e9\u30b9\u3092\u6307\u5b9a\u3059\u308b<\/li>\n\n\n\n<li><code>autoMapping=\"true\"<\/code>\u3092\u3064\u3051\u3066\u304a\u3051\u3070\u81ea\u52d5\u3067\u30ab\u30e9\u30e0\u3068\u30d5\u30a3\u30fc\u30eb\u30c9\u306e\u30de\u30c3\u30d4\u30f3\u30b0\u3092\u3057\u3066\u304f\u308c\u307e\u3059<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\uff11\u5bfe\u591a\u306e\u30c6\u30fc\u30d6\u30eb\u7d50\u5408\u3092\u884c\u3046\u3068SQL\u306e\u7d50\u679c\u3068\u3057\u3066\u306f\u3001\uff11\u5074\u306e\u30c6\u30fc\u30d6\u30eb\u306e\u91cd\u8907\u3057\u305f\u30c7\u30fc\u30bf\u3068\u3001\u591a\u5074\u306e\u30c7\u30fc\u30bf\u304c\u30d5\u30e9\u30c3\u30c8\u306b\u8fd4\u3063\u3066\u304d\u3066\u3057\u307e\u3044\u307e\u3059\u3002 \u305f\u3060\u3001\u696d\u52d9\u30ed\u30b8\u30c3\u30af\u3067\u6271\u3046\u306b\u306f\u968e\u5c64\u304c\u660e\u78ba\u306b\u306a\u3063\u3066\u3044\u305f\u65b9\u304c\u826f\u3044\u3053\u3068\u304c\u3042\u308a\u3001\u968e\u5c64\u5316\u3059\u308b\u305f\u3081\u306b\u30eb &#8230; <\/p>\n","protected":false},"author":1,"featured_media":786,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[116],"class_list":{"0":"post-785","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-6","8":"tag-mybatis"},"jetpack_featured_media_url":"https:\/\/hirabay.net\/wp-content\/uploads\/2025\/04\/SpringBoot-1.png","_links":{"self":[{"href":"https:\/\/hirabay.net\/index.php?rest_route=\/wp\/v2\/posts\/785","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hirabay.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hirabay.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hirabay.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hirabay.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=785"}],"version-history":[{"count":2,"href":"https:\/\/hirabay.net\/index.php?rest_route=\/wp\/v2\/posts\/785\/revisions"}],"predecessor-version":[{"id":789,"href":"https:\/\/hirabay.net\/index.php?rest_route=\/wp\/v2\/posts\/785\/revisions\/789"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/hirabay.net\/index.php?rest_route=\/wp\/v2\/media\/786"}],"wp:attachment":[{"href":"https:\/\/hirabay.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=785"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hirabay.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=785"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hirabay.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=785"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}