{"id":25648,"date":"2024-11-24T09:30:57","date_gmt":"2024-11-24T01:30:57","guid":{"rendered":"https:\/\/fwq.ai\/blog\/25648\/"},"modified":"2024-11-24T09:30:57","modified_gmt":"2024-11-24T01:30:57","slug":"jpa-%e5%8a%a8%e6%80%81%e6%9d%a1%e4%bb%b6-sql-%e4%b8%ad%e5%a6%82%e4%bd%95%e4%bc%98%e9%9b%85%e5%a4%84%e7%90%86-null-%e5%80%bc%ef%bc%9f-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/25648\/","title":{"rendered":"JPA \u52a8\u6001\u6761\u4ef6 SQL \u4e2d\u5982\u4f55\u4f18\u96c5\u5904\u7406 NULL \u503c\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173064475648634.jpg\" class=\"aligncenter\" title=\"JPA \u52a8\u6001\u6761\u4ef6 SQL \u4e2d\u5982\u4f55\u4f18\u96c5\u5904\u7406 NULL \u503c\uff1f\u63d2\u56fe\" alt=\"JPA \u52a8\u6001\u6761\u4ef6 SQL \u4e2d\u5982\u4f55\u4f18\u96c5\u5904\u7406 NULL \u503c\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5728 JPA \u52a8\u6001\u6761\u4ef6 SQL \u4e2d\u4f7f\u7528 IFNULL<\/strong><\/p>\n<p>\u5728\u4f7f\u7528 JPA \u8fdb\u884c\u591a\u8868\u8054\u5408\u52a8\u6001 SQL \u67e5\u8be2\u65f6\uff0c\u5982\u679c\u9700\u8981\u5224\u65ad\u67d0\u4e2a\u5b57\u6bb5\u662f\u5426\u4e3a\u7a7a\uff0c\u53ef\u80fd\u4f1a\u4f7f\u7528 IFNULL(NULLIF(?1,&#8221;),&#8217;xxx\u5b57\u6bb5&#8217;) \u8fd9\u6837\u7684\u8868\u8fbe\u5f0f\u3002\u7136\u800c\uff0c\u8fd9\u79cd\u5199\u6cd5\u5b58\u5728\u4e00\u5b9a\u7684\u5f0a\u7aef\u3002<\/p>\n<p>\u9996\u5148\uff0c\u5b83\u589e\u52a0\u4e86 SQL \u67e5\u8be2\u7684\u590d\u6742\u6027\u3002\u5f53\u4f7f\u7528\u591a\u4e2a\u6761\u4ef6\u62fc\u63a5\u65f6\uff0c\u8fd9\u79cd\u8868\u8fbe\u5f0f\u4f1a\u4f7f SQL \u8bed\u53e5\u53d8\u5f97\u5197\u957f\u96be\u4ee5\u9605\u8bfb\uff0c\u8fd9\u5c06\u5f71\u54cd\u53ef\u7ef4\u62a4\u6027\u3002<\/p>\n<p>\u5176\u6b21\uff0c\u5b83\u5bf9 MySQL \u7684\u6027\u80fd\u6709\u635f\u8017\u3002IFNULL \u51fd\u6570\u672c\u8d28\u4e0a\u662f\u4e00\u4e2a CASE \u8868\u8fbe\u5f0f\uff0c\u5b83\u9700\u8981\u5728\u8fd0\u884c\u65f6\u8fdb\u884c\u989d\u5916\u7684\u8ba1\u7b97\uff0c\u964d\u4f4e\u67e5\u8be2\u7684\u6267\u884c\u6548\u7387\u3002<\/p>\n<p>\u6700\u540e\uff0c\u8fd9\u79cd\u5199\u6cd5\u4e0d\u7b26\u5408 SQL \u6807\u51c6\u3002\u867d\u7136\u5b83\u5728 MySQL \u4e2d\u53ef\u4ee5\u901a\u8fc7\uff0c\u4f46\u662f\u5728\u5176\u4ed6\u6570\u636e\u5e93\u7cfb\u7edf\u4e2d\u53ef\u80fd\u4f1a\u51fa\u73b0\u95ee\u9898\u3002\u4e3a\u4e86\u4fdd\u8bc1\u4ee3\u7801\u7684\u8de8\u5e73\u53f0\u517c\u5bb9\u6027\uff0c\u6700\u597d\u907f\u514d\u4f7f\u7528\u8fd9\u79cd non-standard \u7684\u5199\u6cd5\u3002<\/p>\n<p>\u6700\u4f73\u5b9e\u8df5\u662f\u5728\u4ee3\u7801\u5c42\u9762\u63a7\u5236\u6b64\u7c7b\u903b\u8f91\uff0c\u800c\u4e0d\u662f\u4f9d\u8d56\u4e8e MySQL \u7684\u51fd\u6570\u3002\u4e5f\u53ef\u4ee5\u901a\u8fc7\u4ed4\u7ec6\u8bbe\u8ba1\u8868\u7ed3\u6784\uff0c\u907f\u514d\u4f7f\u7528 NULL \u503c\uff0c\u4ee5\u63d0\u9ad8\u67e5\u8be2\u6027\u80fd\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fJPA \u52a8\u6001\u6761\u4ef6 SQL \u4e2d\u5982\u4f55\u4f18\u96c5\u5904\u7406 NULL \u503c\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 JPA \u52a8\u6001\u6761\u4ef6 SQL \u4e2d\u4f7f\u7528 IFNULL \u5728\u4f7f\u7528 JPA \u8fdb\u884c\u591a\u8868\u8054\u5408\u52a8\u6001 SQL \u67e5\u8be2\u65f6\uff0c\u5982\u679c\u9700\u8981\u5224\u65ad\u67d0\u4e2a\u5b57\u6bb5\u662f\u5426\u4e3a\u7a7a\uff0c\u53ef\u80fd\u4f1a\u4f7f\u7528 IFNULL(NULLIF(?1,&#8221;),&#8217;xxx\u5b57\u6bb5&#8217;) \u8fd9\u6837\u7684\u8868\u8fbe\u5f0f\u3002\u7136\u800c\uff0c\u8fd9\u79cd\u5199\u6cd5\u5b58\u5728\u4e00\u5b9a\u7684\u5f0a\u7aef\u3002 \u9996\u5148\uff0c\u5b83\u589e\u52a0\u4e86 SQL \u67e5\u8be2\u7684\u590d\u6742\u6027\u3002\u5f53\u4f7f\u7528\u591a\u4e2a\u6761\u4ef6\u62fc\u63a5\u65f6\uff0c\u8fd9\u79cd\u8868\u8fbe\u5f0f\u4f1a\u4f7f SQL \u8bed\u53e5\u53d8\u5f97\u5197\u957f\u96be\u4ee5\u9605\u8bfb\uff0c\u8fd9\u5c06\u5f71\u54cd\u53ef\u7ef4\u62a4\u6027\u3002 \u5176\u6b21\uff0c\u5b83\u5bf9 MySQL \u7684\u6027\u80fd\u6709\u635f\u8017\u3002IFNULL \u51fd\u6570\u672c\u8d28\u4e0a\u662f\u4e00\u4e2a CASE \u8868\u8fbe\u5f0f\uff0c\u5b83\u9700\u8981\u5728\u8fd0\u884c\u65f6\u8fdb\u884c\u989d\u5916\u7684\u8ba1\u7b97\uff0c\u964d\u4f4e\u67e5\u8be2\u7684\u6267\u884c\u6548\u7387\u3002 \u6700\u540e\uff0c\u8fd9\u79cd\u5199\u6cd5\u4e0d\u7b26\u5408 SQL \u6807\u51c6\u3002\u867d\u7136\u5b83\u5728 MySQL \u4e2d\u53ef\u4ee5\u901a\u8fc7\uff0c\u4f46\u662f\u5728\u5176\u4ed6\u6570\u636e\u5e93\u7cfb\u7edf\u4e2d\u53ef\u80fd\u4f1a\u51fa\u73b0\u95ee\u9898\u3002\u4e3a\u4e86\u4fdd\u8bc1\u4ee3\u7801\u7684\u8de8\u5e73\u53f0\u517c\u5bb9\u6027\uff0c\u6700\u597d\u907f\u514d\u4f7f\u7528\u8fd9\u79cd non-standard \u7684\u5199\u6cd5\u3002 \u6700\u4f73\u5b9e\u8df5\u662f\u5728\u4ee3\u7801\u5c42\u9762\u63a7\u5236\u6b64\u7c7b\u903b\u8f91\uff0c\u800c\u4e0d\u662f\u4f9d\u8d56\u4e8e MySQL \u7684\u51fd\u6570\u3002\u4e5f\u53ef\u4ee5\u901a\u8fc7\u4ed4\u7ec6\u8bbe\u8ba1\u8868\u7ed3\u6784\uff0c\u907f\u514d\u4f7f\u7528 NULL \u503c\uff0c\u4ee5\u63d0\u9ad8\u67e5\u8be2\u6027\u80fd\u3002 \u4ee5\u4e0a\u5c31\u662fJPA \u52a8\u6001\u6761\u4ef6 SQL \u4e2d\u5982\u4f55\u4f18\u96c5\u5904\u7406 NULL \u503c\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\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-25648","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/25648","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=25648"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/25648\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=25648"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=25648"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=25648"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}