{"id":200808,"date":"2025-05-06T10:20:54","date_gmt":"2025-05-06T02:20:54","guid":{"rendered":"https:\/\/server.hk\/cnblog\/200808\/"},"modified":"2025-05-06T10:20:54","modified_gmt":"2025-05-06T02:20:54","slug":"mybatis-%e4%b8%ad%e5%a6%82%e4%bd%95%e5%a4%84%e7%90%86%e7%89%b9%e6%ae%8a%e5%ad%97%e7%ac%a6%e5%af%bc%e8%87%b4%e7%9a%84-sql-%e8%af%ad%e6%b3%95%e9%94%99%e8%af%af%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/200808\/","title":{"rendered":"MyBatis \u4e2d\u5982\u4f55\u5904\u7406\u7279\u6b8a\u5b57\u7b26\u5bfc\u81f4\u7684 SQL \u8bed\u6cd5\u9519\u8bef\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>MyBatis \u4e2d\u5982\u4f55\u5904\u7406\u7279\u6b8a\u5b57\u7b26\u5bfc\u81f4\u7684 SQL \u8bed\u6cd5\u9519\u8bef\uff1f<\/h1>\n<p>\u54c8\u55bd\uff01\u4eca\u5929\u5fc3\u8840\u6765\u6f6e\u7ed9\u5927\u5bb6\u5e26\u6765\u4e86\uff0c\u60f3\u5fc5\u5927\u5bb6\u5e94\u8be5\u5bf9\u90fd\u4e0d\u964c\u751f\u5427\uff0c\u90a3\u4e48\u9605\u8bfb\u672c\u6587\u5c31\u90fd\u4e0d\u4f1a\u5f88\u56f0\u96be\uff0c\u4ee5\u4e0b\u5185\u5bb9\u4e3b\u8981\u6d89\u53ca\u5230\uff0c\u82e5\u662f\u4f60\u6b63\u5728\u5b66\u4e60\uff0c\u5343\u4e07\u522b\u9519\u8fc7\u8fd9\u7bc7\u6587\u7ae0~\u5e0c\u671b\u80fd\u5e2e\u52a9\u5230\u4f60\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241115\/173166413367371905adb54.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>\u4f7f\u7528 mybatis \u65f6\u5904\u7406\u7279\u6b8a\u5b57\u7b26\u7684\u5b57\u7b26\u4e32<\/strong><\/p>\n<p>\u6570\u636e\u5e93\u8868\u4e2d\u5b58\u5728\u7279\u6b8a\u7b26\u53f7\u65f6\uff0c\u901a\u8fc7 mybatis \u8fdb\u884c\u66f4\u65b0\u64cd\u4f5c\u53ef\u80fd\u4f1a\u9047\u5230\u95ee\u9898\u3002\u4f8b\u5982\uff0c\u5982\u679c\u5c06\u7279\u6b8a\u7b26\u53f7\u4f5c\u4e3a\u53c2\u6570\u503c\u4f20\u5165\uff0c\u53ef\u80fd\u4f1a\u89e6\u53d1\u8bed\u6cd5\u9519\u8bef\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u4ee5\u4e0b mybatis \u66f4\u65b0\u8bed\u53e5\u53ef\u80fd\u4f1a\u5bfc\u81f4\u95ee\u9898\uff1a<\/p>\n<pre>    &lt;update id=\"update\"&gt;\n        update d_table set\n        separator = #{separator, jdbctype=varchar}\n        where id = #{id, jdbctype=bigint}\n    &lt;\/update&gt;<\/pre>\n<p>\u5982\u679c separator \u4f20\u5165\u7684\u503c\u662f\u7279\u6b8a\u7b26\u53f7\uff0c\u5982 ? \u6216 !\uff0c\u5219\u4f1a\u5f15\u53d1\u9519\u8bef\u3002<\/p>\n<pre>### error updating database.  cause: java.sql.sqlsyntaxerrorexception: you have an error in your sql syntax; check the manual that corresponds to your mysql server version for the right syntax to use near 'separator = '!'  \n...<\/pre>\n<p><strong>\u89e3\u51b3\u65b9\u6848<\/strong><\/p>\n<p>\u95ee\u9898\u5728\u4e8e\uff0cseparator \u672c\u8eab\u662f\u4e00\u4e2a\u5173\u952e\u8bcd\u3002\u89e3\u51b3\u65b9\u6cd5\u662f\u4f7f\u7528\u53cd\u5f15\u53f7\uff08&#8221;\uff09\u5c06\u5217\u540d\u62ec\u8d77\u6765\uff0c\u4ece\u800c\u907f\u514d\u5173\u952e\u5b57\u51b2\u7a81\uff1a<\/p>\n<pre>    &lt;update id=\"update\"&gt;\n        UPDATE d_table SET\n        `separator` = #{separator, jdbcType=VARCHAR}\n        WHERE id = #{id, jdbcType=BIGINT}\n    &lt;\/update&gt;<\/pre>\n<p>\u4f7f\u7528\u53cd\u5f15\u53f7\u540e\uff0c\u5373\u4f7f\u53c2\u6570\u503c\u5305\u542b\u7279\u6b8a\u7b26\u53f7\uff0c\u4e5f\u80fd\u6b63\u5e38\u66f4\u65b0\u6570\u636e\u5e93\u3002<\/p>\n<p>\u7406\u8bba\u8981\u638c\u63e1\uff0c\u5b9e\u64cd\u4e0d\u80fd\u843d\uff01\u4ee5\u4e0a\u5173\u4e8e\u300aMyBatis \u4e2d\u5982\u4f55\u5904\u7406\u7279\u6b8a\u5b57\u7b26\u5bfc\u81f4\u7684 SQL \u8bed\u6cd5\u9519\u8bef\uff1f\u300b\u7684\u8be6\u7ec6\u4ecb\u7ecd\uff0c\u5927\u5bb6\u90fd\u638c\u63e1\u4e86\u5427\uff01\u5982\u679c\u60f3\u8981\u7ee7\u7eed\u63d0\u5347\u81ea\u5df1\u7684\u80fd\u529b\uff0c\u90a3\u4e48\u5c31\u6765\u5173\u6ce8\u4e3b\u673a\u5b9d\u8d1d\u516c\u4f17\u53f7\u5427\uff01<\/p>\n<dl>\n<dt>\n <\/dt>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>MyBatis \u4e2d\u5982\u4f55\u5904\u7406\u7279\u6b8a\u5b57&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-200808","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200808","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=200808"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200808\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=200808"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=200808"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=200808"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}