{"id":25566,"date":"2024-11-24T13:16:52","date_gmt":"2024-11-24T05:16:52","guid":{"rendered":"https:\/\/fwq.ai\/blog\/25566\/"},"modified":"2024-11-24T13:16:52","modified_gmt":"2024-11-24T05:16:52","slug":"jpa-%e5%8a%a8%e6%80%81%e6%9d%a1%e4%bb%b6-sql-%e4%bd%bf%e7%94%a8-ifnull-%e6%97%b6%ef%bc%8c%e4%b8%ba%e4%bb%80%e4%b9%88%e6%9f%a5%e8%af%a2%e7%bb%93%e6%9e%9c%e6%b2%a1%e6%9c%89%e8%bf%87%e6%bb%a4%e4%bb%bb-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/25566\/","title":{"rendered":"JPA \u52a8\u6001\u6761\u4ef6 SQL \u4f7f\u7528 IFNULL() \u65f6\uff0c\u4e3a\u4ec0\u4e48\u67e5\u8be2\u7ed3\u679c\u6ca1\u6709\u8fc7\u6ee4\u4efb\u4f55\u884c\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173063310538353.jpg\" class=\"aligncenter\" title=\"JPA \u52a8\u6001\u6761\u4ef6 SQL \u4f7f\u7528 IFNULL() \u65f6\uff0c\u4e3a\u4ec0\u4e48\u67e5\u8be2\u7ed3\u679c\u6ca1\u6709\u8fc7\u6ee4\u4efb\u4f55\u884c\uff1f\u63d2\u56fe\" alt=\"JPA \u52a8\u6001\u6761\u4ef6 SQL \u4f7f\u7528 IFNULL() \u65f6\uff0c\u4e3a\u4ec0\u4e48\u67e5\u8be2\u7ed3\u679c\u6ca1\u6709\u8fc7\u6ee4\u4efb\u4f55\u884c\uff1f\u63d2\u56fe\" \/><\/p>\n<p>\u5728 jpa \u52a8\u6001\u6761\u4ef6 sql \u4e2d\u9047\u5230 ifnull() \u95ee\u9898<\/p>\n<p>\u5728\u4f7f\u7528 jpa \u6765\u521b\u5efa\u52a8\u6001 sql \u6761\u4ef6\u65f6\uff0c\u60a8\u53ef\u80fd\u66fe\u5c1d\u8bd5\u8fc7\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<pre>where ifnull(nullif(?1,''),'xxx\u5b57\u6bb5')<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u7136\u800c\uff0c\u60a8\u6ce8\u610f\u5230\u4e86\u4e00\u4e2a\u95ee\u9898\uff1a\u6267\u884c\u6b64\u4ee3\u7801\u540e\uff0c\u67e5\u8be2\u7ed3\u679c\u76f8\u5f53\u4e8e\uff1a<\/p>\n<pre>where xxx\u5b57\u6bb5 = xxx\u5b57\u6bb5<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u662f\u600e\u4e48\u56de\u4e8b\uff0c\u6709\u89e3\u51b3\u529e\u6cd5\u5417\uff1f<\/p>\n<p>\u56de\u7b54\uff1a<\/p>\n<p>ifnull() \u51fd\u6570\u7684\u4f5c\u7528\u662f\u68c0\u67e5\u7b2c\u4e00\u4e2a\u53c2\u6570\u662f\u5426\u4e3a null\uff0c\u5982\u679c\u662f\uff0c\u5219\u8fd4\u56de\u7b2c\u4e8c\u4e2a\u53c2\u6570\u3002\u5728\u60a8\u7684\u60c5\u51b5\u4e0b\uff0c\u7b2c\u4e00\u4e2a\u53c2\u6570\u662f\u53ef\u4e3a null \u7684\u53d8\u91cf ?1\uff0c\u7b2c\u4e8c\u4e2a\u53c2\u6570\u662f\u5b57\u7b26\u4e32 &#8216;xxx\u5b57\u6bb5&#8217;.<\/p>\n<p> \u5728\u5904\u7406\u6b64\u4ee3\u7801\u65f6\uff0c\u5b83\u5c06\u6267\u884c\u4ee5\u4e0b\u64cd\u4f5c\uff1a<\/p>\n<ol>\n<li>\u68c0\u67e5 ?1 \u662f\u5426\u4e3a null\u3002<\/li>\n<li>\u5982\u679c ?1 \u4e0d\u4e3a null\uff0c\u5219\u8fd4\u56de\u5b83\u3002<\/li>\n<li>\u5982\u679c ?1 \u4e3a null\uff0c\u5219\u8fd4\u56de &#8216;xxx\u5b57\u6bb5&#8217;\u3002<\/li>\n<\/ol>\n<p>\u7136\u800c\uff0c\u6700\u540e\u4e00\u79cd\u60c5\u51b5\u6c38\u8fdc\u4e0d\u4f1a\u53d1\u751f\uff0c\u56e0\u4e3a nullif() \u51fd\u6570\u786e\u4fdd ?1 \u6c38\u8fdc\u4e0d\u4f1a\u4e3a null\u3002\u56e0\u6b64\uff0c\u67e5\u8be2\u59cb\u7ec8\u4f1a\u6267\u884c where xxx\u5b57\u6bb5 = xxx\u5b57\u6bb5\uff0c\u5e76\u4e14\u4e0d\u4f1a\u8fc7\u6ee4\u4efb\u4f55\u884c\u3002<\/p>\n<p>\u6700\u4f73\u5b9e\u8df5\u5efa\u8bae\u662f\u4f7f\u7528\u4ee3\u7801\u8fdb\u884c\u6761\u4ef6\u63a7\u5236\u3002\u907f\u514d\u4f9d\u8d56 mysql \u6765\u5904\u7406\u7a7a\u503c\uff0c\u56e0\u4e3a\u5b83\u53ef\u80fd\u4f1a\u635f\u5bb3\u6027\u80fd\u3002\u6b64\u5916\uff0c\u5728\u8bbe\u8ba1\u8868\u65f6\uff0c\u5c3d\u53ef\u80fd\u907f\u514d\u4f7f\u7528 null \u503c\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fJPA \u52a8\u6001\u6761\u4ef6 SQL \u4f7f\u7528 IFNULL() \u65f6\uff0c\u4e3a\u4ec0\u4e48\u67e5\u8be2\u7ed3\u679c\u6ca1\u6709\u8fc7\u6ee4\u4efb\u4f55\u884c\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\u9047\u5230 ifnull() \u95ee\u9898 \u5728\u4f7f\u7528 jpa \u6765\u521b\u5efa\u52a8\u6001 sql \u6761\u4ef6\u65f6\uff0c\u60a8\u53ef\u80fd\u66fe\u5c1d\u8bd5\u8fc7\u4ee5\u4e0b\u4ee3\u7801\uff1a where ifnull(nullif(?1,&#8221;),&#8217;xxx\u5b57\u6bb5&#8217;) \u767b\u5f55\u540e\u590d\u5236 \u7136\u800c\uff0c\u60a8\u6ce8\u610f\u5230\u4e86\u4e00\u4e2a\u95ee\u9898\uff1a\u6267\u884c\u6b64\u4ee3\u7801\u540e\uff0c\u67e5\u8be2\u7ed3\u679c\u76f8\u5f53\u4e8e\uff1a where xxx\u5b57\u6bb5 = xxx\u5b57\u6bb5 \u767b\u5f55\u540e\u590d\u5236 \u8fd9\u662f\u600e\u4e48\u56de\u4e8b\uff0c\u6709\u89e3\u51b3\u529e\u6cd5\u5417\uff1f \u56de\u7b54\uff1a ifnull() \u51fd\u6570\u7684\u4f5c\u7528\u662f\u68c0\u67e5\u7b2c\u4e00\u4e2a\u53c2\u6570\u662f\u5426\u4e3a null\uff0c\u5982\u679c\u662f\uff0c\u5219\u8fd4\u56de\u7b2c\u4e8c\u4e2a\u53c2\u6570\u3002\u5728\u60a8\u7684\u60c5\u51b5\u4e0b\uff0c\u7b2c\u4e00\u4e2a\u53c2\u6570\u662f\u53ef\u4e3a null \u7684\u53d8\u91cf ?1\uff0c\u7b2c\u4e8c\u4e2a\u53c2\u6570\u662f\u5b57\u7b26\u4e32 &#8216;xxx\u5b57\u6bb5&#8217;. \u5728\u5904\u7406\u6b64\u4ee3\u7801\u65f6\uff0c\u5b83\u5c06\u6267\u884c\u4ee5\u4e0b\u64cd\u4f5c\uff1a \u68c0\u67e5 ?1 \u662f\u5426\u4e3a null\u3002 \u5982\u679c ?1 \u4e0d\u4e3a null\uff0c\u5219\u8fd4\u56de\u5b83\u3002 \u5982\u679c ?1 \u4e3a null\uff0c\u5219\u8fd4\u56de &#8216;xxx\u5b57\u6bb5&#8217;\u3002 \u7136\u800c\uff0c\u6700\u540e\u4e00\u79cd\u60c5\u51b5\u6c38\u8fdc\u4e0d\u4f1a\u53d1\u751f\uff0c\u56e0\u4e3a nullif() \u51fd\u6570\u786e\u4fdd ?1 \u6c38\u8fdc\u4e0d\u4f1a\u4e3a null\u3002\u56e0\u6b64\uff0c\u67e5\u8be2\u59cb\u7ec8\u4f1a\u6267\u884c where xxx\u5b57\u6bb5 = xxx\u5b57\u6bb5\uff0c\u5e76\u4e14\u4e0d\u4f1a\u8fc7\u6ee4\u4efb\u4f55\u884c\u3002 \u6700\u4f73\u5b9e\u8df5\u5efa\u8bae\u662f\u4f7f\u7528\u4ee3\u7801\u8fdb\u884c\u6761\u4ef6\u63a7\u5236\u3002\u907f\u514d\u4f9d\u8d56 [&hellip;]<\/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-25566","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/25566","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=25566"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/25566\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=25566"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=25566"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=25566"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}