{"id":24515,"date":"2024-11-21T10:14:14","date_gmt":"2024-11-21T02:14:14","guid":{"rendered":"https:\/\/fwq.ai\/blog\/24515\/"},"modified":"2024-11-21T10:14:14","modified_gmt":"2024-11-21T02:14:14","slug":"%e8%bf%90%e7%94%a8webman%e6%8a%80%e6%9c%af%e6%89%93%e9%80%a0%e6%97%a0%e4%ba%ba%e9%a9%be%e9%a9%b6%e9%a2%86%e5%9f%9f%e7%9a%84%e5%ba%94%e7%94%a8","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/24515\/","title":{"rendered":"\u8fd0\u7528WebMan\u6280\u672f\u6253\u9020\u65e0\u4eba\u9a7e\u9a76\u9886\u57df\u7684\u5e94\u7528"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/465\/014\/169302170518654.jpg\" class=\"aligncenter\" title=\"\u8fd0\u7528WebMan\u6280\u672f\u6253\u9020\u65e0\u4eba\u9a7e\u9a76\u9886\u57df\u7684\u5e94\u7528\u63d2\u56fe\" alt=\"\u8fd0\u7528WebMan\u6280\u672f\u6253\u9020\u65e0\u4eba\u9a7e\u9a76\u9886\u57df\u7684\u5e94\u7528\u63d2\u56fe\" \/><\/p>\n<p>\u8fd0\u7528WebMan\u6280\u672f\u6253\u9020\u65e0\u4eba\u9a7e\u9a76\u9886\u57df\u7684\u5e94\u7528<\/p>\n<p>\u968f\u7740\u79d1\u6280\u7684\u4e0d\u65ad\u8fdb\u6b65\u548c\u4eba\u5de5\u667a\u80fd\u7684\u5feb\u901f\u53d1\u5c55\uff0c\u65e0\u4eba\u9a7e\u9a76\u8f66\u8f86\u9010\u6e10\u6210\u4e3a\u4e86\u6c7d\u8f66\u5de5\u4e1a\u7684\u70ed\u95e8\u8bdd\u9898\u3002WebMan\u662f\u4e00\u79cd\u7528\u4e8e\u5f00\u53d1Web\u5e94\u7528\u7a0b\u5e8f\u7684\u6280\u672f\uff0c\u5b83\u80fd\u591f\u5e94\u7528\u5728\u65e0\u4eba\u9a7e\u9a76\u9886\u57df\uff0c\u5b9e\u73b0\u8f66\u8f86\u8fdc\u7a0b\u64cd\u63a7\u3001\u6570\u636e\u76d1\u63a7\u548c\u8f66\u8f86\u4fe1\u606f\u7ba1\u7406\u7b49\u529f\u80fd\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528WebMan\u6280\u672f\u6765\u6784\u5efa\u65e0\u4eba\u9a7e\u9a76\u9886\u57df\u7684\u5e94\u7528\uff0c\u5e76\u901a\u8fc7\u4ee3\u7801\u793a\u4f8b\u6765\u8bf4\u660e\u5176\u5b9e\u73b0\u8fc7\u7a0b\u3002<\/p>\n<h2>1. \u73af\u5883\u51c6\u5907<\/h2>\n<p>\u5728\u4f7f\u7528WebMan\u6280\u672f\u4e4b\u524d\uff0c\u9700\u8981\u51c6\u5907\u73af\u5883\u3002\u9996\u5148\uff0c\u786e\u4fdd\u4f60\u7684\u7535\u8111\u4e0a\u5df2\u7ecf\u5b89\u88c5\u4e86Java SDK\u548cWebMan\u6846\u67b6\u3002\u53ef\u4ee5\u5728\u5b98\u65b9\u7f51\u7ad9\u4e0a\u4e0b\u8f7d\u5e76\u5b89\u88c5\u6700\u65b0\u7248\u672c\u3002\u540c\u65f6\uff0c\u8fd8\u9700\u8981\u4f7f\u7528\u4e00\u4e2aIDE\uff08\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff09\u6765\u7f16\u5199\u548c\u8fd0\u884c\u4ee3\u7801\uff0c\u6bd4\u5982Eclipse\u6216IntelliJ IDEA\u3002<\/p>\n<h2>2. \u521b\u5efaWeb\u5e94\u7528\u7a0b\u5e8f<\/h2>\n<p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Web\u5e94\u7528\u7a0b\u5e8f\u6765\u5b9e\u73b0\u65e0\u4eba\u9a7e\u9a76\u8f66\u8f86\u7684\u529f\u80fd\u3002\u6253\u5f00\u4f60\u7684IDE\uff0c\u9009\u62e9\u65b0\u5efa\u9879\u76ee\uff0c\u9009\u62e9WebMan\u6a21\u677f\uff0c\u5e76\u586b\u5199\u9879\u76ee\u540d\u79f0\u3002IDE\u4f1a\u81ea\u52a8\u751f\u6210\u57fa\u672c\u7684\u9879\u76ee\u7ed3\u6784\u548c\u914d\u7f6e\u6587\u4ef6\u3002<\/p>\n<p>\u5728\u521b\u5efa\u7684\u9879\u76ee\u4e2d\uff0c\u53ef\u4ee5\u770b\u5230\u4e00\u4e2a\u540d\u4e3a&#8221;src&#8221;\u7684\u6587\u4ef6\u5939\uff0c\u8fd9\u662f\u7528\u6765\u5b58\u653e\u4f60\u7684Java\u4ee3\u7801\u7684\u5730\u65b9\u3002\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a&#8221;MainClass&#8221;\u7684Java\u7c7b\uff0c\u5e76\u7f16\u5199\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<pre>import io.webman.WebManApplication;\nimport io.webman.annotation.RequestMapping;\nimport io.webman.annotation.RequestMethod;\nimport io.webman.annotation.RestController;\nimport io.webman.route.RouteResponse;\n\n@RestController\npublic class MainClass {\n\n    @RequestMapping(value = \"\/\", method = RequestMethod.GET)\n    public String helloWorld() {\n        return \"Hello, World!\";\n    }\n\n    @RequestMapping(value = \"\/drive\", method = RequestMethod.GET)\n    public RouteResponse drive() {\n        \/\/ Add your code for controlling the self-driving car here\n        return new RouteResponse(\"The car is driving...\");\n    }\n\n    @RequestMapping(value = \"\/data\", method = RequestMethod.GET)\n    public RouteResponse getData() {\n        \/\/ Add your code for getting car's data here\n        return new RouteResponse(\"Car data: ...\");\n    }\n\n    @RequestMapping(value = \"\/manage\", method = RequestMethod.POST)\n    public RouteResponse manage() {\n        \/\/ Add your code for managing the car here\n        return new RouteResponse(\"Managing car...\");\n    }\n\n    public static void main(String[] args) {\n        WebManApplication.run(MainClass.class, args);\n    }\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u8be5\u4ee3\u7801\u793a\u4f8b\u521b\u5efa\u4e86\u4e00\u4e2a\u540d\u4e3a&#8221;MainClass&#8221;\u7684Java\u7c7b\uff0c\u4f7f\u7528\u4e86WebMan\u6846\u67b6\u7684\u6ce8\u89e3\u6765\u5b9a\u4e49\u4e0d\u540c\u7684\u8def\u7531\u548c\u8bf7\u6c42\u65b9\u5f0f\u3002\u5728&#8221;helloWorld&#8221;\u65b9\u6cd5\u4e2d\uff0c\u8fd4\u56de\u4e86\u4e00\u4e2a\u7b80\u5355\u7684\u5b57\u7b26\u4e32\u4f5c\u4e3a\u793a\u4f8b\u3002\u5728&#8221;drive&#8221;\u65b9\u6cd5\u4e2d\uff0c\u4f60\u53ef\u4ee5\u6dfb\u52a0\u63a7\u5236\u65e0\u4eba\u9a7e\u9a76\u8f66\u8f86\u7684\u4ee3\u7801\u3002\u540c\u6837\u5730\uff0c\u5728&#8221;getData&#8221;\u548c&#8221;manage&#8221;\u65b9\u6cd5\u4e2d\uff0c\u53ef\u4ee5\u6dfb\u52a0\u83b7\u53d6\u8f66\u8f86\u6570\u636e\u548c\u7ba1\u7406\u8f66\u8f86\u7684\u4ee3\u7801\u3002<\/p>\n<h2>3. \u8fd0\u884c\u548c\u6d4b\u8bd5<\/h2>\n<p>\u5728\u5b8c\u6210\u4ee3\u7801\u7684\u7f16\u5199\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u8fd0\u884c\u548c\u6d4b\u8bd5\u5e94\u7528\u7a0b\u5e8f\u4e86\u3002\u5728IDE\u4e2d\uff0c\u9009\u62e9&#8221;Run&#8221;\u6216&#8221;Debug&#8221;\u6765\u8fd0\u884c\u4f60\u7684Web\u5e94\u7528\u7a0b\u5e8f\u3002\u4e00\u65e6\u5e94\u7528\u7a0b\u5e8f\u542f\u52a8\u6210\u529f\uff0c\u4f60\u53ef\u4ee5\u5728\u6d4f\u89c8\u5668\u4e2d\u8f93\u5165&#8221;http:\/\/localhost:8080&#8243;\u6765\u8bbf\u95ee\u4f60\u7684\u5e94\u7528\u3002<\/p>\n<p>\u5f53\u8bbf\u95ee&#8221;http:\/\/localhost:8080&#8243;\u65f6\uff0c\u4f60\u4f1a\u770b\u5230\u4e00\u4e2a\u663e\u793a&#8221;Hello, World!&#8221;\u7684\u9875\u9762\u3002\u8fd9\u662f\u56e0\u4e3a\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2a\u5904\u7406\u6839\u8def\u7531\u7684\u65b9\u6cd5\uff0c\u5e76\u8fd4\u56de\u4e86\u4e00\u4e2a\u5b57\u7b26\u4e32\u4f5c\u4e3a\u54cd\u5e94\u3002<\/p>\n<p>\u5982\u679c\u9700\u8981\u6d4b\u8bd5\u5176\u4ed6\u7684\u529f\u80fd\uff0c\u53ef\u4ee5\u5728\u6d4f\u89c8\u5668\u4e2d\u8f93\u5165&#8221;http:\/\/localhost:8080\/drive&#8221;\u6765\u6d4b\u8bd5\u65e0\u4eba\u9a7e\u9a76\u8f66\u8f86\u7684\u63a7\u5236\u529f\u80fd\uff0c\u6216\u8005\u8f93\u5165&#8221;http:\/\/localhost:8080\/data&#8221;\u6765\u6d4b\u8bd5\u83b7\u53d6\u8f66\u8f86\u6570\u636e\u7684\u529f\u80fd\u3002\u6839\u636e\u5b9e\u9645\u9700\u6c42\uff0c\u4f60\u53ef\u4ee5\u5728\u76f8\u5173\u65b9\u6cd5\u4e2d\u6dfb\u52a0\u81ea\u5df1\u7684\u4ee3\u7801\u6765\u5b9e\u73b0\u529f\u80fd\u3002<\/p>\n<h2>4. \u7ed3\u8bed<\/h2>\n<p>\u672c\u6587\u4ecb\u7ecd\u4e86\u5982\u4f55\u4f7f\u7528WebMan\u6280\u672f\u6765\u6784\u5efa\u65e0\u4eba\u9a7e\u9a76\u9886\u57df\u7684\u5e94\u7528\u3002\u901a\u8fc7\u7f16\u5199Java\u4ee3\u7801\uff0c\u6211\u4eec\u80fd\u591f\u5b9e\u73b0\u65e0\u4eba\u9a7e\u9a76\u8f66\u8f86\u7684\u8fdc\u7a0b\u64cd\u63a7\u3001\u6570\u636e\u76d1\u63a7\u548c\u8f66\u8f86\u4fe1\u606f\u7ba1\u7406\u7b49\u529f\u80fd\u3002\u5e0c\u671b\u672c\u6587\u80fd\u591f\u5e2e\u52a9\u4f60\u8fdb\u4e00\u6b65\u4e86\u89e3\u548c\u5e94\u7528WebMan\u6280\u672f\uff0c\u5728\u65e0\u4eba\u9a7e\u9a76\u8f66\u8f86\u7684\u53d1\u5c55\u4e2d\u505a\u51fa\u8d21\u732e\uff01<\/p>\n<p>\uff08\u6ce8\uff1a\u6b64\u6587\u4e3a\u793a\u4f8b\u6587\u7ae0\uff0c\u4ee3\u7801\u672a\u7ecf\u5b8c\u6574\u6d4b\u8bd5\uff0c\u8bf7\u6839\u636e\u5177\u4f53\u60c5\u51b5\u8fdb\u884c\u8c03\u6574\u548c\u6539\u8fdb\u3002\uff09<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u8fd0\u7528WebMan\u6280\u672f\u6253\u9020\u65e0\u4eba\u9a7e\u9a76\u9886\u57df\u7684\u5e94\u7528\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>\u8fd0\u7528WebMan\u6280\u672f\u6253\u9020\u65e0\u4eba\u9a7e\u9a76\u9886\u57df\u7684\u5e94\u7528 \u968f\u7740\u79d1\u6280\u7684\u4e0d\u65ad\u8fdb\u6b65\u548c\u4eba\u5de5\u667a\u80fd\u7684\u5feb\u901f\u53d1\u5c55\uff0c\u65e0\u4eba\u9a7e\u9a76\u8f66\u8f86\u9010\u6e10\u6210\u4e3a\u4e86\u6c7d\u8f66\u5de5\u4e1a\u7684\u70ed\u95e8\u8bdd\u9898\u3002WebMan\u662f\u4e00\u79cd\u7528\u4e8e\u5f00\u53d1Web\u5e94\u7528\u7a0b\u5e8f\u7684\u6280\u672f\uff0c\u5b83\u80fd\u591f\u5e94\u7528\u5728\u65e0\u4eba\u9a7e\u9a76\u9886\u57df\uff0c\u5b9e\u73b0\u8f66\u8f86\u8fdc\u7a0b\u64cd\u63a7\u3001\u6570\u636e\u76d1\u63a7\u548c\u8f66\u8f86\u4fe1\u606f\u7ba1\u7406\u7b49\u529f\u80fd\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528WebMan\u6280\u672f\u6765\u6784\u5efa\u65e0\u4eba\u9a7e\u9a76\u9886\u57df\u7684\u5e94\u7528\uff0c\u5e76\u901a\u8fc7\u4ee3\u7801\u793a\u4f8b\u6765\u8bf4\u660e\u5176\u5b9e\u73b0\u8fc7\u7a0b\u3002 1. \u73af\u5883\u51c6\u5907 \u5728\u4f7f\u7528WebMan\u6280\u672f\u4e4b\u524d\uff0c\u9700\u8981\u51c6\u5907\u73af\u5883\u3002\u9996\u5148\uff0c\u786e\u4fdd\u4f60\u7684\u7535\u8111\u4e0a\u5df2\u7ecf\u5b89\u88c5\u4e86Java SDK\u548cWebMan\u6846\u67b6\u3002\u53ef\u4ee5\u5728\u5b98\u65b9\u7f51\u7ad9\u4e0a\u4e0b\u8f7d\u5e76\u5b89\u88c5\u6700\u65b0\u7248\u672c\u3002\u540c\u65f6\uff0c\u8fd8\u9700\u8981\u4f7f\u7528\u4e00\u4e2aIDE\uff08\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff09\u6765\u7f16\u5199\u548c\u8fd0\u884c\u4ee3\u7801\uff0c\u6bd4\u5982Eclipse\u6216IntelliJ IDEA\u3002 2. \u521b\u5efaWeb\u5e94\u7528\u7a0b\u5e8f \u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Web\u5e94\u7528\u7a0b\u5e8f\u6765\u5b9e\u73b0\u65e0\u4eba\u9a7e\u9a76\u8f66\u8f86\u7684\u529f\u80fd\u3002\u6253\u5f00\u4f60\u7684IDE\uff0c\u9009\u62e9\u65b0\u5efa\u9879\u76ee\uff0c\u9009\u62e9WebMan\u6a21\u677f\uff0c\u5e76\u586b\u5199\u9879\u76ee\u540d\u79f0\u3002IDE\u4f1a\u81ea\u52a8\u751f\u6210\u57fa\u672c\u7684\u9879\u76ee\u7ed3\u6784\u548c\u914d\u7f6e\u6587\u4ef6\u3002 \u5728\u521b\u5efa\u7684\u9879\u76ee\u4e2d\uff0c\u53ef\u4ee5\u770b\u5230\u4e00\u4e2a\u540d\u4e3a&#8221;src&#8221;\u7684\u6587\u4ef6\u5939\uff0c\u8fd9\u662f\u7528\u6765\u5b58\u653e\u4f60\u7684Java\u4ee3\u7801\u7684\u5730\u65b9\u3002\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a&#8221;MainClass&#8221;\u7684Java\u7c7b\uff0c\u5e76\u7f16\u5199\u4ee5\u4e0b\u4ee3\u7801\uff1a import io.webman.WebManApplication; import io.webman.annotation.RequestMapping; import io.webman.annotation.RequestMethod; import io.webman.annotation.RestController; import io.webman.route.RouteResponse; @RestController public class MainClass { @RequestMapping(value = &#8220;\/&#8221;, method = RequestMethod.GET) public String helloWorld() { return &#8220;Hello, World!&#8221;; } @RequestMapping(value = &#8220;\/drive&#8221;, method = RequestMethod.GET) public RouteResponse drive() { \/\/ Add your code for [&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-24515","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/24515","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=24515"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/24515\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=24515"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=24515"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=24515"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}