{"id":149504,"date":"2020-08-27T04:14:28","date_gmt":"2020-08-26T20:14:28","guid":{"rendered":"http:\/\/4563.org\/?p=149504"},"modified":"2020-09-05T21:32:40","modified_gmt":"2020-09-05T13:32:40","slug":"jpa-%e4%ba%8c%e7%ba%a7%e7%bc%93%e5%ad%98%e9%97%ae%e9%a2%98%e8%af%b7%e6%95%99","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=149504","title":{"rendered":"JPA \u4e8c\u7ea7\u7f13\u5b58\u95ee\u9898\u8bf7\u6559"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  JPA \u4e8c\u7ea7\u7f13\u5b58\u95ee\u9898\u8bf7\u6559               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : NULL2020 <\/span>  <span><i><\/i> 10<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>service \u5c42\u4e24\u4e2a\u67e5\u8be2\u65b9\u6cd5\uff1a<\/p>\n<pre><code>    @Cacheable(value = \"space\", key = \"#id\", unless = \"#result==null\")     public Space searchOne(long id) {         return repository.findById(id).orElse(null);     }      public Space searchOneWithUser(long id) {         Space space = searchOne(id);         space.setCreator(userService.searchOne(space.getUserId()));         return space;     }  <\/code><\/pre>\n<p>\u4e3a\u4ec0\u4e48\u8c03\u7528\u7b2c\u4e8c\u4e2a\u65b9\u6cd5\u4e0d\u8d70\u7f13\u5b58\uff1f \u7f13\u5b58\u6709\u6570\u636e\u8fd8\u662f\u4ece\u6570\u636e\u5e93\u91cc\u67e5\uff0c\u7f13\u5b58\u6ca1\u6709\u6570\u636e\uff0c\u67e5\u51fa\u6765\u540e\u4e5f\u4e0d\u5199\u5230\u7f13\u5b58\u91cc\u9762\u3002<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>11<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"3137026\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : CoderGeek <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8fd9\u4e2a\u662f\u57fa\u4e8e AOP \u7684\u52a8\u6001\u4ee3\u7406\u5b9e\u73b0\uff0c\u4f60\u5185\u90e8\u5f15\u7528\u4e0d\u751f\u6548 <br \/>1.\u653e\u5230\u5916\u90e8\u7684\u7c7b\u8c03\u7528<br \/>2.\u7528 ApplicationContext.getBean \u5728\u8c03\u7528 searchOne(id)                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3137027\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : wysnylc <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             https:\/\/www.jianshu.com\/p\/6534945eb3b5<br \/>JDK Dynamic Proxy \u65e0\u6cd5\u62e6\u622a this,Spring \u9ed8\u8ba4\u4f7f\u7528 JDK Dynamic Proxy,\u6240\u4ee5 Spring AOP \u65e0\u6cd5\u4ee3\u7406 this \u6240\u4ee5 Spring Cache \u7f13\u5b58\u6ce8\u89e3\u65e0\u6548.\u89e3\u51b3\u65b9\u6848\u4e3a\u6ce8\u5165\u5f53\u524d\u7c7b\u7684 bean \u8fdb\u884c\u4f7f\u7528(\u4f46\u662f\u6709\u53ef\u80fd\u9020\u6210\u5faa\u73af\u8c03\u7528)\u6216\u8005\u62c6\u5206\u903b\u8f91\u5230\u53e6\u4e00\u4e2a services<br \/>\u9898\u5916\u8bdd:\u4f60\u8fd9\u4e0d\u662f JPA \u4e8c\u7ea7\u7f13\u5b58\u800c\u662f Spring Cache \u81ea\u5b9a\u4e49\u7f13\u5b58,\u4e8c\u7ea7\u7f13\u5b58\u662f\u57fa\u4e8e\u8868\u7684\u7f13\u5b58                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3137028\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : NULL2020 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @CoderGeek #1 <br \/>@wysnylc #2 <\/p>\n<p>\u591a\u8c22\u591a\u8c22                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3137029\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ixx <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u591a\u8bf4\u4e00\u53e5\uff0c\u6709\u4e00\u9053\u5173\u4e8e\u4e8b\u52a1\u7684\u9762\u8bd5\u9898\u5c31\u662f\u4f60\u8fd9\u4e48\u5199\u7684\uff0c\u628a\u7f13\u5b58\u6ce8\u89e3\u6362\u6210\u4e8b\u52a1\u6ce8\u89e3 \u539f\u7406\u662f\u4e00\u6837\u7684 \uff0c\u8c03\u7528\u7b2c\u4e8c\u4e2a\u4e0d\u8d70\u4e8b\u52a1                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3137030\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : NULL2020 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @wysnylc #2 \u6211\u7684\u7406\u89e3\uff0c\u4e8c\u7ea7\u7f13\u5b58\u5c31\u662f\u67e5\u8be2\u7f13\u5b58\uff0c\u4f60\u8bf4\u7684 [\u57fa\u4e8e\u8868\u7684\u7f13\u5b58] \u597d\u50cf\u7b2c\u4e00\u6b21\u542c\u8bf4\uff0c\u6709\u6ca1\u6709\u6280\u672f\u6587\u7ae0\u53ef\u4ee5\u5206\u4eab\u4e00\u4e0b\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3137031\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : NULL2020 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @ixx #4 \u611f\u8c22\uff0c\u4e8b\u52a1\u5931\u6548\u7684\u51e0\u79cd\u539f\u56e0\u4e4b\u4e00 [\u81ea\u8c03\u7528]                                                             <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3137032\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : aragakiyuii <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8fd9\u4e2a\u4e0d\u662f orm \u7684\u4e8c\u7ea7\u7f13\u5b58\u5427\u3002\u3002<br \/>cglib \u4ee3\u7406\u5b8c\u5927\u6982\u5c31\u8fd9\u6837\uff08\u4e0d\u51c6\u786e<\/p>\n<p> <img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/09\/Udf8YlPb.png\" alt=\"JPA \u4e8c\u7ea7\u7f13\u5b58\u95ee\u9898\u8bf7\u6559\"> <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3137033\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : aragakiyuii <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @aragakiyuii #7 extend -&gt; extends                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3137034\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : wysnylc <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @NULL2020 #5 http:\/\/wbnbd.com\/?q=jpa%20%E4%B8%80%E7%BA%A7%E7%BC%93%E5%AD%98%20%E4%BA%8C%E7%BA%A7%E7%BC%93%E5%AD%98<br \/>http:\/\/iwo.im\/?q=mybatis%20%E4%BA%8C%E7%BA%A7%E7%BC%93%E5%AD%98                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3137035\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : leafre <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             Space space = this.searchOne(id);<br \/>&lt;aop:aspectj-autoproxy expose-proxy=&#8221;true&#8221;\/&gt;                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3137036\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : br00k <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u628a\u5f53\u524d\u5b9e\u4f8b\u4f7f\u7528 @Lazy \u6ce8\u5165\uff0c\u5185\u90e8\u65b9\u6cd5\u8d70 service \u8c03\u7528\u5c31\u53ef\u4ee5\u8d70\u4ee3\u7406\u4e86\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>JPA \u4e8c\u7ea7\u7f13\u5b58\u95ee\u9898\u8bf7\u6559 \u8cc7\u6df1\u5927\u4f6c&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\/149504"}],"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=149504"}],"version-history":[{"count":1,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/149504\/revisions"}],"predecessor-version":[{"id":149506,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/149504\/revisions\/149506"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=149504"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=149504"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=149504"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}