{"id":85096,"date":"2020-03-26T20:01:50","date_gmt":"2020-03-26T12:01:50","guid":{"rendered":"http:\/\/4563.org\/?p=85096"},"modified":"2020-03-26T20:01:50","modified_gmt":"2020-03-26T12:01:50","slug":"%e4%bd%bf%e7%94%a8-mybatis-%e7%9a%84-sql-%e6%9e%84%e9%80%a0%e5%99%a8-%e6%89%8b%e5%8a%a8%e6%9e%84%e9%80%a0-sql%ef%bc%8c%e5%8f%82%e6%95%b0%e6%9b%bf%e6%8d%a2%e6%9c%89%e4%bb%80%e4%b9%88%e5%a5%bd%e6%96%b9","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=85096","title":{"rendered":"\u4f7f\u7528 mybatis \u7684 SQL \u6784\u9020\u5668 \u624b\u52a8\u6784\u9020 SQL\uff0c\u53c2\u6570\u66ff\u6362\u6709\u4ec0\u4e48\u597d\u65b9\u6cd5\u505a\u5417?"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u4f7f\u7528 mybatis \u7684 SQL \u6784\u9020\u5668 \u624b\u52a8\u6784\u9020 SQL\uff0c\u53c2\u6570\u66ff\u6362\u6709\u4ec0\u4e48\u597d\u65b9\u6cd5\u505a\u5417?               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : mikicomo <\/span>  <span><i><\/i> 11<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>https:\/\/mybatis.org\/mybatis-3\/zh\/statement-builders.html#<\/p>\n<pre><code>\/\/ \u52a8\u6001\u6761\u4ef6\uff08\u6ce8\u610f\u53c2\u6570\u9700\u8981\u4f7f\u7528 final \u4fee\u9970\uff0c\u4ee5\u4fbf\u533f\u540d\u5185\u90e8\u7c7b\u5bf9\u5b83\u4eec\u8fdb\u884c\u8bbf\u95ee\uff09 public String selectPersonLike(final String id, final String firstName, final String lastName) {   return new SQL() {{     SELECT(\"P.ID, P.USERNAME, P.PASSWORD, P.FIRST_NAME, P.LAST_NAME\");     FROM(\"PERSON P\");     if (id != null) {       WHERE(\"P.ID like #{id}\");     }     if (firstName != null) {       WHERE(\"P.FIRST_NAME like #{firstName}\");     }     if (lastName != null) {       WHERE(\"P.LAST_NAME like #{lastName}\");     }     ORDER_BY(\"P.LAST_NAME\");   }}.toString(); } <\/code><\/pre>\n<p>\u6211\u5e0c\u671b\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u6784\u9020\u51fa sql\uff0c\u4f20\u9012\u7ed9\u53e6\u4e00\u4e2a\u670d\u52a1\uff0c\u4ed6\u4f1a\u628a\u6211\u7684 sql \u5f53\u505a\u5b50\u67e5\u8be2\u6761\u4ef6\u8fdb\u884c\u67e5\u8be2<\/p>\n<p>\u4f46\u662f\u8fd9\u6837\u7684\u8bdd\uff0c\u5f53\u9047\u5230\u53c2\u6570\u662f\u65e5\u671f\u7c7b\u578b\u65f6\uff0c\u6709\u4ec0\u4e48\u597d\u7684\u529e\u6cd5\u5417\uff1f\u53ea\u80fd\u624b\u52a8\u628a\u65e5\u671f\u683c\u5f0f\u5316\u4e3a String \u7c7b\u578b\u8fdb\u884c\u62fc\u63a5\u5417\uff1f<\/p>\n<p>\u4ed6 demo \u4e2d\u7ed9\u51fa\u7684#{firstName}\u8fd9\u6837\u7684\u53ea\u662f\u4e2a\u5360\u4f4d\u7b26\uff0c\u5e76\u4e0d\u80fd\u76f4\u63a5\u83b7\u53d6\u5165\u53c2\u8fdb\u884c\u6ce8\u5165<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>0<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528 mybatis \u7684 SQL &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/85096"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=85096"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/85096\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=85096"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=85096"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=85096"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}