{"id":24559,"date":"2024-11-21T08:51:52","date_gmt":"2024-11-21T00:51:52","guid":{"rendered":"https:\/\/fwq.ai\/blog\/24559\/"},"modified":"2024-11-21T08:51:52","modified_gmt":"2024-11-21T00:51:52","slug":"%e5%a6%82%e4%bd%95%e9%80%9a%e8%bf%87webman%e6%8a%80%e6%9c%af%e5%ae%9e%e7%8e%b0%e5%9c%a8%e7%ba%bf%e8%af%81%e5%88%b8%e4%ba%a4%e6%98%93%e7%b3%bb%e7%bb%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/24559\/","title":{"rendered":"\u5982\u4f55\u901a\u8fc7WebMan\u6280\u672f\u5b9e\u73b0\u5728\u7ebf\u8bc1\u5238\u4ea4\u6613\u7cfb\u7edf"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/887\/227\/169306058058312.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u901a\u8fc7WebMan\u6280\u672f\u5b9e\u73b0\u5728\u7ebf\u8bc1\u5238\u4ea4\u6613\u7cfb\u7edf\u63d2\u56fe\" alt=\"\u5982\u4f55\u901a\u8fc7WebMan\u6280\u672f\u5b9e\u73b0\u5728\u7ebf\u8bc1\u5238\u4ea4\u6613\u7cfb\u7edf\u63d2\u56fe\" \/><\/p>\n<p>\u5982\u4f55\u901a\u8fc7WebMan\u6280\u672f\u5b9e\u73b0\u5728\u7ebf\u8bc1\u5238\u4ea4\u6613\u7cfb\u7edf<\/p>\n<p>WebMan\u6280\u672f\u662f\u4e00\u79cd\u57fa\u4e8eWeb\u7684\u7ba1\u7406\u6280\u672f\uff0c\u901a\u8fc7WebMan\u6280\u672f\u53ef\u4ee5\u65b9\u4fbf\u5730\u5b9e\u73b0\u5728\u7ebf\u8bc1\u5238\u4ea4\u6613\u7cfb\u7edf\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u5229\u7528WebMan\u6280\u672f\u642d\u5efa\u4e00\u4e2a\u7b80\u5355\u7684\u5728\u7ebf\u8bc1\u5238\u4ea4\u6613\u7cfb\u7edf\uff0c\u5e76\u7ed9\u51fa\u76f8\u5173\u7684\u4ee3\u7801\u793a\u4f8b\u3002<\/p>\n<p>\u5728\u7ebf\u8bc1\u5238\u4ea4\u6613\u7cfb\u7edf\u662f\u73b0\u4ee3\u91d1\u878d\u9886\u57df\u975e\u5e38\u91cd\u8981\u7684\u5e94\u7528\u4e4b\u4e00\uff0c\u5b83\u53ef\u4ee5\u65b9\u4fbf\u5730\u8ba9\u6295\u8d44\u8005\u8fdb\u884c\u8bc1\u5238\u4ea4\u6613\uff0c\u5728\u7ebf\u67e5\u8be2\u80a1\u7968\u884c\u60c5\u4ee5\u53ca\u8d26\u6237\u4fe1\u606f\u7b49\u3002\u5229\u7528WebMan\u6280\u672f\uff0c\u6211\u4eec\u53ef\u4ee5\u5feb\u901f\u5730\u642d\u5efa\u8fd9\u6837\u4e00\u4e2a\u7cfb\u7edf\uff0c\u5e76\u4e14\u63d0\u4f9b\u826f\u597d\u7684\u7528\u6237\u4f53\u9a8c\u548c\u53ef\u9760\u7684\u4ea4\u6613\u5b89\u5168\u3002<\/p>\n<p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u521b\u5efa\u4e00\u4e2aWeb\u5e94\u7528\u7a0b\u5e8f\u6765\u5b9e\u73b0\u8bc1\u5238\u4ea4\u6613\u7cfb\u7edf\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Java\u8bed\u8a00\u548cSpring\u6846\u67b6\u6765\u642d\u5efa\u8fd9\u4e2a\u7cfb\u7edf\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u4ee3\u7801\u793a\u4f8b\uff1a<\/p>\n<pre>@RestController\n@RequestMapping(\"\/securities\")\npublic class SecuritiesController {\n\n    @Autowired\n    private SecuritiesService securitiesService;\n\n    @RequestMapping(method = RequestMethod.GET)\n    public List&lt;security&gt; getAllSecurities() {\n        return securitiesService.getAllSecurities();\n    }\n\n    @RequestMapping(value = \"\/{id}\", method = RequestMethod.GET)\n    public Security getSecurityById(@PathVariable int id) {\n        return securitiesService.getSecurityById(id);\n    }\n\n    @RequestMapping(method = RequestMethod.POST)\n    public void addSecurity(@RequestBody Security security) {\n        securitiesService.addSecurity(security);\n    }\n\n    @RequestMapping(value = \"\/{id}\", method = RequestMethod.PUT)\n    public void updateSecurity(@PathVariable int id, @RequestBody Security security) {\n        securitiesService.updateSecurity(id, security);\n    }\n\n    @RequestMapping(value = \"\/{id}\", method = RequestMethod.DELETE)\n    public void deleteSecurity(@PathVariable int id) {\n        securitiesService.deleteSecurity(id);\n    }\n}\n\n\n@Service\npublic class SecuritiesService {\n\n    private List&lt;security&gt; securities;\n\n    public SecuritiesService() {\n        securities = new ArrayList();\n        securities.add(new Security(1, \"Apple Inc.\", \"AAPL\", \"Technology\"));\n        securities.add(new Security(2, \"Microsoft Corporation\", \"MSFT\", \"Technology\"));\n        securities.add(new Security(3, \"Alphabet Inc.\", \"GOOGL\", \"Technology\"));\n    }\n\n    public List&lt;security&gt; getAllSecurities() {\n        return securities;\n    }\n\n    public Security getSecurityById(int id) {\n        return securities.stream().filter(s -&amp;gt; s.getId() == id).findFirst().orElse(null);\n    }\n\n    public void addSecurity(Security security) {\n        securities.add(security);\n    }\n\n    public void updateSecurity(int id, Security security) {\n        Security existingSecurity = getSecurityById(id);\n        if (existingSecurity != null) {\n            existingSecurity.setName(security.getName());\n            existingSecurity.setCode(security.getCode());\n            existingSecurity.setCategory(security.getCategory());\n        }\n    }\n\n    public void deleteSecurity(int id) {\n        Security existingSecurity = getSecurityById(id);\n        if (existingSecurity != null) {\n            securities.remove(existingSecurity);\n        }\n    }\n}\n\n\npublic class Security {\n\n    private int id;\n    private String name;\n    private String code;\n    private String category;\n\n    public Security(int id, String name, String code, String category) {\n        this.id = id;\n        this.name = name;\n        this.code = code;\n        this.category = category;\n    }\n\n    \/\/ getters and setters omitted for brevity\n}&lt;\/security&gt;&lt;\/security&gt;&lt;\/security&gt;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5728\u4e0a\u8ff0\u7684\u4ee3\u7801\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a\u540d\u4e3aSecuritiesController\u7684\u63a7\u5236\u5668\u7c7b\uff0c\u7528\u6765\u5904\u7406\u8bc1\u5238\u76f8\u5173\u7684HTTP\u8bf7\u6c42\u3002\u8fd9\u4e2a\u63a7\u5236\u5668\u4e2d\u5b9a\u4e49\u4e86\u83b7\u53d6\u6240\u6709\u8bc1\u5238\u3001\u6839\u636eID\u83b7\u53d6\u8bc1\u5238\u3001\u6dfb\u52a0\u8bc1\u5238\u3001\u66f4\u65b0\u8bc1\u5238\u4ee5\u53ca\u5220\u9664\u8bc1\u5238\u7684API\u63a5\u53e3\u3002\u8fd9\u4e9b\u63a5\u53e3\u7684\u5b9e\u73b0\u903b\u8f91\u90fd\u59d4\u6258\u7ed9\u4e86SecuritiesService\u7c7b\u3002<\/p>\n<p>SecuritiesService\u7c7b\u8d1f\u8d23\u7ba1\u7406\u8bc1\u5238\u7684\u6570\u636e\uff0c\u5e76\u4e14\u63d0\u4f9b\u57fa\u672c\u7684CRUD\u64cd\u4f5c\u3002\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528\u4e00\u4e2a\u7b80\u5355\u7684List\u6765\u6a21\u62df\u6570\u636e\u5e93\u4e2d\u7684\u8bc1\u5238\u6570\u636e\u3002<\/p>\n<p>\u6700\u540e\uff0c\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2aSecurity\u7c7b\u6765\u8868\u793a\u8bc1\u5238\u7684\u6570\u636e\u6a21\u578b\u3002\u8fd9\u4e2a\u7c7b\u4e2d\u5305\u542b\u8bc1\u5238\u7684ID\u3001\u540d\u79f0\u3001\u4ee3\u7801\u548c\u7c7b\u522b\u7b49\u5c5e\u6027\u3002<\/p>\n<p>\u901a\u8fc7\u4e0a\u8ff0\u7684\u4ee3\u7801\u793a\u4f8b\uff0c\u6211\u4eec\u53ef\u4ee5\u5feb\u901f\u5730\u642d\u5efa\u4e00\u4e2a\u7b80\u5355\u7684\u5728\u7ebf\u8bc1\u5238\u4ea4\u6613\u7cfb\u7edf\u3002\u5f53\u7136\uff0c\u8fd9\u53ea\u662f\u4e00\u4e2a\u793a\u4f8b\uff0c\u5b9e\u9645\u7684\u8bc1\u5238\u4ea4\u6613\u7cfb\u7edf\u9700\u8981\u8003\u8651\u66f4\u591a\u7684\u5b89\u5168\u6027\u3001\u6027\u80fd\u548c\u53ef\u6269\u5c55\u6027\u7b49\u65b9\u9762\u7684\u9700\u6c42\u3002<\/p>\n<p>\u603b\u7ed3\u8d77\u6765\uff0c\u901a\u8fc7WebMan\u6280\u672f\u5b9e\u73b0\u5728\u7ebf\u8bc1\u5238\u4ea4\u6613\u7cfb\u7edf\u53ef\u4ee5\u63d0\u4f9b\u4fbf\u6377\u7684\u4ea4\u6613\u65b9\u5f0f\u548c\u67e5\u8be2\u529f\u80fd\uff0c\u4e3a\u6295\u8d44\u8005\u63d0\u4f9b\u4e86\u66f4\u597d\u7684\u4ea4\u6613\u4f53\u9a8c\u3002\u8fd9\u4e9b\u793a\u4f8b\u4ee3\u7801\u53ef\u4ee5\u4f5c\u4e3a\u642d\u5efa\u8bc1\u5238\u4ea4\u6613\u7cfb\u7edf\u7684\u57fa\u7840\uff0c\u5f00\u53d1\u4eba\u5458\u53ef\u4ee5\u6839\u636e\u5b9e\u9645\u9700\u6c42\u8fdb\u884c\u5b9a\u5236\u548c\u6269\u5c55\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u901a\u8fc7WebMan\u6280\u672f\u5b9e\u73b0\u5728\u7ebf\u8bc1\u5238\u4ea4\u6613\u7cfb\u7edf\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>\u5982\u4f55\u901a\u8fc7WebMan\u6280\u672f\u5b9e\u73b0\u5728\u7ebf\u8bc1\u5238\u4ea4\u6613\u7cfb\u7edf WebMan\u6280\u672f\u662f\u4e00\u79cd\u57fa\u4e8eWeb\u7684\u7ba1\u7406\u6280\u672f\uff0c\u901a\u8fc7WebMan\u6280\u672f\u53ef\u4ee5\u65b9\u4fbf\u5730\u5b9e\u73b0\u5728\u7ebf\u8bc1\u5238\u4ea4\u6613\u7cfb\u7edf\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u5229\u7528WebMan\u6280\u672f\u642d\u5efa\u4e00\u4e2a\u7b80\u5355\u7684\u5728\u7ebf\u8bc1\u5238\u4ea4\u6613\u7cfb\u7edf\uff0c\u5e76\u7ed9\u51fa\u76f8\u5173\u7684\u4ee3\u7801\u793a\u4f8b\u3002 \u5728\u7ebf\u8bc1\u5238\u4ea4\u6613\u7cfb\u7edf\u662f\u73b0\u4ee3\u91d1\u878d\u9886\u57df\u975e\u5e38\u91cd\u8981\u7684\u5e94\u7528\u4e4b\u4e00\uff0c\u5b83\u53ef\u4ee5\u65b9\u4fbf\u5730\u8ba9\u6295\u8d44\u8005\u8fdb\u884c\u8bc1\u5238\u4ea4\u6613\uff0c\u5728\u7ebf\u67e5\u8be2\u80a1\u7968\u884c\u60c5\u4ee5\u53ca\u8d26\u6237\u4fe1\u606f\u7b49\u3002\u5229\u7528WebMan\u6280\u672f\uff0c\u6211\u4eec\u53ef\u4ee5\u5feb\u901f\u5730\u642d\u5efa\u8fd9\u6837\u4e00\u4e2a\u7cfb\u7edf\uff0c\u5e76\u4e14\u63d0\u4f9b\u826f\u597d\u7684\u7528\u6237\u4f53\u9a8c\u548c\u53ef\u9760\u7684\u4ea4\u6613\u5b89\u5168\u3002 \u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u521b\u5efa\u4e00\u4e2aWeb\u5e94\u7528\u7a0b\u5e8f\u6765\u5b9e\u73b0\u8bc1\u5238\u4ea4\u6613\u7cfb\u7edf\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Java\u8bed\u8a00\u548cSpring\u6846\u67b6\u6765\u642d\u5efa\u8fd9\u4e2a\u7cfb\u7edf\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u4ee3\u7801\u793a\u4f8b\uff1a @RestController @RequestMapping(&#8220;\/securities&#8221;) public class SecuritiesController { @Autowired private SecuritiesService securitiesService; @RequestMapping(method = RequestMethod.GET) public List&lt;security&gt; getAllSecurities() { return securitiesService.getAllSecurities(); } @RequestMapping(value = &#8220;\/{id}&#8221;, method = RequestMethod.GET) public Security getSecurityById(@PathVariable int id) { return securitiesService.getSecurityById(id); } @RequestMapping(method = RequestMethod.POST) public void addSecurity(@RequestBody Security security) { securitiesService.addSecurity(security); } @RequestMapping(value = &#8220;\/{id}&#8221;, method = [&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-24559","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/24559","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=24559"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/24559\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=24559"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=24559"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=24559"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}