{"id":200644,"date":"2025-05-06T09:03:05","date_gmt":"2025-05-06T01:03:05","guid":{"rendered":"https:\/\/server.hk\/cnblog\/200644\/"},"modified":"2025-05-06T09:03:05","modified_gmt":"2025-05-06T01:03:05","slug":"java-mybatis-%e6%9f%a5%e8%af%a2%e8%bf%94%e5%9b%9e-int-%e7%b1%bb%e5%9e%8b%e5%87%ba%e7%8e%b0-null%ef%bc%8c%e5%a6%82%e4%bd%95%e9%81%bf%e5%85%8d%e5%bc%82%e5%b8%b8%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/200644\/","title":{"rendered":"Java MyBatis \u67e5\u8be2\u8fd4\u56de int \u7c7b\u578b\u51fa\u73b0 null\uff0c\u5982\u4f55\u907f\u514d\u5f02\u5e38\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>Java MyBatis \u67e5\u8be2\u8fd4\u56de int \u7c7b\u578b\u51fa\u73b0 null\uff0c\u5982\u4f55\u907f\u514d\u5f02\u5e38\uff1f<\/h1>\n<p>\u73cd\u60dc\u65f6\u95f4\uff0c\u52e4\u594b\u5b66\u4e60\uff01\u4eca\u5929\u7ed9\u5927\u5bb6\u5e26\u6765\uff0c\u6b63\u6587\u5185\u5bb9\u4e3b\u8981\u6d89\u53ca\u5230\u7b49\u7b49\uff0c\u5982\u679c\u4f60\u6b63\u5728\u5b66\u4e60\uff0c\u6216\u8005\u662f\u5bf9\u6709\u7591\u95ee\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u6211\uff01\u540e\u9762\u6211\u4f1a\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u5185\u5bb9\u7684\uff0c\u5e0c\u671b\u90fd\u80fd\u5e2e\u5230\u6b63\u5728\u5b66\u4e60\u7684\u5927\u5bb6\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241110\/1731233022673084fe35985.jpg\" class=\"aligncenter\"><\/p>\n<p>\u5728 java \u4e2d\u4f7f\u7528 mybatis \u67e5\u8be2 sql \u65f6\uff0c\u5982\u679c\u671f\u671b\u8fd4\u56de int \u7c7b\u578b\u7684\u503c\uff0c\u4f46\u5b9e\u9645\u8fd4\u56de null\uff0c\u53ef\u80fd\u4f1a\u51fa\u73b0\u5f02\u5e38\u3002<strong>\u5982\u4f55\u5904\u7406\u8fd9\u79cd\u60c5\u51b5\uff1f<\/strong><\/p>\n<p>\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u6709\u4ee5\u4e0b\u4e24\u79cd\u89e3\u51b3\u529e\u6cd5\uff1a<\/p>\n<ol>\n<li><strong>\u5c06\u8fd4\u56de\u7c7b\u578b\u6539\u4e3a integer<\/strong>\uff0c\u7136\u540e\u5728 service \u5c42\u5224\u65ad\u8fd4\u56de\u503c\u662f\u5426\u4e3a null\u3002\u5982\u679c\u662f null\uff0c\u5219\u8fd4\u56de 0\u3002<\/li>\n<li>\n<p><strong>\u5728 sql \u67e5\u8be2\u8bed\u53e5\u4e2d\u4f7f\u7528 ifnull \u7b49\u6570\u636e\u5e93\u51fd\u6570<\/strong>\u6765\u5305\u88f9 max \u51fd\u6570\uff0c\u786e\u4fdd\u5373\u4f7f\u8868\u4e2d\u6ca1\u6709\u6570\u636e\uff0c\u4e5f\u4f1a\u8fd4\u56de 0\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>SELECT ifnull(max(id), 0) FROM user<\/pre>\n<\/li>\n<\/ol>\n<p>\u672c\u7bc7\u5173\u4e8e\u300aJava MyBatis \u67e5\u8be2\u8fd4\u56de int \u7c7b\u578b\u51fa\u73b0 null\uff0c\u5982\u4f55\u907f\u514d\u5f02\u5e38\uff1f\u300b\u7684\u4ecb\u7ecd\u5c31\u5230\u6b64\u7ed3\u675f\u5566\uff0c\u4f46\u662f\u5b66\u65e0\u6b62\u5883\uff0c\u60f3\u8981\u4e86\u89e3\u5b66\u4e60\u66f4\u591a\u5173\u4e8e\u6570\u636e\u5e93\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u8bf7\u5173\u6ce8\u4e3b\u673a\u5b9d\u8d1d\u516c\u4f17\u53f7\uff01<\/p>\n<dl>\n<dt>\n <\/dt>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>Java MyBatis \u67e5\u8be2\u8fd4&#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-200644","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200644","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=200644"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200644\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=200644"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=200644"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=200644"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}