{"id":4765,"date":"2020-02-12T09:32:35","date_gmt":"2020-02-12T01:32:35","guid":{"rendered":"https:\/\/www.xttblog.com\/?p=4765"},"modified":"2020-02-12T09:34:08","modified_gmt":"2020-02-12T01:34:08","slug":"spring-%e5%b8%b8%e7%8a%af%e7%9a%84%e5%8d%81%e5%a4%a7%e9%94%99%e8%af%af%ef%bc%8c%e6%89%93%e6%ad%bb%e9%83%bd%e4%b8%8d%e8%a6%81%e7%8a%af%ef%bc%81","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=4765","title":{"rendered":"Spring \u5e38\u72af\u7684\u5341\u5927\u9519\u8bef\uff0c\u6253\u6b7b\u90fd\u4e0d\u8981\u72af\uff01"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Spring \u53ef\u4ee5\u8bf4\u662f\u6700\u6d41\u884c\u7684 Java \u6846\u67b6\u4e4b\u4e00\uff0c\u4e5f\u662f\u4e00\u53ea\u9700\u8981\u9a6f\u670d\u7684\u5f3a\u5927\u91ce\u517d\u3002\u867d\u7136\u5b83\u7684\u57fa\u672c\u6982\u5ff5\u76f8\u5f53\u5bb9\u6613\u638c\u63e1\uff0c\u4f46\u6210\u4e3a\u4e00\u540d\u5f3a\u5927\u7684 Spring \u5f00\u53d1\u8005\u4ecd\u9700\u8981\u5f88\u591a\u65f6\u95f4\u548c\u52aa\u529b\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u5c06\u4ecb\u7ecd Spring \u4e2d\u4e00\u4e9b\u5e38\u89c1\u7684\u9519\u8bef\uff0c\u7279\u522b\u662f\u9762\u5411 Web \u5e94\u7528\u7a0b\u5e8f\u548c Spring Boot\u3002\u6b63\u5982&nbsp;<a href=\"http:\/\/projects.spring.io\/spring-boot\/\">Spring Boot \u5b98\u7f51<\/a>&nbsp;\u6240\u8bf4\uff0cSpring Boot \u5bf9\u5e94\u8be5\u5982\u4f55\u6784\u5efa Production-Ready \u7684\u5e94\u7528\u4fdd\u6301\u7740&nbsp;<em>\u76f8\u5f53\u56fa\u6267\u7684\u89c2\u70b9<\/em>\uff0c\u672c\u6587\u5c06\u5c1d\u8bd5\u6a21\u4eff\u8fd9\u79cd\u89c2\u70b9\uff0c\u5e76\u63d0\u4f9b\u4e00\u4e9b\u6280\u5de7\u7684\u6982\u8ff0\uff0c\u8fd9\u4e9b\u6280\u5de7\u5c06\u5f88\u597d\u5730\u878d\u5165\u6807\u51c6 Spring Boot \u7684 web \u5e94\u7528\u7a0b\u5e8f\u5f00\u53d1\u4e2d\u53bb\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u4f60\u5bf9 Spring Boot \u8fd8\u4e0d\u662f\u5f88\u719f\u6089\uff0c\u4f46\u4ecd\u60f3\u5c1d\u8bd5\u4e0b\u63a5\u4e0b\u6765\u63d0\u5230\u7684\u4e00\u4e9b\u5185\u5bb9\uff0c\u6211\u4e5f\u4e3a\u672c\u6587\u521b\u5efa\u4e86<a href=\"https:\/\/github.com\/tkukurin\/toptal-spring-common-mistakes\">\u4e00\u4e2a GitHub \u4ed3\u5e93<\/a>\u3002\u5982\u679c\u4f60\u5728\u9605\u8bfb\u8fc7\u7a0b\u4e2d\u611f\u5230\u56f0\u60d1\uff0c\u6211\u5efa\u8bae\u628a\u4ee3\u7801 clone \u4e0b\u6765\uff0c\u5e76\u5728\u672c\u5730\u7535\u8111\u4e0a\u4f7f\u7528\u8fd9\u4e9b\u4ee3\u7801\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u9519\u8bef\u4e00\uff1a\u592a\u8fc7\u5173\u6ce8\u5e95\u5c42<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u6211\u4eec\u6b63\u5728\u89e3\u51b3\u8fd9\u4e2a\u5e38\u89c1\u9519\u8bef\uff0c\u662f\u56e0\u4e3a \u201c\u975e\u6211\u6240\u521b\u201d \u7efc\u5408\u75c7\u5728\u8f6f\u4ef6\u5f00\u53d1\u9886\u57df\u5f88\u662f\u5e38\u89c1\u3002\u75c7\u72b6\u5305\u62ec\u7ecf\u5e38\u91cd\u5199\u4e00\u4e9b\u5e38\u89c1\u7684\u4ee3\u7801\uff0c\u5f88\u591a\u5f00\u53d1\u4eba\u5458\u90fd\u6709\u8fd9\u79cd\u75c7\u72b6\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u867d\u7136\u7406\u89e3\u7279\u5b9a\u5e93\u7684\u5185\u90e8\u7ed3\u6784\u53ca\u5176\u5b9e\u73b0\uff0c\u5728\u5f88\u5927\u7a0b\u5ea6\u4e0a\u662f\u597d\u7684\u5e76\u4e14\u5f88\u6709\u5fc5\u8981\u7684\uff08\u4e5f\u53ef\u4ee5\u662f\u4e00\u4e2a\u5f88\u597d\u7684\u5b66\u4e60\u8fc7\u7a0b\uff09\uff0c\u4f46\u4f5c\u4e3a\u8f6f\u4ef6\u5de5\u7a0b\u5e08\uff0c\u4e0d\u65ad\u5730\u5904\u7406\u76f8\u540c\u7684\u5e95\u5c42\u5b9e\u73b0\u7ec6\u8282\u5bf9\u4e2a\u4eba\u7684\u5f00\u53d1\u751f\u6daf\u662f\u6709\u5bb3\u7684\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u50cf Spring \u8fd9\u79cd\u62bd\u8c61\u6846\u67b6\u7684\u5b58\u5728\u662f\u6709\u539f\u56e0\u7684\uff0c\u5b83\u5c06\u4f60\u4ece\u91cd\u590d\u5730\u624b\u5de5\u52b3\u4f5c\u4e2d\u89e3\u653e\u51fa\u6765\uff0c\u5e76\u5141\u8bb8\u4f60\u4e13\u6ce8\u4e8e\u66f4\u9ad8\u5c42\u6b21\u7684\u7ec6\u8282 \u2014\u2014 \u9886\u57df\u5bf9\u8c61\u548c\u4e1a\u52a1\u903b\u8f91\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u56e0\u6b64\uff0c\u63a5\u53d7\u62bd\u8c61\u3002\u4e0b\u6b21\u9762\u5bf9\u7279\u5b9a\u95ee\u9898\u65f6\uff0c\u9996\u5148\u8fdb\u884c\u5feb\u901f\u641c\u7d22\uff0c\u786e\u5b9a\u89e3\u51b3\u8be5\u95ee\u9898\u7684\u5e93\u662f\u5426\u5df2\u88ab\u96c6\u6210\u5230 Spring \u4e2d\uff1b\u73b0\u5728\uff0c\u4f60\u53ef\u80fd\u627e\u5230\u4e00\u4e2a\u5408\u9002\u7684\u73b0\u6210\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6bd4\u5982\uff0c\u4e00\u4e2a\u5f88\u6709\u7528\u7684\u5e93\uff0c\u5728\u672c\u6587\u7684\u5176\u4ed6\u90e8\u5206\uff0c\u6211\u5c06\u5728\u793a\u4f8b\u4e2d\u4f7f\u7528 Project Lombok \u6ce8\u89e3\u3002Lombok \u88ab\u7528\u4f5c\u6837\u677f\u4ee3\u7801\u751f\u6210\u5668\uff0c\u5e0c\u671b\u61d2\u60f0\u7684\u5f00\u53d1\u4eba\u5458\u5728\u719f\u6089\u8fd9\u4e2a\u5e93\u65f6\u4e0d\u4f1a\u9047\u5230\u95ee\u9898\u3002\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u770b\u770b\u4f7f\u7528 Lombok \u7684 \u201c\u6807\u51c6 Java Bean\u201d \u662f\u4ec0\u4e48\u6837\u5b50\u7684\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@Getter\n@Setter\n@NoArgsConstructor\npublic class Bean implements Serializable {\n    int firstBeanProperty;\n    String secondBeanProperty;\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u4f60\u6240\u60f3\uff0c\u4e0a\u8ff0\u4ee3\u7801\u88ab\u7f16\u8bd1\u4e3a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class Bean implements Serializable {\n    private int firstBeanProperty;\n    private String secondBeanProperty;\n    public int getFirstBeanProperty() {\n        return this.firstBeanProperty;\n    }\n    public String getSecondBeanProperty() {\n        return this.secondBeanProperty;\n    }\n    public void setFirstBeanProperty(int firstBeanProperty) {\n        this.firstBeanProperty = firstBeanProperty;\n    }\n    public void setSecondBeanProperty(String secondBeanProperty) {\n        this.secondBeanProperty = secondBeanProperty;\n    }\n    public Bean() {}\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f46\u662f\uff0c\u8bf7\u6ce8\u610f\uff0c\u5982\u679c\u4f60\u6253\u7b97\u5728 IDE \u4e2d\u4f7f\u7528 Lombok\uff0c\u5f88\u53ef\u80fd\u9700\u8981\u5b89\u88c5\u4e00\u4e2a\u63d2\u4ef6\uff0c\u53ef\u5728 \u6b64\u5904 \u627e\u5230 Intellij IDEA \u7248\u672c\u7684\u63d2\u4ef6\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f46\u662f\uff0c\u8bf7\u6ce8\u610f\uff0c\u5982\u679c\u4f60\u6253\u7b97\u5728 IDE \u4e2d\u4f7f\u7528 Lombok\uff0c\u5f88\u53ef\u80fd\u9700\u8981\u5b89\u88c5\u4e00\u4e2a\u63d2\u4ef6\uff0c\u53ef\u5728\u00a0<a href=\"https:\/\/plugins.jetbrains.com\/idea\/plugin\/6317-lombok-plugin\">\u6b64\u5904<\/a>\u00a0\u627e\u5230 Intellij IDEA \u7248\u672c\u7684\u63d2\u4ef6\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5e38\u89c1\u9519\u8bef\u4e8c\uff1a\u5185\u90e8\u7ed3\u6784 \u201c\u6cc4\u9732\u201d<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u516c\u5f00\u4f60\u7684\u5185\u90e8\u7ed3\u6784\uff0c\u4ece\u6765\u90fd\u4e0d\u662f\u4e00\u4e2a\u597d\u4e3b\u610f\uff0c\u56e0\u4e3a\u5b83\u5728\u670d\u52a1\u8bbe\u8ba1\u4e2d\u9020\u6210\u4e86\u4e0d\u7075\u6d3b\u6027\uff0c\u4ece\u800c\u4fc3\u8fdb\u4e86\u4e0d\u597d\u7684\u7f16\u7801\u5b9e\u8df5\u3002\u201c\u6cc4\u9732\u201d \u7684\u5185\u90e8\u673a\u5236\u8868\u73b0\u4e3a\u4f7f\u6570\u636e\u5e93\u7ed3\u6784\u53ef\u4ee5\u4ece\u67d0\u4e9b API \u7aef\u70b9\u8bbf\u95ee\u3002\u4f8b\u5982\uff0c\u4e0b\u9762\u7684 POJO\uff08\u201cPlain Old Java Object\u201d\uff09\u7c7b\u8868\u793a\u6570\u636e\u5e93\u4e2d\u7684\u4e00\u4e2a\u8868\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@Entity\n@NoArgsConstructor\n@Getter\npublic class TopTalentEntity {\n    @Id\n    @GeneratedValue\n    private Integer id;\n\n    @Column\n    private String name;\n\n    public TopTalentEntity(String name) {\n        this.name = name;\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5047\u8bbe\uff0c\u5b58\u5728\u4e00\u4e2a\u7aef\u70b9\uff0c\u4ed6\u9700\u8981\u8bbf\u95ee TopTalentEntity \u6570\u636e\u3002\u8fd4\u56de TopTalentEntity \u5b9e\u4f8b\u53ef\u80fd\u5f88\u8bf1\u4eba\uff0c\u4f46\u66f4\u7075\u6d3b\u7684\u89e3\u51b3\u65b9\u6848\u662f\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u7c7b\u6765\u8868\u793a API \u7aef\u70b9\u4e0a\u7684 TopTalentEntity \u6570\u636e\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@AllArgsConstructor\n@NoArgsConstructor\n@Getter\npublic class TopTalentData {\n    private String name;\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u6837\uff0c\u5bf9\u6570\u636e\u5e93\u540e\u7aef\u8fdb\u884c\u66f4\u6539\u5c06\u4e0d\u9700\u8981\u5728\u670d\u52a1\u5c42\u8fdb\u884c\u4efb\u4f55\u989d\u5916\u7684\u66f4\u6539\u3002\u8003\u8651\u4e0b\uff0c\u5728 TopTalentEntity \u4e2d\u6dfb\u52a0\u4e00\u4e2a \u201cpassword\u201d \u5b57\u6bb5\u6765\u5b58\u50a8\u6570\u636e\u5e93\u4e2d\u7528\u6237\u5bc6\u7801\u7684 Hash \u503c \u2014\u2014 \u5982\u679c\u6ca1\u6709 TopTalentData \u4e4b\u7c7b\u7684\u8fde\u63a5\u5668\uff0c\u5fd8\u8bb0\u66f4\u6539\u670d\u52a1\u524d\u7aef\uff0c\u5c06\u4f1a\u610f\u5916\u5730\u66b4\u9732\u4e00\u4e9b\u4e0d\u5fc5\u8981\u7684\u79d8\u5bc6\u4fe1\u606f\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5e38\u89c1\u9519\u8bef\u4e09\uff1a\u7f3a\u4e4f\u5173\u6ce8\u70b9\u5206\u79bb<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u968f\u7740\u7a0b\u5e8f\u89c4\u6a21\u7684\u589e\u957f\uff0c\u9010\u6e10\u5730\uff0c\u4ee3\u7801\u7ec4\u7ec7\u6210\u4e3a\u4e00\u4e2a\u8d8a\u6765\u8d8a\u91cd\u8981\u7684\u95ee\u9898\u3002\u8bbd\u523a\u7684\u662f\uff0c\u5927\u591a\u6570\u597d\u7684\u8f6f\u4ef6\u5de5\u7a0b\u539f\u5219\u5f00\u59cb\u5728\u89c4\u6a21\u4e0a\u5d29\u6e83 \u2014\u2014 \u7279\u522b\u662f\u5728\u6ca1\u6709\u592a\u591a\u8003\u8651\u7a0b\u5e8f\u4f53\u7cfb\u7ed3\u6784\u8bbe\u8ba1\u7684\u60c5\u51b5\u4e0b\u3002\u5f00\u53d1\u4eba\u5458\u6700\u5e38\u72af\u7684\u4e00\u4e2a\u9519\u8bef\u5c31\u662f\u6df7\u6dc6\u4ee3\u7801\u5173\u6ce8\u70b9\uff0c\u8fd9\u5f88\u5bb9\u6613\u505a\u5230\uff01<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u901a\u5e38\uff0c\u6253\u7834 \u5173\u6ce8\u70b9\u5206\u79bb \u7684\u662f\u5c06\u65b0\u529f\u80fd\u7b80\u5355\u5730 \u201c\u5012\u201d \u5728\u73b0\u6709\u7c7b\u4e2d\u3002\u5f53\u7136\uff0c\u8fd9\u662f\u4e00\u4e2a\u5f88\u597d\u7684\u77ed\u671f\u89e3\u51b3\u65b9\u6848\uff08\u5bf9\u4e8e\u521d\u5b66\u8005\u6765\u8bf4\uff0c\u5b83\u9700\u8981\u66f4\u5c11\u7684\u8f93\u5165\uff09\uff0c\u4f46\u5b83\u4e5f\u4e0d\u53ef\u907f\u514d\u5730\u4f1a\u5728\u5c06\u6765\u6210\u4e3a\u4e00\u4e2a\u95ee\u9898\uff0c\u65e0\u8bba\u662f\u5728\u6d4b\u8bd5\u671f\u95f4\u3001\u7ef4\u62a4\u671f\u95f4\u8fd8\u662f\u4ecb\u4e8e\u4e24\u8005\u4e4b\u95f4\u3002\u8003\u8651\u4e0b\u4e0b\u9762\u7684\u63a7\u5236\u5668\uff0c\u5b83\u5c06\u4ece\u6570\u636e\u5e93\u8fd4\u56de TopTalentData\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@RestController\npublic class TopTalentController {\n\n    private final TopTalentRepository topTalentRepository;\n\n    @RequestMapping(\"\/toptal\/get\")\n    public List&lt;TopTalentData&gt; getTopTalent() {\n        return topTalentRepository.findAll()\n                .stream()\n                .map(this::entityToData)\n                .collect(Collectors.toList());\n    }\n\n    private TopTalentData entityToData(TopTalentEntity topTalentEntity) {\n        return new TopTalentData(topTalentEntity.getName());\n    }\n\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8d77\u521d\uff0c\u8fd9\u6bb5\u4ee3\u7801\u4f3c\u4e4e\u6ca1\u4ec0\u4e48\u7279\u522b\u7684\u95ee\u9898\uff1b\u5b83\u63d0\u4f9b\u4e86\u4e00\u4e2a\u4ece TopTalentEntity \u5b9e\u4f8b\u68c0\u7d22\u51fa\u6765\u7684 TopTalentData \u7684 List\u3002\u7136\u800c\uff0c\u4ed4\u7ec6\u89c2\u5bdf\u4e0b\uff0c\u6211\u4eec\u53ef\u4ee5\u770b\u5230 TopTalentController \u5b9e\u9645\u4e0a\u5728\u6b64\u505a\u4e86\u4e9b\u4e8b\u60c5\uff1b\u4e5f\u5c31\u662f\u8bf4\uff0c\u5b83\u5c06\u8bf7\u6c42\u6620\u5c04\u5230\u7279\u5b9a\u7aef\u70b9\uff0c\u4ece\u6570\u636e\u5e93\u68c0\u7d22\u6570\u636e\uff0c\u5e76\u5c06\u4ece TopTalentRepository \u63a5\u6536\u7684\u5b9e\u4f53\u8f6c\u6362\u4e3a\u53e6\u4e00\u79cd\u683c\u5f0f\u3002\u4e00\u4e2a\u201c\u66f4\u5e72\u51c0\u201d \u7684\u89e3\u51b3\u65b9\u6848\u662f\u5c06\u8fd9\u4e9b\u5173\u6ce8\u70b9\u5206\u79bb\u5230\u4ed6\u4eec\u81ea\u5df1\u7684\u7c7b\u4e2d\u3002\u770b\u8d77\u6765\u53ef\u80fd\u662f\u8fd9\u4e2a\u6837\u5b50\u7684\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@RestController\n@RequestMapping(\"\/toptal\")\n@AllArgsConstructor\npublic class TopTalentController {\n\n    private final TopTalentService topTalentService;\n\n    @RequestMapping(\"\/get\")\n    public List&lt;TopTalentData&gt; getTopTalent() {\n        return topTalentService.getTopTalent();\n    }\n}\n\n@AllArgsConstructor\n@Service\npublic class TopTalentService {\n\n    private final TopTalentRepository topTalentRepository;\n    private final TopTalentEntityConverter topTalentEntityConverter;\n\n    public List&lt;TopTalentData&gt; getTopTalent() {\n        return topTalentRepository.findAll()\n                .stream()\n                .map(topTalentEntityConverter::toResponse)\n                .collect(Collectors.toList());\n    }\n}\n\n@Component\npublic class TopTalentEntityConverter {\n    public TopTalentData toResponse(TopTalentEntity topTalentEntity) {\n        return new TopTalentData(topTalentEntity.getName());\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u79cd\u5c42\u6b21\u7ed3\u6784\u7684\u53e6\u4e00\u4e2a\u4f18\u70b9\u662f\uff0c\u5b83\u5141\u8bb8\u6211\u4eec\u901a\u8fc7\u68c0\u67e5\u7c7b\u540d\u6765\u786e\u5b9a\u5c06\u529f\u80fd\u9a7b\u7559\u5728\u4f55\u5904\u3002\u6b64\u5916\uff0c\u5728\u6d4b\u8bd5\u671f\u95f4\uff0c\u5982\u679c\u9700\u8981\uff0c\u6211\u4eec\u53ef\u4ee5\u5f88\u5bb9\u6613\u5730\u7528\u6a21\u62df\u5b9e\u73b0\u6765\u66ff\u6362\u4efb\u4f55\u7c7b\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5e38\u89c1\u9519\u8bef\u56db\uff1a\u7f3a\u4e4f\u5f02\u5e38\u5904\u7406\u6216\u5904\u7406\u4e0d\u5f53<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e00\u81f4\u6027\u7684\u4e3b\u9898\u5e76\u975e\u662f Spring\uff08\u6216 Java\uff09\u6240\u72ec\u6709\u7684\uff0c\u4f46\u4ecd\u7136\u662f\u5904\u7406 Spring \u9879\u76ee\u65f6\u9700\u8981\u8003\u8651\u7684\u4e00\u4e2a\u91cd\u8981\u65b9\u9762\u3002\u867d\u7136\u7f16\u7801\u98ce\u683c\u53ef\u80fd\u5b58\u5728\u4e89\u8bae\uff08\u901a\u5e38\u56e2\u961f\u6216\u6574\u4e2a\u516c\u53f8\u5185\u90e8\u5df2\u8fbe\u6210\u4e00\u81f4\uff09\uff0c\u4f46\u62e5\u6709\u4e00\u4e2a\u5171\u540c\u7684\u6807\u51c6\u6700\u7ec8\u4f1a\u6781\u5927\u5730\u63d0\u9ad8\u751f\u4ea7\u529b\u3002\u5bf9\u591a\u4eba\u56e2\u961f\u5c24\u4e3a\u5982\u6b64\uff1b\u4e00\u81f4\u6027\u5141\u8bb8\u4ea4\u6d41\u53d1\u751f\uff0c\u800c\u4e0d\u9700\u8981\u82b1\u8d39\u5f88\u591a\u8d44\u6e90\u5728\u624b\u628a\u624b\u4ea4\u63a5\u4e0a\uff0c\u4e5f\u4e0d\u9700\u8981\u5c31\u4e0d\u540c\u7c7b\u7684\u804c\u8d23\u63d0\u4f9b\u5197\u957f\u7684\u89e3\u91ca\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8003\u8651\u4e00\u4e2a\u5305\u542b\u5404\u79cd\u914d\u7f6e\u6587\u4ef6\u3001\u670d\u52a1\u548c\u63a7\u5236\u5668\u7684 Spring \u9879\u76ee\u3002\u5728\u547d\u540d\u65f6\u4fdd\u6301\u8bed\u4e49\u4e0a\u7684\u4e00\u81f4\u6027\uff0c\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u6613\u4e8e\u641c\u7d22\u7684\u7ed3\u6784\uff0c\u4efb\u4f55\u65b0\u7684\u5f00\u53d1\u4eba\u5458\u90fd\u53ef\u4ee5\u6309\u7167\u81ea\u5df1\u7684\u65b9\u5f0f\u7ba1\u7406\u4ee3\u7801\uff1b\u4f8b\u5982\uff0c\u5c06 Config \u540e\u7f00\u6dfb\u52a0\u5230\u914d\u7f6e\u7c7b\uff0c\u670d\u52a1\u5c42\u4ee5 Service \u7ed3\u5c3e\uff0c\u4ee5\u53ca\u63a7\u5236\u5668\u7528 Controller \u7ed3\u5c3e\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0e\u4e00\u81f4\u6027\u4e3b\u9898\u5bc6\u5207\u76f8\u5173\uff0c\u670d\u52a1\u5668\u7aef\u7684\u9519\u8bef\u5904\u7406\u503c\u5f97\u7279\u522b\u5f3a\u8c03\u3002\u5982\u679c\u4f60\u66fe\u7ecf\u4e0d\u5f97\u4e0d\u5904\u7406\u7f16\u5199\u5f88\u5dee\u7684 API \u7684\u5f02\u5e38\u54cd\u5e94\uff0c\u90a3\u4f60\u53ef\u80fd\u77e5\u9053\u539f\u56e0 \u2014\u2014 \u6b63\u786e\u89e3\u6790\u5f02\u5e38\u4f1a\u662f\u4e00\u4ef6\u75db\u82e6\u7684\u4e8b\u60c5\uff0c\u800c\u786e\u5b9a\u8fd9\u4e9b\u5f02\u5e38\u6700\u521d\u53d1\u751f\u7684\u539f\u56e0\u5219\u66f4\u4e3a\u75db\u82e6\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f5c\u4e3a\u4e00\u540d API \u5f00\u53d1\u8005\uff0c\u7406\u60f3\u60c5\u51b5\u4e0b\u4f60\u5e0c\u671b\u8986\u76d6\u6240\u6709\u9762\u5411\u7528\u6237\u7684\u7aef\u70b9\uff0c\u5e76\u5c06\u4ed6\u4eec\u8f6c\u6362\u4e3a\u5e38\u89c1\u7684\u9519\u8bef\u683c\u5f0f\u3002\u8fd9\u901a\u5e38\u610f\u5473\u7740\u6709\u4e00\u4e2a\u901a\u7528\u7684\u9519\u8bef\u4ee3\u7801\u548c\u63cf\u8ff0\uff0c\u800c\u4e0d\u662f\u9003\u907f\u89e3\u51b3\u95ee\u9898\uff1aa) \u8fd4\u56de\u4e00\u4e2a \u201c500 Internal Server Error\u201d\u4fe1\u606f\u3002b) \u76f4\u63a5\u8fd4\u56de\u5f02\u5e38\u7684\u5806\u6808\u4fe1\u606f\u7ed9\u7528\u6237\u3002\uff08\u5b9e\u9645\u4e0a\uff0c\u8fd9\u4e9b\u90fd\u5e94\u8be5\u4e0d\u60dc\u4e00\u5207\u4ee3\u4ef7\u5730\u53bb\u907f\u514d\uff0c\u56e0\u4e3a\u9664\u4e86\u5ba2\u6237\u7aef\u96be\u4ee5\u5904\u7406\u4ee5\u5916\uff0c\u5b83\u8fd8\u66b4\u9732\u4e86\u4f60\u7684\u5185\u90e8\u4fe1\u606f\uff09\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f8b\u5982\uff0c\u5e38\u89c1\u9519\u8bef\u54cd\u5e94\u683c\u5f0f\u53ef\u80fd\u957f\u8fd9\u6837\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@Value\npublic class ErrorResponse {\n    private Integer errorCode;\n    private String errorMessage;\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0e\u6b64\u7c7b\u4f3c\u7684\u4e8b\u60c5\u5728\u5927\u591a\u6570\u6d41\u884c\u7684 API \u4e2d\u4e5f\u7ecf\u5e38\u9047\u5230\uff0c\u7531\u4e8e\u53ef\u4ee5\u5bb9\u6613\u4e14\u7cfb\u7edf\u5730\u8bb0\u5f55\uff0c\u6548\u679c\u5f80\u5f80\u5f88\u4e0d\u9519\u3002\u5c06\u5f02\u5e38\u8f6c\u6362\u4e3a\u8fd9\u79cd\u683c\u5f0f\u53ef\u4ee5\u901a\u8fc7\u5411\u65b9\u6cd5\u63d0\u4f9b @ExceptionHandler \u6ce8\u89e3\u6765\u5b8c\u6210\uff08\u6ce8\u89e3\u6848\u4f8b\u53ef\u89c1\u4e8e\u7b2c\u516d\u7ae0\uff09\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5e38\u89c1\u9519\u8bef\u4e94\uff1a\u591a\u7ebf\u7a0b\u5904\u7406\u4e0d\u5f53<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0d\u7ba1\u662f\u684c\u9762\u5e94\u7528\u8fd8\u662f Web \u5e94\u7528\uff0c\u65e0\u8bba\u662f Spring \u8fd8\u662f No Spring\uff0c\u591a\u7ebf\u7a0b\u90fd\u662f\u5f88\u96be\u7834\u89e3\u7684\u3002\u7531\u5e76\u884c\u6267\u884c\u7a0b\u5e8f\u6240\u5f15\u8d77\u7684\u95ee\u9898\u662f\u4ee4\u4eba\u6bdb\u9aa8\u609a\u7136\u4e14\u96be\u4ee5\u6349\u6478\u7684\uff0c\u800c\u4e14\u5e38\u5e38\u96be\u4ee5\u8c03\u8bd5 \u2014\u2014 \u5b9e\u9645\u4e0a\uff0c\u7531\u4e8e\u95ee\u9898\u7684\u672c\u8d28\uff0c\u4e00\u65e6\u4f60\u610f\u8bc6\u5230\u4f60\u6b63\u5728\u5904\u7406\u4e00\u4e2a\u5e76\u884c\u6267\u884c\u95ee\u9898\uff0c\u4f60\u53ef\u80fd\u5c31\u4e0d\u5f97\u4e0d\u5b8c\u5168\u653e\u5f03\u8c03\u8bd5\u5668\u4e86\uff0c\u5e76 \u201c\u624b\u52a8\u201d \u68c0\u67e5\u4ee3\u7801\uff0c\u76f4\u5230\u627e\u5230\u6839\u672c\u4e0a\u7684\u9519\u8bef\u539f\u56e0\u3002\u4e0d\u5e78\u7684\u662f\uff0c\u8fd9\u7c7b\u95ee\u9898\u5e76\u6ca1\u6709\u5343\u7bc7\u4e00\u5f8b\u7684\u89e3\u51b3\u65b9\u6848\uff1b\u6839\u636e\u5177\u4f53\u573a\u666f\u6765\u8bc4\u4f30\u60c5\u51b5\uff0c\u7136\u540e\u4ece\u4f60\u8ba4\u4e3a\u6700\u597d\u7684\u89d2\u5ea6\u6765\u89e3\u51b3\u95ee\u9898\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5f53\u7136\uff0c\u7406\u60f3\u60c5\u51b5\u4e0b\uff0c\u4f60\u4e5f\u5e0c\u671b\u5b8c\u5168\u907f\u514d\u591a\u7ebf\u7a0b\u9519\u8bef\u3002\u540c\u6837\uff0c\u4e0d\u5b58\u5728\u90a3\u79cd\u4e00\u5200\u5207\u7684\u65b9\u6cd5\uff0c\u4f46\u8fd9\u6709\u4e00\u4e9b\u8c03\u8bd5\u548c\u9632\u6b62\u591a\u7ebf\u7a0b\u9519\u8bef\u7684\u5b9e\u9645\u8003\u8651\u56e0\u7d20\uff1a<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"\u907f\u514d\u5168\u5c40\u72b6\u6001\">5.1. \u907f\u514d\u5168\u5c40\u72b6\u6001<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u9996\u5148\uff0c\u7262\u8bb0 \u201c\u5168\u5c40\u72b6\u6001\u201d \u95ee\u9898\u3002\u5982\u679c\u4f60\u6b63\u521b\u5efa\u4e00\u4e2a\u591a\u7ebf\u7a0b\u5e94\u7528\uff0c\u90a3\u4e48\u5e94\u8be5\u5bc6\u5207\u5173\u6ce8\u4efb\u4f55\u53ef\u80fd\u5168\u5c40\u4fee\u6539\u7684\u5185\u5bb9\uff0c\u5982\u679c\u53ef\u80fd\u7684\u8bdd\uff0c\u5c06\u4ed6\u4eec\u5168\u90e8\u5220\u6389\u3002\u5982\u679c\u67d0\u4e2a\u5168\u5c40\u53d8\u91cf\u6709\u5fc5\u987b\u4fdd\u6301\u53ef\u4fee\u6539\u7684\u539f\u56e0\uff0c\u8bf7\u4ed4\u7ec6\u4f7f\u7528&nbsp;<a href=\"https:\/\/docs.oracle.com\/javase\/tutorial\/essential\/concurrency\/syncmeth.html\">synchronization<\/a>\uff0c\u5e76\u5bf9\u7a0b\u5e8f\u6027\u80fd\u8fdb\u884c\u8ddf\u8e2a\uff0c\u4ee5\u786e\u5b9a\u6ca1\u6709\u56e0\u4e3a\u65b0\u5f15\u5165\u7684\u7b49\u5f85\u65f6\u95f4\u800c\u5bfc\u81f4\u7cfb\u7edf\u6027\u80fd\u964d\u4f4e\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"\u907f\u514d\u53ef\u53d8\u6027\">5.2. \u907f\u514d\u53ef\u53d8\u6027<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u70b9\u76f4\u63a5\u6765\u81ea\u4e8e&nbsp;<a href=\"https:\/\/en.wikipedia.org\/wiki\/Functional_programming\">\u51fd\u6570\u5f0f\u7f16\u7a0b<\/a>\uff0c\u5e76\u4e14\u9002\u7528\u4e8e OOP\uff0c\u58f0\u660e\u5e94\u8be5\u907f\u514d\u7c7b\u548c\u72b6\u6001\u7684\u6539\u53d8\u3002\u7b80\u800c\u8a00\u4e4b\uff0c\u8fd9\u610f\u5473\u7740\u653e\u5f03 setter \u65b9\u6cd5\uff0c\u5e76\u5728\u6240\u6709\u6a21\u578b\u7c7b\u4e0a\u62e5\u6709\u79c1\u6709\u7684 final \u5b57\u6bb5\u3002\u5b83\u4eec\u7684\u503c\u552f\u4e00\u53d1\u751f\u53d8\u5316\u7684\u65f6\u95f4\u662f\u5728\u6784\u9020\u671f\u95f4\u3002\u8fd9\u6837\uff0c\u4f60\u53ef\u4ee5\u786e\u5b9a\u4e0d\u4f1a\u51fa\u73b0\u4e89\u7528\u95ee\u9898\uff0c\u4e14\u8bbf\u95ee\u5bf9\u8c61\u5c5e\u6027\u5c06\u59cb\u7ec8\u63d0\u4f9b\u6b63\u786e\u7684\u503c\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"\u8bb0\u5f55\u5173\u952e\u6570\u636e\">5.3. \u8bb0\u5f55\u5173\u952e\u6570\u636e<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u8bc4\u4f30\u4f60\u7684\u7a0b\u5e8f\u53ef\u80fd\u4f1a\u5728\u4f55\u5904\u53d1\u751f\u5f02\u5e38\uff0c\u5e76\u9884\u5148\u8bb0\u5f55\u6240\u6709\u5173\u952e\u6570\u636e\u3002\u5982\u679c\u53d1\u751f\u9519\u8bef\uff0c\u4f60\u5c06\u5f88\u9ad8\u5174\u53ef\u4ee5\u5f97\u5230\u4fe1\u606f\u8bf4\u660e\u6536\u5230\u4e86\u54ea\u4e9b\u8bf7\u6c42\uff0c\u5e76\u53ef\u66f4\u597d\u5730\u4e86\u89e3\u4f60\u7684\u5e94\u7528\u7a0b\u5e8f\u4e3a\u4ec0\u4e48\u4f1a\u51fa\u73b0\u9519\u8bef\u3002\u9700\u8981\u518d\u6b21\u6ce8\u610f\u7684\u662f\uff0c\u65e5\u5fd7\u8bb0\u5f55\u5f15\u5165\u4e86\u989d\u5916\u7684\u6587\u4ef6 I\/O\uff0c\u53ef\u80fd\u4f1a\u4e25\u91cd\u5f71\u54cd\u5e94\u7528\u7684\u6027\u80fd\uff0c\u56e0\u6b64\u8bf7\u4e0d\u8981\u6ee5\u7528\u65e5\u5fd7\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"\u590d\u7528\u73b0\u5b58\u5b9e\u73b0\">5.4. \u590d\u7528\u73b0\u5b58\u5b9e\u73b0<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u6bcf\u5f53\u4f60\u9700\u8981\u521b\u5efa\u81ea\u5df1\u7684\u7ebf\u7a0b\u65f6\uff08\u4f8b\u5982\uff1a\u5411\u4e0d\u540c\u7684\u670d\u52a1\u53d1\u51fa\u5f02\u6b65\u8bf7\u6c42\uff09\uff0c\u590d\u7528\u73b0\u6709\u7684\u5b89\u5168\u5b9e\u73b0\u6765\u4ee3\u66ff\u521b\u5efa\u81ea\u5df1\u7684\u89e3\u51b3\u65b9\u6848\u3002\u8fd9\u5728\u5f88\u5927\u7a0b\u5ea6\u4e0a\u610f\u5473\u7740\u8981\u4f7f\u7528\u00a0<a href=\"http:\/\/www.nurkiewicz.com\/2014\/11\/executorservice-10-tips-and-tricks.html\">ExecutorServices<\/a>\u00a0\u548c Java 8 \u7b80\u6d01\u7684\u51fd\u6570\u5f0f\u00a0<a href=\"http:\/\/www.nurkiewicz.com\/2013\/05\/java-8-definition%20-guide-to%20-%20.html\">CompletableFutures<\/a>\u00a0\u6765\u521b\u5efa\u7ebf\u7a0b\u3002Spring \u8fd8\u5141\u8bb8\u901a\u8fc7\u00a0<a href=\"http:\/\/docs.spring.io\/springing-framework\/docs\/4.0.x\/springing-frame-reference\/html\/mvc.html%20#%20mvc.ann-async\">DeferredResult<\/a>\u00a0\u7c7b\u6765\u8fdb\u884c\u5f02\u6b65\u8bf7\u6c42\u5904\u7406\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5e38\u89c1\u9519\u8bef\u516d\uff1a\u4e0d\u4f7f\u7528\u57fa\u4e8e\u6ce8\u89e3\u7684\u9a8c\u8bc1<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5047\u8bbe\u6211\u4eec\u4e4b\u524d\u7684 TopTalent \u670d\u52a1\u9700\u8981\u4e00\u4e2a\u7aef\u70b9\u6765\u6dfb\u52a0\u65b0\u7684 TopTalent\u3002\u6b64\u5916\uff0c\u5047\u8bbe\u57fa\u4e8e\u67d0\u4e9b\u539f\u56e0\uff0c\u6bcf\u4e2a\u65b0\u540d\u8bcd\u90fd\u9700\u8981\u4e3a 10 \u4e2a\u5b57\u7b26\u957f\u5ea6\u3002\u6267\u884c\u6b64\u64cd\u4f5c\u7684\u4e00\u79cd\u65b9\u6cd5\u53ef\u80fd\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@RequestMapping(\"\/put\")\npublic void addTopTalent(@RequestBody TopTalentData topTalentData) {\n    boolean nameNonExistentOrHasInvalidLength =\n            Optional.ofNullable(topTalentData)\n         .map(TopTalentData::getName)\n   .map(name -&gt; name.length() == 10)\n   .orElse(true);\n\n    if (nameNonExistentOrInvalidLength) {\n        \/\/ throw some exception\n    }\n\n    topTalentService.addTopTalent(topTalentData);\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u7136\u800c\uff0c\u4e0a\u9762\u7684\u65b9\u6cd5\uff08\u9664\u4e86\u6784\u9020\u5f88\u5dee\u4ee5\u5916\uff09\u5e76\u4e0d\u662f\u4e00\u4e2a\u771f\u6b63 \u201c\u5e72\u51c0\u201d \u7684\u89e3\u51b3\u529e\u6cd5\u3002\u6211\u4eec\u6b63\u68c0\u67e5\u4e0d\u6b62\u4e00\u79cd\u7c7b\u578b\u7684\u6709\u6548\u6027\uff08\u5373&nbsp;<code>TopTalentData<\/code>&nbsp;\u4e0d\u5f97\u4e3a\u7a7a\uff0c<code>TopTalentData.name<\/code>&nbsp;\u4e0d\u5f97\u4e3a\u7a7a\uff0c\u4e14&nbsp;<code>TopTalentData.name<\/code>&nbsp;\u4e3a 10 \u4e2a\u5b57\u7b26\u957f\u5ea6\uff09\uff0c\u4ee5\u53ca\u5728\u6570\u636e\u65e0\u6548\u65f6\u629b\u51fa\u5f02\u5e38\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u901a\u8fc7\u5728 Spring \u4e2d\u96c6\u6210\u00a0<a href=\"http:\/\/hibernate%20nate.org\/validator\/\">Hibernate validator<\/a>\uff0c\u6570\u636e\u6821\u9a8c\u53ef\u4ee5\u66f4\u5e72\u51c0\u5730\u8fdb\u884c\u3002\u8ba9\u6211\u4eec\u9996\u5148\u91cd\u6784\u00a0<code>addTopTalent<\/code>\u00a0\u65b9\u6cd5\u6765\u652f\u6301\u9a8c\u8bc1\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@RequestMapping(\"\/put\")\npublic void addTopTalent(@Valid @NotNull @RequestBody TopTalentData topTalentData) {\n    topTalentService.addTopTalent(topTalentData);\n}\n\n@ExceptionHandler\n@ResponseStatus(HttpStatus.BAD_REQUEST)\npublic ErrorResponse handleInvalidTopTalentDataException(MethodArgumentNotValidException methodArgumentNotValidException) {\n    \/\/ handle validation exception\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6b64\u5916\uff0c\u6211\u4eec\u8fd8\u5fc5\u987b\u6307\u51fa\u6211\u4eec\u60f3\u8981\u5728 TopTalentData \u7c7b\u4e2d\u9a8c\u8bc1\u4ec0\u4e48\u5c5e\u6027\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class TopTalentData {\n    @Length(min = 10, max = 10)\n    @NotNull\n    private String name;\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u73b0\u5728\uff0cSpring \u5c06\u5728\u8c03\u7528\u65b9\u6cd5\u4e4b\u524d\u62e6\u622a\u5176\u8bf7\u6c42\u5e76\u5bf9\u53c2\u6570\u8fdb\u884c\u9a8c\u8bc1 \u2014\u2014 \u65e0\u9700\u4f7f\u7528\u989d\u5916\u7684\u624b\u5de5\u6d4b\u8bd5\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u53e6\u4e00\u79cd\u5b9e\u73b0\u76f8\u540c\u529f\u80fd\u7684\u65b9\u6cd5\u662f\u521b\u5efa\u6211\u4eec\u81ea\u5df1\u7684\u6ce8\u89e3\u3002\u867d\u7136\u4f60\u901a\u5e38\u53ea\u5728\u9700\u8981\u8d85\u51fa\u00a0<a href=\"https:\/\/docs.jboss.org\/hibernate\/stable\/validator\/reference\/en-US\/html_single\/#section-builtin-constraints\">Hibernate\u7684\u5185\u7f6e\u7ea6\u675f\u96c6<\/a>\u00a0\u65f6\u624d\u4f7f\u7528\u81ea\u5b9a\u4e49\u6ce8\u89e3\uff0c\u672c\u4f8b\u4e2d\uff0c\u6211\u4eec\u5047\u8bbe @Length \u4e0d\u5b58\u5728\u3002\u4f60\u53ef\u4ee5\u521b\u5efa\u4e24\u4e2a\u989d\u5916\u7684\u7c7b\u6765\u9a8c\u8bc1\u5b57\u7b26\u4e32\u957f\u5ea6\uff0c\u4e00\u4e2a\u7528\u4e8e\u9a8c\u8bc1\uff0c\u4e00\u4e2a\u7528\u4e8e\u5bf9\u5c5e\u6027\u8fdb\u884c\u6ce8\u89e3\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER})\n@Retention(RetentionPolicy.RUNTIME)\n@Documented\n@Constraint(validatedBy = { MyAnnotationValidator.class })\npublic @interface MyAnnotation {\n\n    String message() default \"String length does not match expected\";\n\n    Class&lt;?&gt;[] groups() default {};\n\n    Class&lt;? extends Payload&gt;[] payload() default {};\n\n    int value();\n\n}\n\n@Component\npublic class MyAnnotationValidator implements ConstraintValidator&lt;MyAnnotation, String&gt; {\n\n    private int expectedLength;\n\n    @Override\n    public void initialize(MyAnnotation myAnnotation) {\n        this.expectedLength = myAnnotation.value();\n    }\n\n    @Override\n    public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) {\n        return s == null || s.length() == this.expectedLength;\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8bf7\u6ce8\u610f\uff0c\u8fd9\u4e9b\u60c5\u51b5\u4e0b\uff0c\u5173\u6ce8\u70b9\u5206\u79bb\u7684\u6700\u4f73\u5b9e\u8df5\u8981\u6c42\u5728\u5c5e\u6027\u4e3a null \u65f6\uff0c\u5c06\u5176\u6807\u8bb0\u4e3a\u6709\u6548\uff08<code>isValid<\/code>\u00a0\u65b9\u6cd5\u4e2d\u7684\u00a0<code>s == null<\/code>\uff09\uff0c\u5982\u679c\u8fd9\u662f\u5c5e\u6027\u7684\u9644\u52a0\u8981\u6c42\uff0c\u5219\u4f7f\u7528\u00a0<code>@NotNull<\/code>\u00a0\u6ce8\u89e3\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class TopTalentData {\n    @MyAnnotation(value = 10)\n    @NotNull\n    private String name;\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u5e38\u89c1\u9519\u8bef\u4e03\u4f9d\u65e7\u4f7f\u7528\u57fa\u4e8exml\u7684\u914d\u7f6e\">\u5e38\u89c1\u9519\u8bef\u4e03\uff1a\uff08\u4f9d\u65e7\uff09\u4f7f\u7528\u57fa\u4e8exml\u7684\u914d\u7f6e<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u867d\u7136\u4e4b\u524d\u7248\u672c\u7684 Spring \u9700\u8981 XML\uff0c\u4f46\u5982\u4eca\u5927\u90e8\u5206\u914d\u7f6e\u5747\u53ef\u901a\u8fc7 Java \u4ee3\u7801\u6216\u6ce8\u89e3\u6765\u5b8c\u6210\uff1bXML \u914d\u7f6e\u53ea\u662f\u4f5c\u4e3a\u9644\u52a0\u7684\u4e0d\u5fc5\u8981\u7684\u6837\u677f\u4ee3\u7801\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u672c\u6587\uff08\u53ca\u5176\u9644\u5e26\u7684 GitHub \u4ed3\u5e93\uff09\u5747\u4f7f\u7528\u6ce8\u89e3\u6765\u914d\u7f6e Spring\uff0cSpring \u77e5\u9053\u5e94\u8be5\u8fde\u63a5\u54ea\u4e9b Bean\uff0c\u56e0\u4e3a\u5f85\u626b\u63cf\u7684\u9876\u7ea7\u5305\u76ee\u5f55\u5df2\u5728\u00a0<code>@SpringBootApplication<\/code>\u00a0\u590d\u5408\u6ce8\u89e3\u4e2d\u505a\u4e86\u58f0\u660e\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@SpringBootApplication\npublic class Application {\n    public static void main(String[] args) {\n        SpringApplication.run(Application.class, args);\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u590d\u5408\u6ce8\u89e3\uff08\u53ef\u901a\u8fc7&nbsp;<a href=\"http:\/\/docs.spring.io\/autorepo\/docs\/springing-boot\/current\/reference\/html\/using-boot%20-using-springbootapplication-%20annot.html\">Spring \u6587\u6863<\/a>&nbsp;\u4e86\u89e3\u66f4\u591a\u4fe1\u606f\uff09\u53ea\u662f\u5411 Spring \u63d0\u793a\u5e94\u8be5\u626b\u63cf\u54ea\u4e9b\u5305\u6765\u68c0\u7d22 Bean\u3002\u5728\u6211\u4eec\u7684\u6848\u4f8b\u4e2d\uff0c\u8fd9\u610f\u5473\u7740\u8fd9\u4e2a\u9876\u7ea7\u5305 \uff08co.kukurin\uff09\u5c06\u7528\u4e8e\u68c0\u7d22\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><code>@Component<\/code>&nbsp;(<code>TopTalentConverter<\/code>,&nbsp;<code>MyAnnotationValidator<\/code>)<\/li><li><code>@RestController<\/code>&nbsp;(<code>TopTalentController<\/code>)<\/li><li><code>@Repository<\/code>&nbsp;(<code>TopTalentRepository<\/code>)<\/li><li><code>@Service<\/code>&nbsp;(<code>TopTalentService<\/code>) \u7c7b<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u6211\u4eec\u6709\u4efb\u4f55\u989d\u5916\u7684\u00a0<code>@Configuration<\/code>\u00a0\u6ce8\u89e3\u7c7b\uff0c\u5b83\u4eec\u4e5f\u4f1a\u68c0\u67e5\u57fa\u4e8e Java \u7684\u914d\u7f6e\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u5e38\u89c1\u9519\u8bef\u516b\u5ffd\u7565-profile\">\u5e38\u89c1\u9519\u8bef\u516b\uff1a\u5ffd\u7565 profile<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u670d\u52a1\u7aef\u5f00\u53d1\u4e2d\uff0c\u7ecf\u5e38\u9047\u5230\u7684\u4e00\u4e2a\u95ee\u9898\u662f\u533a\u5206\u4e0d\u540c\u7684\u914d\u7f6e\u7c7b\u578b\uff0c\u901a\u5e38\u662f\u751f\u4ea7\u914d\u7f6e\u548c\u5f00\u53d1\u914d\u7f6e\u3002\u5728\u6bcf\u6b21\u4ece\u6d4b\u8bd5\u5207\u6362\u5230\u90e8\u7f72\u5e94\u7528\u7a0b\u5e8f\u65f6\uff0c\u4e0d\u8981\u624b\u52a8\u66ff\u6362\u5404\u79cd\u914d\u7f6e\u9879\uff0c\u66f4\u6709\u6548\u7684\u65b9\u6cd5\u662f\u4f7f\u7528 profile\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8003\u8651\u8fd9\u4e48\u4e00\u79cd\u60c5\u51b5\uff1a\u4f60\u6b63\u5728\u4f7f\u7528\u5185\u5b58\u6570\u636e\u5e93\u8fdb\u884c\u672c\u5730\u5f00\u53d1\uff0c\u800c\u5728\u751f\u4ea7\u73af\u5883\u4e2d\u4f7f\u7528 MySQL \u6570\u636e\u5e93\u3002\u672c\u8d28\u4e0a\uff0c\u8fd9\u610f\u5473\u7740\u4f60\u9700\u8981\u4f7f\u7528\u4e0d\u540c\u7684 URL \u548c \uff08\u5e0c\u671b\u5982\u6b64\uff09 \u4e0d\u540c\u7684\u51ed\u8bc1\u6765\u8bbf\u95ee\u8fd9\u4e24\u8005\u3002\u8ba9\u6211\u4eec\u770b\u770b\u53ef\u4ee5\u5982\u4f55\u505a\u5230\u8fd9\u4e24\u4e2a\u4e0d\u540c\u7684\u914d\u7f6e\u6587\u4ef6\uff1a<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"application.yaml-\u6587\u4ef6\">8.1. APPLICATION.YAML \u6587\u4ef6<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code># set default profile to 'dev'\nspring.profiles.active: dev\n\n# production database details\nspring.datasource.url: 'jdbc:mysql:\/\/localhost:3306\/toptal'\nspring.datasource.username: root\nspring.datasource.password:<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"application-dev.yaml-\u6587\u4ef6\">APPLICATION-DEV.YAML \u6587\u4ef6<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>spring.datasource.url: 'jdbc:h2:mem:'\nspring.datasource.platform: h2<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5047\u8bbe\u4f60\u4e0d\u5e0c\u671b\u5728\u4fee\u6539\u4ee3\u7801\u65f6\u610f\u5916\u5730\u5bf9\u751f\u4ea7\u6570\u636e\u5e93\u8fdb\u884c\u4efb\u4f55\u64cd\u4f5c\uff0c\u56e0\u6b64\u5c06\u9ed8\u8ba4\u914d\u7f6e\u6587\u4ef6\u8bbe\u4e3a dev \u662f\u5f88\u6709\u610f\u4e49\u7684\u3002\u7136\u540e\uff0c\u5728\u670d\u52a1\u5668\u4e0a\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u63d0\u4f9b\u00a0<code>-Dspring.profiles.active=prod<\/code>\u00a0\u53c2\u6570\u7ed9 JVM \u6765\u624b\u52a8\u8986\u76d6\u914d\u7f6e\u6587\u4ef6\u3002\u53e6\u5916\uff0c\u8fd8\u53ef\u5c06\u64cd\u4f5c\u7cfb\u7edf\u7684\u73af\u5883\u53d8\u91cf\u8bbe\u7f6e\u4e3a\u6240\u9700\u7684\u9ed8\u8ba4 profile\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u5e38\u89c1\u9519\u8bef\u4e5d\u65e0\u6cd5\u63a5\u53d7\u4f9d\u8d56\u9879\u6ce8\u5165\">\u5e38\u89c1\u9519\u8bef\u4e5d\uff1a\u65e0\u6cd5\u63a5\u53d7\u4f9d\u8d56\u9879\u6ce8\u5165<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u6b63\u786e\u4f7f\u7528 Spring \u7684\u4f9d\u8d56\u6ce8\u5165\u610f\u5473\u7740\u5141\u8bb8\u5176\u901a\u8fc7\u626b\u63cf\u6240\u6709\u5fc5\u987b\u7684\u914d\u7f6e\u7c7b\u6765\u5c06\u6240\u6709\u5bf9\u8c61\u8fde\u63a5\u5728\u4e00\u8d77\uff1b\u8fd9\u5bf9\u4e8e\u89e3\u8026\u5173\u7cfb\u975e\u5e38\u6709\u7528\uff0c\u4e5f\u4f7f\u6d4b\u8bd5\u53d8\u5f97\u66f4\u4e3a\u5bb9\u6613\uff0c\u800c\u4e0d\u662f\u901a\u8fc7\u7c7b\u4e4b\u95f4\u7684\u7d27\u8026\u5408\u6765\u505a\u8fd9\u6837\u7684\u4e8b\u60c5\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class TopTalentController {\n\n    private final TopTalentService topTalentService;\n\n    public TopTalentController() {\n        this.topTalentService = new TopTalentService();\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6211\u4eec\u8ba9 Spring \u4e3a\u6211\u4eec\u505a\u8fde\u63a5\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class TopTalentController {\n\n    private final TopTalentService topTalentService;\n\n    public TopTalentController(TopTalentService topTalentService) {\n        this.topTalentService = topTalentService;\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/youtu.be\/RlfLCWKxHJ0?t=5m52s\">Misko Hevery \u7684 Google talk<\/a> \u6df1\u5165\u89e3\u91ca\u4e86\u4f9d\u8d56\u6ce8\u5165\u7684 \u201c\u4e3a\u4ec0\u4e48\u201d\uff0c\u6240\u4ee5\uff0c\u8ba9\u6211\u4eec\u770b\u770b\u5b83\u5728\u5b9e\u8df5\u4e2d\u662f\u5982\u4f55\u4f7f\u7528\u7684\u3002\u5728\u5173\u6ce8\u70b9\u5206\u79bb\uff08\u5e38\u89c1\u9519\u8bef 3\uff09\u4e00\u8282\u4e2d\uff0c\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a\u670d\u52a1\u548c\u63a7\u5236\u5668\u7c7b\u3002\u5047\u8bbe\u6211\u4eec\u60f3\u5728 <code>TopTalentService<\/code>\u00a0\u884c\u4e3a\u6b63\u786e\u7684\u524d\u63d0\u4e0b\u6d4b\u8bd5\u63a7\u5236\u5668\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u63d0\u4f9b\u4e00\u4e2a\u5355\u72ec\u7684\u914d\u7f6e\u7c7b\u6765\u63d2\u5165\u4e00\u4e2a\u6a21\u62df\u5bf9\u8c61\u6765\u4ee3\u66ff\u5b9e\u9645\u7684\u670d\u52a1\u5b9e\u73b0\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@Configuration\npublic class SampleUnitTestConfig {\n    @Bean\n    public TopTalentService topTalentService() {\n        TopTalentService topTalentService = Mockito.mock(TopTalentService.class);\n        Mockito.when(topTalentService.getTopTalent()).thenReturn(\n                Stream.of(\"Mary\", \"Joel\").map(TopTalentData::new).collect(Collectors.toList()));\n        return topTalentService;\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u7136\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u544a\u8bc9 Spring \u4f7f\u7528 SampleUnitTestConfig \u4f5c\u4e3a\u5b83\u7684\u914d\u7f6e\u7c7b\u6765\u6ce8\u5165\u6a21\u62df\u5bf9\u8c61\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@ContextConfiguration(classes = { SampleUnitTestConfig.class })<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e4b\u540e\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u4f7f\u7528\u4e0a\u4e0b\u6587\u914d\u7f6e\u5c06 Bean \u6ce8\u5165\u5230\u5355\u5143\u6d4b\u8bd5\u4e2d\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u5e38\u89c1\u9519\u8bef\u5341\u7f3a\u4e4f\u6d4b\u8bd5\u6216\u6d4b\u8bd5\u4e0d\u5f53\">\u5e38\u89c1\u9519\u8bef\u5341\uff1a\u7f3a\u4e4f\u6d4b\u8bd5\uff0c\u6216\u6d4b\u8bd5\u4e0d\u5f53<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5c3d\u7ba1\u5355\u5143\u6d4b\u8bd5\u7684\u6982\u5ff5\u5df2\u7ecf\u5b58\u5728\u5f88\u957f\u65f6\u95f4\u4e86\uff0c\u4f46\u5f88\u591a\u5f00\u53d1\u4eba\u5458\u4f3c\u4e4e\u8981\u4e48 \u201c\u5fd8\u8bb0\u201d \u505a\u8fd9\u4ef6\u4e8b\uff08\u7279\u522b\u662f\u5982\u679c\u5b83\u4e0d\u662f \u201c\u5fc5\u9700\u201d \u7684\u65f6\u5019\uff09\uff0c\u8981\u4e48\u53ea\u662f\u5728\u4e8b\u540e\u628a\u5b83\u6dfb\u52a0\u8fdb\u6765\u3002\u8fd9\u663e\u7136\u662f\u4e0d\u53ef\u53d6\u7684\uff0c\u56e0\u4e3a\u6d4b\u8bd5\u4e0d\u4ec5\u5e94\u8be5\u9a8c\u8bc1\u4ee3\u7801\u7684\u6b63\u786e\u6027\uff0c\u8fd8\u5e94\u8be5\u4f5c\u4e3a\u7a0b\u5e8f\u5728\u4e0d\u540c\u573a\u666f\u4e0b\u5e94\u5982\u4f55\u8868\u73b0\u7684\u6587\u6863\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u6d4b\u8bd5 Web \u670d\u52a1\u65f6\uff0c\u5f88\u5c11\u53ea\u8fdb\u884c \u201c\u7eaf\u201d \u5355\u5143\u6d4b\u8bd5\uff0c\u56e0\u4e3a\u901a\u8fc7 HTTP \u8fdb\u884c\u901a\u4fe1\u901a\u5e38\u9700\u8981\u8c03\u7528 Spring \u7684\u00a0<code>DispatcherServlet<\/code>\uff0c\u5e76\u67e5\u770b\u5f53\u6536\u5230\u4e00\u4e2a\u5b9e\u9645\u7684\u00a0<code>HttpServletRequest<\/code>\u00a0\u65f6\u4f1a\u53d1\u751f\u4ec0\u4e48\uff08\u4f7f\u5b83\u6210\u4e3a\u4e00\u4e2a \u201c\u96c6\u6210\u201d \u6d4b\u8bd5\uff0c\u5904\u7406\u9a8c\u8bc1\u3001\u5e8f\u5217\u5316\u7b49\uff09\u3002<a href=\"https:\/\/github.com\/rest-assured\/rest-assured\">REST Assured<\/a>\uff0c\u4e00\u4e2a\u7528\u4e8e\u7b80\u5316\u6d4b\u8bd5REST\u670d\u52a1\u7684 Java DSL\uff0c\u5728 MockMVC \u4e4b\u4e0a\uff0c\u5df2\u7ecf\u88ab\u8bc1\u660e\u63d0\u4f9b\u4e86\u4e00\u4e2a\u975e\u5e38\u4f18\u96c5\u7684\u89e3\u51b3\u65b9\u6848\u3002\u8003\u8651\u4ee5\u4e0b\u5e26\u6709\u4f9d\u8d56\u9879\u6ce8\u5165\u7684\u4ee3\u7801\u7247\u6bb5\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@RunWith(SpringJUnit4ClassRunner.class)\n@ContextConfiguration(classes = {\n        Application.class,\n        SampleUnitTestConfig.class\n})\npublic class RestAssuredTestDemonstration {\n\n    @Autowired\n    private TopTalentController topTalentController;\n\n    @Test\n    public void shouldGetMaryAndJoel() throws Exception {\n        \/\/ given\n        MockMvcRequestSpecification givenRestAssuredSpecification = RestAssuredMockMvc.given()\n                .standaloneSetup(topTalentController);\n\n        \/\/ when\n        MockMvcResponse response = givenRestAssuredSpecification.when().get(\"\/toptal\/get\");\n\n        \/\/ then\n        response.then().statusCode(200);\n        response.then().body(\"name\", hasItems(\"Mary\", \"Joel\"));\n    }\n\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">SampleUnitTestConfig \u7c7b\u5c06 TopTalentService \u7684\u6a21\u62df\u5b9e\u73b0\u8fde\u63a5\u5230 TopTalentController \u4e2d\uff0c\u800c\u6240\u6709\u7684\u5176\u4ed6\u7c7b\u90fd\u662f\u901a\u8fc7\u626b\u63cf\u5e94\u7528\u7c7b\u6240\u5728\u5305\u7684\u4e0b\u7ea7\u5305\u76ee\u5f55\u6765\u63a8\u65ad\u51fa\u7684\u6807\u51c6\u914d\u7f6e\u3002RestAssuredMockMvc \u53ea\u662f\u7528\u6765\u8bbe\u7f6e\u4e00\u4e2a\u8f7b\u91cf\u7ea7\u73af\u5883\uff0c\u5e76\u5411 \/toptal\/get \u7aef\u70b9\u53d1\u9001\u4e00\u4e2a GET \u8bf7\u6c42\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u539f\u6587\uff1a<a href=\"https:\/\/www.toptal.com\/spring\/top-10-most-common-spring-framework-mistakes\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"https:\/\/www.toptal.com\/spring\/top-10-most-common-spring-framework-mistakes\uff08\u5728\u65b0\u7a97\u53e3\u6253\u5f00\uff09\">https:\/\/www.toptal.com\/spring\/top-10-most-common-spring-framework-mistakes<\/a><br>\u4f5c\u8005\uff1aToni Kukurin<br>\u8bd1\u8005\uff1a\u4e07\u60f3<\/p>\n<!-- <audio autoplay=\"autoplay\" height=\"100\" width=\"100\" hidden=\"true\"><source src=\"https:\/\/c.coka.la\/orAvPR.mp3\" type=\"audio\/mp3\"\/><\/audio><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/ws3.sinaimg.cn\/large\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/> --><p><!-- <img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/>--><img decoding=\"async\" src=\"https:\/\/saas.51autoparts.cn\/api\/admin\/sys-file\/oss\/file?fileName=84db51f8561e448f9a4fda2eff0811f9.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/><\/p><p>\u6700\u540e\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u4e2a\u4eba\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u4e1a\u4f59\u8349\uff08yyucao\uff09\uff01<b>\u53ef\u52a0\u4f5c\u8005\u5fae\u4fe1\u53f7\uff1a<font color=\"red\">xttblog2<\/font>\u3002\u5907\u6ce8\uff1a\u201c1\u201d\uff0c\u6dfb\u52a0\u535a\u4e3b\u5fae\u4fe1\u62c9\u4f60\u8fdb\u5fae\u4fe1\u7fa4\u3002\u5907\u6ce8\u9519\u8bef\u4e0d\u4f1a\u540c\u610f\u597d\u53cb\u7533\u8bf7\u3002<\/b>\u518d\u6b21\u611f\u8c22\u60a8\u7684\u5173\u6ce8\uff01\u540e\u7eed\u6709\u7cbe\u5f69\u5185\u5bb9\u4f1a\u7b2c\u4e00\u65f6\u95f4\u53d1\u7ed9\u60a8\uff01\u539f\u521b\u6587\u7ae0\u6295\u7a3f\u8bf7\u53d1\u9001\u81f3532009913@qq.com\u90ae\u7bb1\u3002\u5546\u52a1\u5408\u4f5c\u4e5f\u53ef\u6dfb\u52a0\u4f5c\u8005\u5fae\u4fe1\u8fdb\u884c\u8054\u7cfb\uff01<\/p><p>\u672c\u6587\u539f\u6587\u51fa\u5904\uff1a<a href=\"https:\/\/www.xttblog.com\">\u4e1a\u4f59\u8349<\/a>\uff1a &raquo; <a href=\"https:\/\/www.xttblog.com\/?p=4765\">Spring \u5e38\u72af\u7684\u5341\u5927\u9519\u8bef\uff0c\u6253\u6b7b\u90fd\u4e0d\u8981\u72af\uff01<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>Spring \u53ef\u4ee5\u8bf4\u662f\u6700\u6d41\u884c\u7684 Java \u6846\u67b6\u4e4b\u4e00\uff0c\u4e5f\u662f\u4e00\u53ea\u9700\u8981\u9a6f\u670d\u7684\u5f3a\u5927\u91ce\u517d\u3002\u867d\u7136\u5b83\u7684\u57fa\u672c\u6982\u5ff5\u76f8\u5f53\u5bb9\u6613\u638c\u63e1\uff0c [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[551,587,1522,413,414],"class_list":["post-4765","post","type-post","status-publish","format-standard","hentry","category-java","tag-spring","tag-spring-boot","tag-springboot","tag-springmvc"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/4765","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4765"}],"version-history":[{"count":2,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/4765\/revisions"}],"predecessor-version":[{"id":4767,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/4765\/revisions\/4767"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4765"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4765"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4765"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}