{"id":2404,"date":"2021-04-02T22:06:16","date_gmt":"2021-04-02T14:06:16","guid":{"rendered":"\/?p=2404"},"modified":"2021-04-02T22:06:16","modified_gmt":"2021-04-02T14:06:16","slug":"9-%e5%9f%ba%e4%ba%8e%e5%85%85%e8%a1%80%e6%a8%a1%e5%9e%8b%e5%bc%80%e5%8f%91%e7%9a%84ddd%e6%a8%a1%e5%9e%8b","status":"publish","type":"post","link":"http:\/\/xinblog.ltd\/?p=2404","title":{"rendered":"9.\u57fa\u4e8e\u5145\u8840\u6a21\u578b\u5f00\u53d1\u7684DDD\u6a21\u578b"},"content":{"rendered":"<p>\u5f88\u591aAPP\u5f53\u4e2d\u90fd\u5177\u6709\u94b1\u5305\u7684\u529f\u80fd\uff0c\u4e3a\u6bcf\u4e00\u4e2a\u7528\u6237\u5f00\u901a\u4e00\u4e2a\u5355\u72ec\u7684\u865a\u62df\u94b1\u5305\u8d26\u6237\uff0c\u8fd9\u4e2a\u865a\u62df\u7684\u94b1\u5305\u8d26\u6237\u652f\u6301\u5145\u503c\u63d0\u73b0\uff0c\u67e5\u8be2\u8d26\u6237\u4f59\u989d\uff0c\u67e5\u8be2\u4ea4\u6613\u6d41\u6c34\u7b49\u529f\u80fd<\/p>\n<p>\u4e00\u822c\u6765\u8bf4\u865a\u62df\u94b1\u5305\u8d26\u6237\u90fd\u4f1a\u5bf9\u5e94\u7684\u771f\u5b9e\u7684\u91d1\u878d\u8d26\u6237\uff0c\u53ef\u80fd\u662f\u4e00\u4e9b\u7b2c\u4e09\u65b9\u7684\u652f\u4ed8(\u652f\u4ed8\u5b9d)\uff0c\u4e5f\u53ef\u80fd\u662f\u4e00\u5f20\u94f6\u884c\u5361\uff0c\u5f53\u7136\u5728\u8fd9\u91cc\u9762\u6211\u4eec\u4e0d\u8003\u8651\u771f\u5b9e\u8d26\u6237\u7684\u6574\u5408\uff0c\u53ea\u8003\u8651\u865a\u62df\u94b1\u5305\u8d26\u6237\u7684\u5b9e\u73b0<\/p>\n<p>\u6211\u4eec\u4e3b\u8981\u5b9e\u73b0\u7684\u529f\u80fd\u6709\u4ee5\u4e0b5\u4e2a,\u5145\u503c,\u652f\u4ed8,\u63d0\u73b0,\u67e5\u8be2\u4f59\u989d\u548c\u67e5\u8be2\u4ea4\u6613\u8bb0\u5f55<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"805\" height=\"477\" class=\"wp-image-2405\" src=\"\/wp-content\/uploads\/2021\/04\/unnamed-file-3.png\" alt=\"\u56fe\u7247\" srcset=\"http:\/\/xinblog.ltd\/wp-content\/uploads\/2021\/04\/unnamed-file-3.png 805w, http:\/\/xinblog.ltd\/wp-content\/uploads\/2021\/04\/unnamed-file-3-300x178.png 300w, http:\/\/xinblog.ltd\/wp-content\/uploads\/2021\/04\/unnamed-file-3-768x455.png 768w\" sizes=\"(max-width: 805px) 100vw, 805px\" \/><\/p>\n<p>\u5145\u503c\u4e3b\u8981\u662f\u5c06\u771f\u5b9e\u8d26\u6237\u4e2d\u7684\u94b1\u8f6c\u79fb\u5230\u7528\u6237\u7684\u865a\u62df\u8d26\u6237\u5f53\u4e2d\uff0c\u53ef\u4ee5\u5206\u4e3a\u4ee5\u4e0b\u4e09\u4e2a\u6b65\u9aa4\uff0c1.\u5c06\u7528\u6237\u7684\u771f\u5b9e\u8d26\u6237\u4e0a\u7684\u94b1\u8f6c\u8d26\u5230\u6211\u4eec\u7684\u516c\u7528\u94f6\u884c\u8d26\u6237\u4e0a\uff0c2.\u5c06\u7528\u6237\u7684\u5145\u503c\u91d1\u989d\u52a0\u5230\u865a\u62df\u94b1\u5305\u4e0a\uff0c3.\u8bb0\u5f55\u5982\u4e0a\u7684\u4ea4\u6613\u6d41\u6c34.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"722\" height=\"288\" class=\"wp-image-2406\" src=\"\/wp-content\/uploads\/2021\/04\/unnamed-file-4.png\" alt=\"\u56fe\u7247\" srcset=\"http:\/\/xinblog.ltd\/wp-content\/uploads\/2021\/04\/unnamed-file-4.png 722w, http:\/\/xinblog.ltd\/wp-content\/uploads\/2021\/04\/unnamed-file-4-300x120.png 300w\" sizes=\"(max-width: 722px) 100vw, 722px\" \/><\/p>\n<p>\u652f\u4ed8\u5219\u662f\u5c06\u7528\u6237\u7684\u865a\u62df\u94b1\u5305\u8d26\u6237\u4e0a\u7684\u94b1\u8f6c\u5230\u5546\u5bb6\u7684\u865a\u62df\u94b1\u5305\u8d26\u6237\u4e0a\uff0c\u5176\u4e2d\u4e5f\u53ea\u6709\u4e5f\u4f1a\u5206\u4e3a\u4e24\u6b65\uff0c\u4e00\u5c06\u7528\u6237\u8d26\u6237\u4e0a\u7684\u94b1\u8f6c\u79fb\u5230\u5546\u5bb6\u8d26\u6237\u4e0a\uff0c\u4e8c\u8bb0\u5f55\u672c\u6b21\u8bb0\u5f55<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"663\" height=\"186\" class=\"wp-image-2407\" src=\"\/wp-content\/uploads\/2021\/04\/unnamed-file-5.png\" alt=\"\u56fe\u7247\" srcset=\"http:\/\/xinblog.ltd\/wp-content\/uploads\/2021\/04\/unnamed-file-5.png 663w, http:\/\/xinblog.ltd\/wp-content\/uploads\/2021\/04\/unnamed-file-5-300x84.png 300w\" sizes=\"(max-width: 663px) 100vw, 663px\" \/><\/p>\n<p>\u63d0\u73b0\u5219\u662f\u5c06\u7528\u6237\u865a\u62df\u94b1\u5305\u8d26\u6237\u4e0a\u7684\u94b1\u8f6c\u79fb\u5230\u81ea\u5df1\u7684\u94f6\u884c\u5361\u4e2d\uff0c\u5176\u5b9e\u4e5f\u5c31\u662f\u5148\u5bf9\u7528\u6237\u7684\u865a\u62df\u94b1\u5305\u8d26\u6237\u8fdb\u884c\u51cf\u91d1\u989d\uff0c\u7136\u540e\u4ece\u516c\u5171\u7684\u94f6\u884c\u5361\u4e0a\u8f6c\u51fa\u91d1\u989d\u5230\u7528\u6237\u79c1\u4eba\u7684\u94f6\u884c\u5361\u4e0a.\u7136\u540e\u8bb0\u4f4f\u672c\u6b21\u4ea4\u6613\u8bb0\u5f55<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"710\" height=\"220\" class=\"wp-image-2408\" src=\"\/wp-content\/uploads\/2021\/04\/unnamed-file-6.png\" alt=\"\u56fe\u7247\" srcset=\"http:\/\/xinblog.ltd\/wp-content\/uploads\/2021\/04\/unnamed-file-6.png 710w, http:\/\/xinblog.ltd\/wp-content\/uploads\/2021\/04\/unnamed-file-6-300x93.png 300w\" sizes=\"(max-width: 710px) 100vw, 710px\" \/><\/p>\n<p>\u67e5\u8be2\u8d26\u6237\u4f59\u989d\u4e0d\u5fc5\u8bf4\uff0c\u53ea\u662f\u7b80\u5355\u7684\u8fdb\u884c\u8d26\u6237\u5f53\u4e2d\u7684\u4f59\u989d\u67e5\u8be2<\/p>\n<p>\u800c\u67e5\u8be2\u4ea4\u6613\u4e5f\u662f\u6839\u636e\u4ea4\u6613\u7684\u4fe1\u606f\uff0c\u6bd4\u5982\u8bf4\u4ea4\u6613\u7684\u65f6\u95f4\uff0c\u4ea4\u6613\u7684\u7c7b\u578b\uff0c\u8fdb\u884c\u8fc7\u6ee4\u540e\u8fdb\u884c\u663e\u793a\u5373\u53ef<\/p>\n<p>\u90a3\u4e48\u6211\u4eec\u53ef\u4ee5\u5c06\u6574\u4e2a\u94b1\u5305\u7cfb\u7edf\u5206\u4e3a\u4e24\u90e8\u5206\u6765\u505a\uff0c1\u662f\u865a\u62df\u94b1\u5305\uff0c2\u662f\u771f\u5b9e\u94b1\u5305\uff0c\u4e5f\u5c31\u662f\u6240\u8c13\u7684\u7528\u6237\u94f6\u884c\u5361\u4fe1\u606f<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"813\" height=\"564\" class=\"wp-image-2409\" src=\"\/wp-content\/uploads\/2021\/04\/unnamed-file-7.png\" alt=\"\u56fe\u7247\" srcset=\"http:\/\/xinblog.ltd\/wp-content\/uploads\/2021\/04\/unnamed-file-7.png 813w, http:\/\/xinblog.ltd\/wp-content\/uploads\/2021\/04\/unnamed-file-7-300x208.png 300w, http:\/\/xinblog.ltd\/wp-content\/uploads\/2021\/04\/unnamed-file-7-768x533.png 768w\" sizes=\"(max-width: 813px) 100vw, 813px\" \/><\/p>\n<p>\u4eca\u5929\u6211\u4eec\u4e3b\u8981\u505a\u7684\u662f\u865a\u62df\u94b1\u5305\u76f8\u5173\u7684\u64cd\u4f5c<\/p>\n<p>\u7b80\u5355\u6765\u8bf4,\u5c31\u662f\u865a\u62df\u94b1\u5305\u4e2d\u7684\u4f59\u989d\u7684\u52a0\u52a0\u51cf\u51cf<\/p>\n<p>\u5145\u503c \u63d0\u73b0 \u67e5\u8be2 \u90fd\u53ea\u6d89\u53ca\u4e00\u4e2a\u865a\u62df\u94b1\u5305\u8d26\u6237,\u4ea4\u6613\u6d89\u53ca\u4e24\u4e2a\u94b1\u5305\u8d26\u6237<\/p>\n<p>\u800c\u63a5\u4e0b\u6765\u7684\u4ea4\u6613\u6d41\u6c34,\u6211\u4eec\u5982\u4f55\u5b9a\u4e49\u6570\u636e\u7c7b\u578b<\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u6309\u7167\u4e0a\u9762\u7684\u56fe\u6765\u5b9a\u4e49\u4ea4\u6613\u6d41\u6c34\u7684\u6570\u636e\u683c\u5f0f\uff0c\u4f46\u662f\u5728\u5176\u4e2d\u6211\u4eec\u5305\u542b\u4e24\u4e2a\u94b1\u5305\u8d26\u53f7,\u4e00\u4e2a\u662f\u5165\u8d26\u7684\uff0c\u4e00\u4e2a\u662f\u51fa\u8d26\u7684\uff0c\u8fd9\u6837\u7684\u8bbe\u8ba1\u6a21\u5f0f\u5176\u5b9e\u662f\u6709\u4e9b\u5197\u4f59\u7684\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u4ea4\u6613\u8fd9\u4e2a\u7c7b\u578b\u6539\u4e3a\u4e24\u4e2a\u5b50\u7c7b\u578b,\u652f\u4ed8\u548c\u88ab\u652f\u4ed8\uff0c\u652f\u4ed8\u8868\u793a\u51fa\u8d26\uff0c\u88ab\u652f\u4ed8\u8868\u662f\u5165\u8d26\uff0c\u8fd9\u6837\u7684\u8bdd\u5c31\u53ef\u4ee5\u53bb\u6389\u5165\u8d26\u94b1\u5305\u8d26\u53f7\u548c\u51fa\u94b1\u5305\u8d26\u53f7\u8fd9\u4e2a\u533a\u522b\uff0c\u53ea\u8bb0\u5f55\u4e00\u4e2a\u94b1\u5305\u8d26\u53f7\u5373\u53ef<\/p>\n<p>\u4f46\u662f\u6211\u4eec\u5c31\u9700\u8981\u8bb0\u5f55\u4e24\u6761\u4fe1\u606f\u6765\u8868\u793a\u4e00\u6b21\u8f6c\u8d26\u64cd\u4f5c\u4e86,\u5f80\u5f80\u4f1a\u51fa\u73b0\u5728\u4e00\u4e2a\u8d26\u6237\u4e0a\u52a0\u91d1\u989d\u6210\u529f\u5728\u53e6\u4e00\u4e2a\u8d26\u6237\u4e0a\u51cf\u91d1\u989d\u5931\u8d25\u7684\u60c5\u51b5.\u4e8e\u662f\u6211\u4eec\u53ea\u4fdd\u8bc1\u7528\u8d26\u6237\u7684\u6700\u7ec8\u4e00\u81f4\u6027\uff0c\u8f6c\u8d26\u8fd9\u79cd\u64cd\u4f5c\uff0c\u6211\u4eec\u53ef\u4ee5\u5148\u5206\u522b\u8bb0\u5f55\u4e24\u4e2a\u8d26\u6237\u7684\u52a0\u91d1\u989d\u548c\u51cf\u91d1\u989d\uff0c<\/p>\n<p>\u7136\u540e\u518d\u52a0\u4e0a\u4e00\u6761\u5305\u542b\u4ea4\u6613\u7c7b\u578b\u8f6c\u8d26\u7684\u5b8c\u6210\u8bb0\u5f55<\/p>\n<p>\u5728\u7ed9\u4e24\u4e2a\u94b1\u5305\u8fdb\u884c\u52a0\u51cf\u7684\u8fc7\u7a0b\u4e2d\uff0c\u53ea\u8981\u6709\u4e00\u4e2a\u5931\u8d25\u4e86\uff0c\u6211\u4eec\u5c31\u5c06\u4ea4\u6613\u8bb0\u5f55\u7684\u72b6\u6001\u6807\u8bb0\u4e3a\u5931\u8d25\uff0c\u7136\u540e\u91cd\u65b0\u8fdb\u884c\u6267\u884c\u6216\u8005\u662f\u8fdb\u884c\u5220\u9664\u5904\u7406<\/p>\n<p>\u800c\u4e14\u4e3a\u4e86\u907f\u514d\u865a\u62df\u94b1\u5305\u7cfb\u7edf\u611f\u77e5\u5230\u5177\u4f53\u7684\u4ea4\u6613\u7c7b\u578b\uff0c\u6211\u4eec\u53ea\u8bb0\u5f55\u5b83\u662f\u8f6c\u5165\u8fd8\u662f\u8f6c\u51fa\u800c\u5c06\u771f\u6b63\u7684\u4ea4\u6613\u7c7b\u578b\u8bb0\u5f55\u5728\u53e6\u5916\u7684\u4e00\u5f20\u8868\u91cc\u9762\uff0c\u5c31\u662f\u4ea4\u6613\u6d41\u6c34\u8868<\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u67e5\u8be2\u4e0a\u5c42\u94b1\u5305\u7cfb\u7edf\u76f8\u5173\u7684\u6d41\u6c34\u4fe1\u606f\u53bb\u6ee1\u8db3\u7528\u6237\u7684\u67e5\u8be2\uff0c\u7136\u540e\u865a\u62df\u94b1\u5305\u5f53\u4e2d\u7684\u6d41\u6c34\u4fe1\u606f\uff0c\u7528\u6765\u4fdd\u6301\u6570\u636e\u7684\u4e00\u81f4\u6027<\/p>\n<p>\u5982\u4f55\u53bb\u5b9e\u9645\u5f00\u53d1\u4e00\u4e2a\u865a\u62df\u94b1\u5305\u9879\u76ee<\/p>\n<p>\u57fa\u4e8e\u8d2b\u8840MVC\u5f00\u53d1\u6a21\u5f0f\u5f00\u53d1:<\/p>\n<p>\u8d2b\u8840\u6a21\u578b\u53bb\u5f00\u53d1\u4e00\u4e2a\u9879\u76ee\uff0c\u5df2\u7ecf\u975e\u5e38\u719f\u7ec3\u4e86\uff0c\u8fd9\u91cc\u6211\u76f4\u63a5\u4e0a\u4ee3\u7801\u5c31\u884c\u4e86<\/p>\n<p>\u4e66\u5199\u4e86\u76f8\u5bf9\u5e94\u7684VO\u548cController\uff0c\u4ee5\u53caBo\u548c\u76f8\u5bf9\u5e94\u7684Service\uff0c\u8fd8\u6709Repository\u548cEntity\u8d1f\u8d23\u6570\u636e\u5b58\u53d6<\/p>\n<table>\n<tbody>\n<tr>\n<td>public class VirtualWalletBo {\/\/\u7701\u7565getter\/setter\/constructor\u65b9\u6cd5<\/p>\n<p>private Long id;<\/p>\n<p>private Long createTime;<\/p>\n<p>private BigDecimal balance;<\/p>\n<p>}<\/p>\n<p>public class VirtualWalletService {<\/p>\n<p>\/\/ \u901a\u8fc7\u6784\u9020\u51fd\u6570\u6216\u8005IOC\u6846\u67b6\u6ce8\u5165<\/p>\n<p>private VirtualWalletRepository walletRepo;<\/p>\n<p>private VirtualWalletTransactionRepository transactionRepo;<\/p>\n<p>public VirtualWalletBo getVirtualWallet(Long walletId) {<\/p>\n<p>VirtualWalletEntity walletEntity = walletRepo.getWalletEntity(walletId);<\/p>\n<p>VirtualWalletBo walletBo = convert(walletEntity);<\/p>\n<p>return walletBo;<\/p>\n<p>}<\/p>\n<p>public BigDecimal getBalance(Long walletId) {<\/p>\n<p>return walletRepo.getBalance(walletId);<\/p>\n<p>}<\/p>\n<p>public void debit(Long walletId, BigDecimal amount) {<\/p>\n<p>VirtualWalletEntity walletEntity = walletRepo.getWalletEntity(walletId);<\/p>\n<p>BigDecimal balance = walletEntity.getBalance();<\/p>\n<p>if (balance.compareTo(amount) &lt; 0) {<\/p>\n<p>throw new NoSufficientBalanceException(&#8230;);<\/p>\n<p>}<\/p>\n<p>walletRepo.updateBalance(walletId, balance.subtract(amount));<\/p>\n<p>}<\/p>\n<p>public void credit(Long walletId, BigDecimal amount) {<\/p>\n<p>VirtualWalletEntity walletEntity = walletRepo.getWalletEntity(walletId);<\/p>\n<p>BigDecimal balance = walletEntity.getBalance();<\/p>\n<p>walletRepo.updateBalance(walletId, balance.add(amount));<\/p>\n<p>}<\/p>\n<p>public void transfer(Long fromWalletId, Long toWalletId, BigDecimal amount) {<\/p>\n<p>VirtualWalletTransactionEntity transactionEntity = new VirtualWalletTransactionEntity();<\/p>\n<p>transactionEntity.setAmount(amount);<\/p>\n<p>transactionEntity.setCreateTime(System.currentTimeMillis());<\/p>\n<p>transactionEntity.setFromWalletId(fromWalletId);<\/p>\n<p>transactionEntity.setToWalletId(toWalletId);<\/p>\n<p>transactionEntity.setStatus(Status.TO_BE_EXECUTED);<\/p>\n<p>Long transactionId = transactionRepo.saveTransaction(transactionEntity);<\/p>\n<p>try {<\/p>\n<p>debit(fromWalletId, amount);<\/p>\n<p>credit(toWalletId, amount);<\/p>\n<p>} catch (InsufficientBalanceException e) {<\/p>\n<p>transactionRepo.updateStatus(transactionId, Status.CLOSED);<\/p>\n<p>&#8230;rethrow exception e&#8230;<\/p>\n<p>} catch (Exception e) {<\/p>\n<p>transactionRepo.updateStatus(transactionId, Status.FAILED);<\/p>\n<p>&#8230;rethrow exception e&#8230;<\/p>\n<p>}<\/p>\n<p>transactionRepo.updateStatus(transactionId, Status.EXECUTED);<\/p>\n<p>}<\/p>\n<p>}<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u57fa\u4e8e\u5145\u8840\u6a21\u578b\u53bb\u5f00\u53d1\u4e00\u4e2a\u865a\u62df\u94b1\u5305\u9879\u76ee\uff0c\u5219\u662f\u5982\u4e0b\u4ee3\u7801<\/p>\n<table>\n<tbody>\n<tr>\n<td>public class VirtualWallet { \/\/ Domain\u9886\u57df\u6a21\u578b(\u5145\u8840\u6a21\u578b)<\/p>\n<p>private Long id;<\/p>\n<p>private Long createTime = System.currentTimeMillis();;<\/p>\n<p>private BigDecimal balance = BigDecimal.ZERO;<\/p>\n<p>public VirtualWallet(Long preAllocatedId) {<\/p>\n<p>this.id = preAllocatedId;<\/p>\n<p>}<\/p>\n<p>public BigDecimal balance() {<\/p>\n<p>return this.balance;<\/p>\n<p>}<\/p>\n<p>public void debit(BigDecimal amount) {<\/p>\n<p>if (this.balance.compareTo(amount) &lt; 0) {<\/p>\n<p>throw new InsufficientBalanceException(&#8230;);<\/p>\n<p>}<\/p>\n<p>this.balance.subtract(amount);<\/p>\n<p>}<\/p>\n<p>public void credit(BigDecimal amount) {<\/p>\n<p>if (amount.compareTo(BigDecimal.ZERO) &lt; 0) {<\/p>\n<p>throw new InvalidAmountException(&#8230;);<\/p>\n<p>}<\/p>\n<p>this.balance.add(amount);<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>public class VirtualWalletService {<\/p>\n<p>\/\/ \u901a\u8fc7\u6784\u9020\u51fd\u6570\u6216\u8005IOC\u6846\u67b6\u6ce8\u5165<\/p>\n<p>private VirtualWalletRepository walletRepo;<\/p>\n<p>private VirtualWalletTransactionRepository transactionRepo;<\/p>\n<p>public VirtualWallet getVirtualWallet(Long walletId) {<\/p>\n<p>VirtualWalletEntity walletEntity = walletRepo.getWalletEntity(walletId);<\/p>\n<p>VirtualWallet wallet = convert(walletEntity);<\/p>\n<p>return wallet;<\/p>\n<p>}<\/p>\n<p>public BigDecimal getBalance(Long walletId) {<\/p>\n<p>return walletRepo.getBalance(walletId);<\/p>\n<p>}<\/p>\n<p>public void debit(Long walletId, BigDecimal amount) {<\/p>\n<p>VirtualWalletEntity walletEntity = walletRepo.getWalletEntity(walletId);<\/p>\n<p>VirtualWallet wallet = convert(walletEntity);<\/p>\n<p>wallet.debit(amount);<\/p>\n<p>walletRepo.updateBalance(walletId, wallet.balance());<\/p>\n<p>}<\/p>\n<p>public void credit(Long walletId, BigDecimal amount) {<\/p>\n<p>VirtualWalletEntity walletEntity = walletRepo.getWalletEntity(walletId);<\/p>\n<p>VirtualWallet wallet = convert(walletEntity);<\/p>\n<p>wallet.credit(amount);<\/p>\n<p>walletRepo.updateBalance(walletId, wallet.balance());<\/p>\n<p>}<\/p>\n<p>public void transfer(Long fromWalletId, Long toWalletId, BigDecimal amount) {<\/p>\n<p>\/\/&#8230;\u8ddf\u57fa\u4e8e\u8d2b\u8840\u6a21\u578b\u7684\u4f20\u7edf\u5f00\u53d1\u6a21\u5f0f\u7684\u4ee3\u7801\u4e00\u6837&#8230;<\/p>\n<p>}<\/p>\n<p>}<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u7531\u4e8eController\u5c42\u548cRepository\u5c42\u4e2d\u7684\u903b\u8f91\u5e76\u4e0d\u5f3a\uff0c\u6240\u4ee5\u8bf4\u5728\u5145\u8840\u6a21\u578b\u5f53\u4e2dController\u5c42\u4e2dRepository\u5c42\u7684\u4ee3\u7801\u57fa\u672c\u76f8\u540c\uff0c\u4f46\u662f\u5728service\u4e2d\u6211\u4eec\u5206\u4e3a\u4e86Domain\u4ee5\u53caService\u7c7b\u8fdb\u884c\u76f8\u5173\u7684\u5b9e\u73b0,\u6211\u4eec\u5728domain\u7c7b\u5f53\u4e2d\u79fb\u690d\u4e86\u94b1\u5305\u5185\u539f\u6709\u7684\u5165\u8d26\u51fa\u8d26,\u67e5\u8be2\u8d26\u6237\u4f59\u989d\u7684\u64cd\u4f5c\uff0c\u800c\u5c06\u8ddf\u6570\u636e\u5e93\u4e5f\u5c31\u662fRepository\u5c42\u6253\u4ea4\u9053\u7684\u65b9\u6cd5\uff0c\u653e\u5230\u4e86service\u5c42\u5f53\u4e2d\uff0c\u5e76\u4e14\u5c06\u9700\u8981\u548c\u53e6\u4e00\u4e2a\u94b1\u5305\u8d26\u6237\u8fdb\u884c\u64cd\u4f5c\u7684\u8f6c\u8d26\u65b9\u6cd5\u4e5f\u653e\u5230\u4e86Service\u5c42\u4e2d<\/p>\n<p>\u5c31\u73b0\u5728\u7684\u60c5\u51b5\u6765\u770b\u5145\u8840\u6a21\u578b\u548c\u8d2b\u8840\u6a21\u578b\uff0c\u5b83\u4eec\u4e24\u8005\u4e4b\u95f4\u7684\u533a\u522b\u5e76\u4e0d\u662f\u5f88\u5927\uff0c\u5e76\u6ca1\u6709\u4ec0\u4e48\u5c55\u73b0\u4ec0\u4e48\u5177\u4f53\u7684\u4f18\u70b9\uff0c\u53ea\u662f\u66f4\u52a0\u7b26\u5408\u4e86\u9762\u5411\u5bf9\u8c61\u53d8\u6210\u7684\u601d\u60f3<\/p>\n<p>\u4f46\u5982\u679c\u865a\u62df\u94b1\u5305\u7c7b\u5f53\u4e2d\u589e\u52a0\u4e86\u65b0\u7684\u903b\u8f91\uff0c\u6bd4\u5982\u8bf4\u51bb\u7ed3\u548c\u900f\u652f\u8fd9\u4e9b\u903b\u8f91\u7684\u8bdd\uff0c\u4e1a\u52a1\u903b\u8f91\u66f4\u8fd8\u590d\u6742\uff0c\u66f4\u9002\u5408\u5145\u8840\u6a21\u578b\uff0c\u6211\u4eec\u5c06\u6570\u636e\u548c\u5904\u7406\u903b\u8f91\u653e\u5728\u4e00\u8d77\u5c31\u66f4\u52a0\u7b26\u5408\u9762\u5411\u5bf9\u8c61\u7684\u5c01\u88c5\u6027<\/p>\n<p>\u90a3\u4e48\u63a5\u4e0b\u6765\u6211\u4eec\u53ef\u4ee5\u601d\u8003\u4e24\u4e2a\u95ee\u9898<\/p>\n<p>\u4e3a\u4ec0\u4e48\uff1f\u6211\u4eec\u5c06\u4e1a\u52a1\u903b\u8f91\u79fb\u5230\u4e86domain\u65b9\u6cd5\u5f53\u4e2d\uff0c\u5e76\u6ca1\u6709\u5b8c\u5168\u7684\u79fb\u690d\uff0c\u800c\u662f\u5c06\u4e00\u90e8\u5206\u7684\u4e1a\u52a1\u903b\u8f91\u4ecd\u7136\u4fdd\u7559\u5230\u4e86service\u5c42\u5f53\u4e2d.<\/p>\n<p>Service\u5f53\u4e2d\u4e3b\u8981\u8d1f\u8d23\u4e0e\u6570\u636e\u5e93\u5c42\uff0c\u4e5f\u5c31\u662fRepository\u5c42\u8fdb\u884c\u4ea4\u4e92\uff0c\u4fdd\u8bc1\u4e86\u7c7b\u5f53\u4e2d\u7684\u72ec\u7acb\u6027\uff0c\u4e0d\u548c\u5176\u4ed6\u5c42\u7684\u4ee3\u7801\u8fdb\u884c\u8026\u5408\uff0c\u5e76\u4e14\u8de8\u9886\u57df\u7684\u4e1a\u52a1\uff0c\u6bd4\u5982\u8bf4\u8f6c\u8d26\u51fd\u6570\u9700\u8981\u6d89\u53ca\u5230\u4e24\u4e2a\u94b1\u5305\u7684\u64cd\u4f5c\u56e0\u6b64\u8fd9\u90e8\u5206\u7684\u903b\u8f91\u6ca1\u6cd5\u5355\u72ec\u7684\u5206\u7c7b\u7684\u53ea\u80fd\u653e\u4e86\u4e09\u6b21\u4e86\u5982\u679c\u8f6c\u8d26\u4e1a\u52a1\u590d\u6742\u8d77\u6765\u6211\u4eec\u53ef\u4ee5\u518d\u62bd\u53d6\u653e\u5230\u4e00\u4e2adomain\u7c7b\u4e2d<\/p>\n<p>\u63a5\u4e0b\u6765\u5c31\u662f\uff0c\u5bf9Service\u5c42\u548c\u6570\u636e\u5e93\u5c42\uff0c\u662f\u5426\u4e5f\u5fc5\u6709\u5fc5\u8981\u8fdb\u884c\u5145\u8840\u76ee\u524d\u7684\u6539\u9020\u5462\uff1f<\/p>\n<p>\u4f46\u662f\u6ca1\u6709\u5fc5\u8981\u53bb\u8fdb\u884c\u6539\u9020\uff0c\u56e0\u4e3a\u8fd9\u4e24\u4e2a\u5c42\u5f53\u4e2d\u5305\u542b\u7684\u4e1a\u52a1\u903b\u8f91\u5e76\u4e0d\u591a\uff0c\u7136\u540e\u4e1a\u52a1\u903b\u8f91\u6bd4\u8f83\u7b80\u5355\u7684\u8bdd\uff0c\u5c31\u6ca1\u6709\u5fc5\u8981\u8fdb\u884c\u91cd\u65b0\u6a21\u578b\u7684\u6539\u9020\uff0c\u8bbe\u8ba1\u6210\u91cd\u8981\u6a21\u578b\u7684\u8bdd\uff0c\u5176\u5b9e\u548c\u9762\u5411\u8fc7\u7a0b\u7684\u8bc4\u9009\u6a21\u578b\u76f8\u6bd4\u8f83\u6765\u8bf4\u4e5f\u6ca1\u6709\u4ec0\u4e48\u6539\u53d8<\/p>\n<p>\u554a\uff0c\u56de\u987e\u4e00\u4e0b\u672c\u7ae0\uff0c\u9996\u5148\u8bf4\u4e86\u5145\u8840\u6a21\u578b\u548c\u8d2b\u8840\u6a21\u578b\u4e4b\u95f4\u7684\u533a\u522b\uff0c\u7136\u540e\u5e76\u4e14\u5229\u7528\u5b9e\u9645\u7684\u4e00\u4e2a\u5c0fDemo\u6765\u5c55\u793a\u4e86\u5145\u8840\u6a21\u578b\u548c\u8d2b\u8840\u6a21\u578b\u4e4b\u95f4\u7684\u533a\u522b\uff0c\u4e5f\u5c31\u662f\u5145\u8840\u6a21\u578b\u548c\u8d2b\u8840\u6a21\u578b\u76f8\u6bd4\u8f83\uff0c\u4e3b\u8981\u5728\u4e8eService\u5c42\uff0c\u5728\u57fa\u4e8e\u5145\u8840\u6a21\u578b\u7684\u5f00\u53d1\u6a21\u5f0f\u4e0b\uff0c\u6211\u4eec\u5c06\u90e8\u5206\u5904\u4e8eservice\u4e2d\u7684\u4e1a\u52a1\u903b\u8f91\uff0c\u5b58\u5230\u4e86\u4e00\u4e2a\u5145\u8840\u7684\u56fe\u7247\u6a21\u578b\u5f53\u4e2d\uff0c\u8ba9\u6240\u6709\u7684\u4eba\u90fd\u80fd\u5b9e\u73b0\u4f9d\u8d56\u4e8e\u8fd9\u4e2a\u72ec\u95e8\u7c7b\uff0c\u5728\u57fa\u4e8e\u5145\u8840\u7684\u6a21\u578b\u5f00\u5f00\u53d1\u4e0b\uff0c\u8fd9\u8f88\u5b50\u4ece\u5e76\u4e0d\u4f1a\u5b8c\u5168\u7684\u76ca\u5904\uff0c\u800c\u662f\u8d1f\u8d23\u653e\u4e00\u4e9b\u4e0d\u9002\u5408\u5728\u5bf9\u95e8\u5f53\u4e2d\u7684\u5de5\u4f5c\u7528\u7528\u7684\uff0c\u6bd4\u5982\u548c\u526f\u6570\u636e\u5c42\u8fdb\u884c\u6253\u4ea4\u9053\u4ee5\u53ca\u8de8\u9886\u57df\u7684\u805a\u5408\u529f\u80fd\uff0c\u5e42\u7b49\u4e8b\u7269\u7b49\u975e\u529f\u80fd\u6027\u98df\u54c1\u5de5\u4f5c<\/p>\n<p>\u672c\u7ae0\u95ee\u9898\u5c31\u662f\u8bf4\u4e00\u8bf4\u5bf9\u4e8eDDD\u7684\u770b\u6cd5<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f88\u591aAPP\u5f53\u4e2d\u90fd\u5177\u6709\u94b1\u5305\u7684\u529f\u80fd [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15],"tags":[],"_links":{"self":[{"href":"http:\/\/xinblog.ltd\/index.php?rest_route=\/wp\/v2\/posts\/2404"}],"collection":[{"href":"http:\/\/xinblog.ltd\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/xinblog.ltd\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/xinblog.ltd\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/xinblog.ltd\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2404"}],"version-history":[{"count":0,"href":"http:\/\/xinblog.ltd\/index.php?rest_route=\/wp\/v2\/posts\/2404\/revisions"}],"wp:attachment":[{"href":"http:\/\/xinblog.ltd\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2404"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/xinblog.ltd\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2404"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/xinblog.ltd\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2404"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}