{"id":7221,"date":"2024-11-14T12:10:09","date_gmt":"2024-11-14T04:10:09","guid":{"rendered":"https:\/\/fwq.ai\/blog\/7221\/"},"modified":"2024-11-14T12:10:09","modified_gmt":"2024-11-14T04:10:09","slug":"java-mybatis-%e6%9f%a5%e8%af%a2-sql-%e8%bf%94%e5%9b%9e-int-%e4%b8%ba-null-%e5%a6%82%e4%bd%95%e5%a4%84%e7%90%86%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/7221\/","title":{"rendered":"Java MyBatis \u67e5\u8be2 SQL \u8fd4\u56de int \u4e3a Null \u5982\u4f55\u5904\u7406\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173061757946434.jpg\" class=\"aligncenter\" title=\"Java MyBatis \u67e5\u8be2 SQL \u8fd4\u56de int \u4e3a Null \u5982\u4f55\u5904\u7406\uff1f\u63d2\u56fe\" alt=\"Java MyBatis \u67e5\u8be2 SQL \u8fd4\u56de int \u4e3a Null \u5982\u4f55\u5904\u7406\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>java\u67e5\u8be2sql\u65f6\u8fd4\u56deint\u4e3anull\u7684\u5904\u7406<\/strong><\/p>\n<p>\u5f53\u4f7f\u7528mybatis\u67e5\u8be2\u65f6\uff0c\u5982\u679c\u671f\u671b\u8fd4\u56de\u4e00\u4e2aint\u503c\uff0c\u4f46\u5b9e\u9645\u8fd4\u56de\u4e86\u4e00\u4e2anull\u503c\uff0c\u4f1a\u5bfc\u81f4\u5f02\u5e38\u3002<\/p>\n<p>\u4ee5\u4e0b\u7ed9\u51fa\u4e24\u79cd\u53ef\u80fd\u7684\u89e3\u51b3\u65b9\u6848\uff1a<\/p>\n<ol>\n<li><strong>\u4fee\u6539\u8fd4\u56de\u503c\u7c7b\u578b<\/strong><\/li>\n<\/ol>\n<p>\u5c06\u67e5\u8be2\u65b9\u6cd5\u7684\u8fd4\u56de\u503c\u7c7b\u578b\u4eceint\u4fee\u6539\u4e3ainteger\uff0c\u8fd9\u6837\u5373\u4f7f\u6570\u636e\u5e93\u4e2d\u6ca1\u6709\u6570\u636e\u4e5f\u4e0d\u4f1a\u629b\u51fa\u5f02\u5e38\u3002\u5728\u4e1a\u52a1\u4ee3\u7801\u4e2d\uff0c\u53ef\u4ee5\u68c0\u67e5\u8fd4\u56de\u7684integer\u503c\u662f\u5426\u4e3anull\uff0c\u5c06\u5176\u8f6c\u6362\u4e3a0\u6216\u5176\u4ed6\u9ed8\u8ba4\u503c\u3002<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>@select(\"select max(id) from user\")\ninteger maxid();<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ol>\n<li><strong>\u4f7f\u7528\u6570\u636e\u5e93\u51fd\u6570<\/strong><\/li>\n<\/ol>\n<p>\u5728sql\u8bed\u53e5\u4e2d\u4f7f\u7528\u6570\u636e\u5e93\u51fd\u6570\uff0c\u5982ifnull\u6216coalesce\uff0c\u6765\u5904\u7406null\u503c\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>@Select(\"SELECT max(id) FROM user\")\n@Options(resultType = int.class, useGeneratedKeys = true)\nint maxIdWithJdbc();<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>sql\u8bed\u53e5\u4e2d\u4f7f\u7528ifnull(max(id), 0)\u8868\u8fbe\u5f0f\uff0c\u8fd9\u6837\u5982\u679c\u6ca1\u6709\u6570\u636e\uff0c\u5c06\u8fd4\u56de0\uff0c\u800c\u4e0d\u662fnull\u503c\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fJava MyBatis \u67e5\u8be2 SQL \u8fd4\u56de int \u4e3a Null \u5982\u4f55\u5904\u7406\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>java\u67e5\u8be2sql\u65f6\u8fd4\u56deint\u4e3anull\u7684\u5904\u7406 \u5f53\u4f7f\u7528mybatis\u67e5\u8be2\u65f6\uff0c\u5982\u679c\u671f\u671b\u8fd4\u56de\u4e00\u4e2aint\u503c\uff0c\u4f46\u5b9e\u9645\u8fd4\u56de\u4e86\u4e00\u4e2anull\u503c\uff0c\u4f1a\u5bfc\u81f4\u5f02\u5e38\u3002 \u4ee5\u4e0b\u7ed9\u51fa\u4e24\u79cd\u53ef\u80fd\u7684\u89e3\u51b3\u65b9\u6848\uff1a \u4fee\u6539\u8fd4\u56de\u503c\u7c7b\u578b \u5c06\u67e5\u8be2\u65b9\u6cd5\u7684\u8fd4\u56de\u503c\u7c7b\u578b\u4eceint\u4fee\u6539\u4e3ainteger\uff0c\u8fd9\u6837\u5373\u4f7f\u6570\u636e\u5e93\u4e2d\u6ca1\u6709\u6570\u636e\u4e5f\u4e0d\u4f1a\u629b\u51fa\u5f02\u5e38\u3002\u5728\u4e1a\u52a1\u4ee3\u7801\u4e2d\uff0c\u53ef\u4ee5\u68c0\u67e5\u8fd4\u56de\u7684integer\u503c\u662f\u5426\u4e3anull\uff0c\u5c06\u5176\u8f6c\u6362\u4e3a0\u6216\u5176\u4ed6\u9ed8\u8ba4\u503c\u3002 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b @select(&#8220;select max(id) from user&#8221;) integer maxid(); \u767b\u5f55\u540e\u590d\u5236 \u4f7f\u7528\u6570\u636e\u5e93\u51fd\u6570 \u5728sql\u8bed\u53e5\u4e2d\u4f7f\u7528\u6570\u636e\u5e93\u51fd\u6570\uff0c\u5982ifnull\u6216coalesce\uff0c\u6765\u5904\u7406null\u503c\u3002\u4f8b\u5982\uff1a @Select(&#8220;SELECT max(id) FROM user&#8221;) @Options(resultType = int.class, useGeneratedKeys = true) int maxIdWithJdbc(); \u767b\u5f55\u540e\u590d\u5236 sql\u8bed\u53e5\u4e2d\u4f7f\u7528ifnull(max(id), 0)\u8868\u8fbe\u5f0f\uff0c\u8fd9\u6837\u5982\u679c\u6ca1\u6709\u6570\u636e\uff0c\u5c06\u8fd4\u56de0\uff0c\u800c\u4e0d\u662fnull\u503c\u3002 \u4ee5\u4e0a\u5c31\u662fJava MyBatis \u67e5\u8be2 SQL \u8fd4\u56de int \u4e3a Null \u5982\u4f55\u5904\u7406\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-7221","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7221","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=7221"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7221\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=7221"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=7221"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=7221"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}