{"id":628,"date":"2019-10-21T21:52:19","date_gmt":"2019-10-21T13:52:19","guid":{"rendered":"http:\/\/toradora.xyz\/?p=628"},"modified":"2019-10-21T21:52:19","modified_gmt":"2019-10-21T13:52:19","slug":"%e7%9b%b8%e5%86%8c%e5%8a%9f%e8%83%bd%e7%9a%84%e5%ae%9e%e7%8e%b0","status":"publish","type":"post","link":"https:\/\/diuut.com\/?p=628","title":{"rendered":"\u76f8\u518c\u529f\u80fd\u7684\u5b9e\u73b0"},"content":{"rendered":"\n<p>\u63d0\u4f9b\u597d\u7684\u6709album\u6a21\u677f\u754c\u9762\uff0c\u4e0a\u4f20\u7ec4\u4ef6\uff0cpojo\u7c7b\uff0calbumService\u63a5\u53e3\uff0calbum\u901a\u7528Mapper\uff0c\u6570\u636e\u5e93\u8868\u3002<\/p>\n\n\n\n<p>\u9996\u5148\u5206\u6790\u6570\u636e\u5e93\u8868\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/blog-diuut-xyz.oss-cn-beijing.aliyuncs.com\/image\/2019\/10\/20191021211522.jpg\" alt=\"\"\/><figcaption>\u76f8\u518c\u6570\u636e\u5e93\u6574\u4f53\u53ea\u6709\u4e00\u5f20\u8868\uff0c\u4e3b\u952e\u4e3a\u76f8\u518cid\uff0c\u76f8\u518c\u5185\u7684\u56fe\u7247\u662f\u7531url\uff0cuid\uff0cstatus\u7ec4\u6210\u7684json\u5b57\u7b26\u4e32\u6570\u7ec4\u5171\u540c\u5b58\u5728\u4e00\u6761\u76f8\u518c\u7684\u4e00\u4e2a\u5b57\u6bb5\u4e2d\uff0c\u6240\u4ee5\u5f97\u51fa\u7ed3\u8bba\u65b0\u5efa\u76f8\u518c\u7684\u64cd\u4f5c\u662finsert\u4e00\u6761\u6570\u636e\u5e93\u5b57\u6bb5\uff0c\u800c\u6dfb\u52a0\u5220\u9664\u76f8\u518c\u5185\u7684\u56fe\u7247\u5219\u662f\u5bf9\u8be5\u5b57\u6bb5\u7684json\u6570\u7ec4\u8fdb\u884c\u4fee\u6539\uff0c\u56e0\u6b64\u5c31\u662f\u5bf9\u8fd9\u6761\u76f8\u518c\u6570\u636e\u5e93\u7684update\u64cd\u4f5c\u3002\u9ebb\u70e6\u7684\u5730\u65b9\u5c31\u662f\u5bf9\u4e8e\u8be5\u5b57\u6bb5json\u6570\u7ec4\u7684\u589e\u5220\u8f6c\u6362\u3002<\/figcaption><\/figure>\n\n\n\n<p>\u524d\u7aef\u65b9\u9762\u7684\u601d\u8def\uff1a\u56e0\u4e3a\u5206\u4e3a\u76f8\u518c\u5217\u8868\u548c\u76f8\u518c\u8be6\u60c5\uff0c\u6240\u4ee5\u9700\u8981\u4e24\u4e2a\u9875\u9762\u624d\u65b9\u4fbf\u5c55\u793a\u4e0d\u540c\u7684\u64cd\u4f5c\uff0c\u76f4\u63a5\u590d\u5236\u4e2aalbum\u754c\u9762\uff0c\u901a\u8fc7\u4fee\u6539\u6309\u94ae\u548c\u8868\u683c\u663e\u793a\u4f53\u73b0\u51fa\u5217\u8868\u4e0e\u8be6\u60c5\u7684\u533a\u522b\u3002\u76f8\u518c\u5217\u8868\u754c\u9762\u663e\u793a\u6240\u6709\u76f8\u518c\uff0c\u7136\u540e\u70b9\u51fb\u67e5\u770b\u76f8\u518c\uff0c\u5e26\u4e0a\u76f8\u518cid\u8df3\u8f6c\u81f3\u76f8\u518c\u8be6\u60c5\u9875\u9762\uff0c\u5728\u76f8\u518c\u8be6\u60c5\u9875\u9762\u901a\u8fc7\u622a\u53d6\u65b9\u5f0f\u83b7\u53d6id\u540e\u518d\u53d1\u9001\u8bf7\u6c42\u83b7\u53d6\u76f8\u518c\u8be6\u60c5\uff0c\u518d\u5c06imageItems\u4e2d\u56fe\u7247\u8bfb\u53d6\u5c55\u793a\u51fa\u6765\u3002<\/p>\n\n\n\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\naxios.get(`\/album\/findById.do?id=${window.location.href.split(&quot;id=&quot;)[1]}`)\n<\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/blog-diuut-xyz.oss-cn-beijing.aliyuncs.com\/image\/2019\/10\/20191021212515.jpg\" alt=\"\"\/><figcaption>\u76f8\u518c\u5217\u8868<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/blog-diuut-xyz.oss-cn-beijing.aliyuncs.com\/image\/2019\/10\/20191021212545.jpg\" alt=\"\"\/><figcaption>\u76f8\u518c\u8be6\u60c5<\/figcaption><\/figure>\n\n\n\n<p>\u540e\u7aefservice\u5c42\uff1a\u5229\u7528\u73b0\u6210\u7684Service\u63a5\u53e3\u4e2d\u7b80\u5355\u7684\u589e\u5220\u67e5\u6539\u8fdb\u884c\u7ec4\u5408\uff0c\u4e3b\u8981\u5728controller\u5c42\u8fdb\u884c\u7f16\u5199<\/p>\n\n\n\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\n    @PostMapping(&quot;\/add&quot;)\n    public Result add(@RequestBody Album album){\n        \/\/\u76f8\u518c\u7684\u4e0a\u4f20\n        albumService.add(album);\n        return new Result();\n    }\n\n    @PostMapping(&quot;\/update&quot;)\n    public Result update(@RequestBody Album album){\n        \/\/\u4e3b\u8981\u7528\u4e8e\u76f8\u518c\u4e2d\u56fe\u7247\u5217\u8868\u5b57\u6bb5\u7684\u589e\u5220\n        albumService.update(album);\n        return new Result();\n    }\n    @GetMapping(&quot;\/delete&quot;)\n    public Result delete(Long id){\n        \/\/\u5220\u9664\u76f8\u518c\n        albumService.delete(id);\n        return new Result();\n    }\n\n<\/pre>\n\n\n\n<p>\u524d\u7aef\u663e\u793a\uff1a\u4e2a\u4eba\u611f\u89c9\u6700\u9ebb\u70e6\u7684\u5c31\u662f\u524d\u7aef\u5bf9\u4e8e\u56fe\u7247\u8be6\u60c5\u5b57\u6bb5\u7684\u589e\u5220\u64cd\u4f5c\uff0c\u56e0\u4e3a\u4f20\u8fc7\u6765\u7684\u5176\u5b9e\u53ea\u662f\u4e00\u6bb5String\u5b57\u7b26\u4e32\uff0c\u9700\u8981\u5148\u8f6c\u6362\u6210json\u6570\u7ec4\uff0c\u7136\u540e\u518d\u8fdb\u884c\u67e5\u6539\u3002<\/p>\n\n\n\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\n&amp;lt;!---------\u56fe\u7247\u8be6\u60c5\u663e\u793a\u90e8\u5206\u4ee3\u7801---------&amp;gt;\n            &amp;lt;el-table :data=&quot;tableData&quot; border style=&quot;width: 100%&quot;&amp;gt;\n                &amp;lt;el-table-column prop=&quot;images&quot; label=&quot;\u76f8\u518c\u56fe\u7247&quot; width=&quot;250&quot;&amp;gt;\n                    &amp;lt;template slot-scope=&quot;scope&quot;&amp;gt;\n                        &amp;lt;img width=&quot;230px&quot; height=&quot;230px&quot; :src=&quot;scope.row.url&quot;&amp;gt;\n                    &amp;lt;\/template&amp;gt;\n                &amp;lt;\/el-table-column&amp;gt;\n                &amp;lt;el-table-column\n                        label=&quot;\u64cd\u4f5c&quot;&amp;gt;\n                    &amp;lt;template slot-scope=&quot;scope&quot;&amp;gt;\n                        &amp;lt;el-button @click=&quot;dele(scope.row.uid)&quot; size=&quot;mini&quot; type=&quot;danger&quot; size=&quot;small&quot;&amp;gt;\u5220\u9664&amp;lt;\/el-button&amp;gt;\n                    &amp;lt;\/template&amp;gt;\n                &amp;lt;\/el-table-column&amp;gt;\n            &amp;lt;\/el-table&amp;gt;\n\n\n&amp;lt;!----------\u8bf7\u6c42\u90e8\u5206\u4ee3\u7801----------&amp;gt;\n\n new Vue({\n        el: '#app',\n        data() {\n            return {\n                tableData: [],\n                searchMap: {},\n                pojo: {},\n                formVisible: false,\n                imageUrl: '',\n                items: [],\n                images:[null],\n                id: &quot;&quot;\n            }\n        },\n        created() {\n            this.fetchData();\n        },\n\n        methods: {\n            fetchData() {\n                axios.get(`\/album\/findById.do?id=${window.location.href.split(&quot;id=&quot;)[1]}`).then(response =&amp;gt; {\n                    this.items = response.data.imageItems;\n                    this.pojo.title = response.data.title;\n                    this.id = response.data.id;\n                    this.images = JSON.parse(this.items);\n                    this.tableData = this.images;\n                });\n            },\n            save() {\n                \/\/\u76f8\u518c\u8be6\u60c5\u9875\u9762\u5411\u76f8\u518c\u4e2d\u6dfb\u52a0\u56fe\u7247\n                let json = {&quot;url&quot;: this.imageUrl, &quot;uid&quot;: this.get_uuid(), &quot;status&quot;: &quot;success&quot;};\n                this.images.push(json);\n                this.pojo.id = this.id;\n                this.pojo.imageItems = this.images;\n                axios.post(`\/album\/update.do`, this.pojo).then(response =&amp;gt; {\n                    this.fetchData(); \/\/\u5237\u65b0\u5217\u8868\n                    this.formVisible = false;\/\/\u5173\u95ed\u7a97\u53e3\n                });\n            },\n            get_uuid() {\n                var s = [];\n                var hexDigits = &quot;0123456789abcdef&quot;;\n                for (var i = 0; i &amp;lt; 36; i++) {\n                    s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);\n                }\n                s[14] = &quot;4&quot;;\n                s[19] = hexDigits.substr((s[19] &amp;amp; 0x3) | 0x8, 1);\n                s[8] = s[13] = s[18] = s[23] = &quot;-&quot;;\n\n                var uuid = s.join(&quot;&quot;);\n                return uuid;\n            },\n            dele(uid) {\n                this.$confirm('\u786e\u5b9a\u8981\u5220\u9664\u6b64\u8bb0\u5f55\u5417?', '\u63d0\u793a', {\n                    confirmButtonText: '\u786e\u5b9a',\n                    cancelButtonText: '\u53d6\u6d88',\n                    type: 'warning'\n                }).then(() =&amp;gt; {\n                    this.pojo.id = this.id;\n                    for (let i = 0; i &amp;lt; this.images.length; i++) {\n                        if (this.images[i].uid == uid) {         \/\/\u6839\u636euid\u5224\u65ad\u5220\u9664json\u5b57\u6bb5\n                            this.images.splice(i, 1)\n                        }\n                    }\n                    this.pojo.id = this.id;\n                    this.pojo.imageItems = this.images;\n                    axios.post(`\/album\/update.do`, this.pojo).then(response =&amp;gt; {\n                        this.fetchData(); \/\/\u5237\u65b0\u5217\u8868\n                    })\n                })\n            }\n<\/pre>\n\n\n\n<p>\u6b64\u5916\u8fd8\u6709\u4e2a\u95ee\u9898\u5c31\u662f\u5728\u65b0\u5efa\u76f8\u518c\u7684\u65f6\u5019\uff0c\u9ed8\u8ba4\u7684\u56fe\u7247\u8be6\u60c5\u7684\u5b57\u6bb5\u4e3a\u7a7a\uff0c\u6240\u4ee5\u5728albums\u4e2d\u5982\u679c\u7b2c\u4e00\u6b21\u4e0a\u4f20\u7684\u8bdd\u4f1a\u5bfc\u81f4\u8bc6\u522b\u4e0d\u51faimages\u4e3a\u6570\u7ec4\uff0c\u6240\u4ee5\u65e0\u6cd5\u4f7f\u7528push\u65b9\u6cd5\u8fdb\u884c\u5b57\u6bb5\u6dfb\u52a0\uff0c\u6240\u4ee5\u9700\u8981\u5728album\u9875\u9762\u65b0\u5efa\u76f8\u518c\u65f6\u6dfb\u52a0\u201c[]\u201d\u5b57\u7b26\u4e32\u8fdb\u884c\u5360\u4f4d\uff0c\u4e4b\u540ealbums\u4e2d\u5c31\u53ef\u4ee5\u8fdb\u884c\u6b63\u5e38\u589e\u5220\u64cd\u4f5c\u3002<\/p>\n\n\n\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\n  save() {\n                this.pojo.image= this.imageUrl; \/\/\u5982\u9875\u9762\u6709\u56fe\u7247\u4e0a\u4f20\u529f\u80fd\u653e\u5f00\u6ce8\u91ca\n                this.pojo.imageItems=&quot;[]&quot;,\n                axios.post(`\/album\/add.do`, this.pojo).then(response =&amp;gt; {\n                    this.fetchData(); \/\/\u5237\u65b0\u5217\u8868\n                    this.formVisible = false;\/\/\u5173\u95ed\u7a97\u53e3\n                });\n            },\n<\/pre>\n\n\n\n<p>\u4ee5\u4e0a\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63d0\u4f9b\u597d\u7684\u6709album\u6a21\u677f\u754c\u9762\uff0c\u4e0a\u4f20\u7ec4\u4ef6\uff0cpojo\u7c7b\uff0calbumService\u63a5\u53e3\uff0calbum\u901a\u7528Mapper\uff0c<span class=\"more-button\"><a href=\"https:\/\/diuut.com\/?p=628\" class=\"more-link\">view all . . .<span class=\"screen-reader-text\">\u76f8\u518c\u529f\u80fd\u7684\u5b9e\u73b0<\/span><\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":633,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[],"_links":{"self":[{"href":"https:\/\/diuut.com\/index.php?rest_route=\/wp\/v2\/posts\/628"}],"collection":[{"href":"https:\/\/diuut.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/diuut.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/diuut.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/diuut.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=628"}],"version-history":[{"count":0,"href":"https:\/\/diuut.com\/index.php?rest_route=\/wp\/v2\/posts\/628\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/diuut.com\/index.php?rest_route=\/wp\/v2\/media\/633"}],"wp:attachment":[{"href":"https:\/\/diuut.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=628"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/diuut.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=628"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/diuut.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=628"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}