{"id":24123,"date":"2024-11-21T15:14:26","date_gmt":"2024-11-21T07:14:26","guid":{"rendered":"https:\/\/fwq.ai\/blog\/24123\/"},"modified":"2024-11-21T15:14:26","modified_gmt":"2024-11-21T07:14:26","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8webman%e6%a1%86%e6%9e%b6%e5%ae%9e%e7%8e%b0%e6%97%a5%e5%8e%86%e5%92%8c%e4%ba%8b%e4%bb%b6%e6%8f%90%e9%86%92%e5%8a%9f%e8%83%bd%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/24123\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528Webman\u6846\u67b6\u5b9e\u73b0\u65e5\u5386\u548c\u4e8b\u4ef6\u63d0\u9192\u529f\u80fd\uff1f"},"content":{"rendered":"<p>\u5982\u4f55\u4f7f\u7528webman\u6846\u67b6\u5b9e\u73b0\u65e5\u5386\u548c\u4e8b\u4ef6\u63d0\u9192\u529f\u80fd\uff1f<\/p>\n<p>\u5f15\u8a00\uff1a<br \/>\u5728\u73b0\u4ee3\u793e\u4f1a\u4e2d\uff0c\u65f6\u95f4\u7ba1\u7406\u53d8\u5f97\u8d8a\u6765\u8d8a\u91cd\u8981\u3002\u4f5c\u4e3a\u5f00\u53d1\u8005\uff0c\u6211\u4eec\u53ef\u4ee5\u5229\u7528Webman\u6846\u67b6\u6765\u6784\u5efa\u4e00\u4e2a\u529f\u80fd\u5f3a\u5927\u7684\u65e5\u5386\u5e94\u7528\u7a0b\u5e8f\uff0c\u5e2e\u52a9\u4eba\u4eec\u66f4\u597d\u5730\u7ba1\u7406\u81ea\u5df1\u7684\u65f6\u95f4\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528Webman\u6846\u67b6\u5b9e\u73b0\u65e5\u5386\u548c\u4e8b\u4ef6\u63d0\u9192\u529f\u80fd\uff0c\u5e76\u9644\u4e0a\u4ee3\u7801\u793a\u4f8b\u3002<\/p>\n<p>\u4e00\u3001\u642d\u5efa\u73af\u5883<br \/>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u642d\u5efaWebman\u6846\u67b6\u7684\u5f00\u53d1\u73af\u5883\u3002\u8bf7\u53c2\u8003Webman\u5b98\u65b9\u6587\u6863\uff0c\u5b89\u88c5Webman\u6846\u67b6\uff0c\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Web\u9879\u76ee\u3002<\/p>\n<p>\u4e8c\u3001\u6570\u636e\u5e93\u8bbe\u8ba1<br \/>\u65e5\u5386\u548c\u4e8b\u4ef6\u63d0\u9192\u529f\u80fd\u9700\u8981\u4f7f\u7528\u6570\u636e\u5e93\u6765\u5b58\u50a8\u6570\u636e\u3002\u5728\u8fd9\u91cc\uff0c\u6211\u4eec\u4ee5MySQL\u6570\u636e\u5e93\u4e3a\u4f8b\u8fdb\u884c\u8bf4\u660e\u3002\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a\u201ccalendar\u201d\u7684\u6570\u636e\u5e93\uff0c\u5e76\u521b\u5efa\u4e24\u4e2a\u8868\uff1acalendar\u548cevent\u3002<\/p>\n<p>\u8868calendar\u7528\u4e8e\u5b58\u50a8\u6bcf\u4e2a\u7528\u6237\u7684\u65e5\u5386\u4fe1\u606f\uff0c\u5305\u62ec\u7528\u6237ID\u3001\u65e5\u5386\u540d\u79f0\u7b49\u5b57\u6bb5\u3002\u8868event\u7528\u4e8e\u5b58\u50a8\u4e8b\u4ef6\u4fe1\u606f\uff0c\u5305\u62ec\u4e8b\u4ef6ID\u3001\u4e8b\u4ef6\u540d\u79f0\u3001\u5f00\u59cb\u65f6\u95f4\u3001\u7ed3\u675f\u65f6\u95f4\u7b49\u5b57\u6bb5\u3002\u8bf7\u6839\u636e\u5b9e\u9645\u9700\u6c42\u8bbe\u8ba1\u8868\u7ed3\u6784\uff0c\u5e76\u5728Webman\u6846\u67b6\u4e2d\u521b\u5efa\u5bf9\u5e94\u7684Model\u3002<\/p>\n<p>\u4e09\u3001\u5b9e\u73b0\u65e5\u5386\u529f\u80fd<\/p>\n<ol>\n<li>\u521b\u5efa\u65e5\u5386<br \/>\u7528\u6237\u53ef\u4ee5\u521b\u5efa\u591a\u4e2a\u65e5\u5386\uff0c\u6bcf\u4e2a\u65e5\u5386\u6709\u4e00\u4e2a\u552f\u4e00\u7684\u540d\u79f0\u3002\u5728Webman\u6846\u67b6\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u521b\u5efa\u4e00\u4e2aCalendarController\u6765\u5904\u7406\u76f8\u5173\u529f\u80fd\u3002<\/li>\n<\/ol>\n<p>\u4ee3\u7801\u793a\u4f8b\uff1a<\/p>\n<pre>@Route(\"\/calendar\")\npublic class CalendarController extends Controller {\n\n    @Inject\n    private CalendarService calendarService;\n\n    @Post(\"\/create\")\n    public void createCalendar(String name) {\n        \/\/ \u521b\u5efa\u65e5\u5386\n        calendarService.createCalendar(name);\n        renderText(\"\u65e5\u5386\u521b\u5efa\u6210\u529f\uff01\");\n    }\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<ol>\n<li>\u67e5\u770b\u65e5\u5386<br \/>\u7528\u6237\u53ef\u4ee5\u67e5\u770b\u81ea\u5df1\u521b\u5efa\u7684\u65e5\u5386\u3002\u5728Webman\u6846\u67b6\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Query\u6765\u67e5\u8be2\u6570\u636e\u5e93\u4e2d\u7684\u6570\u636e\uff0c\u5e76\u4f7f\u7528HTML\u6a21\u677f\u6765\u6e32\u67d3\u6570\u636e\u3002<\/li>\n<\/ol>\n<p>\u4ee3\u7801\u793a\u4f8b\uff1a<\/p>\n<pre>@Route(\"\/calendar\")\npublic class CalendarController extends Controller {\n\n    @Inject\n    private CalendarService calendarService;\n\n    @Get(\"\/list\")\n    public void listCalendars() {\n        \/\/ \u67e5\u8be2\u65e5\u5386\u5217\u8868\n        List&lt;calendar&gt; calendars = calendarService.listCalendars();\n        assign(\"calendars\", calendars);\n        render(\"calendar\/list.html\");\n    }\n}&lt;\/calendar&gt;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>HTML\u6a21\u677f\u793a\u4f8b\uff08list.html\uff09\uff1a<\/p>\n<pre>\n\n\n    &lt;title&gt;\u65e5\u5386\u5217\u8868&lt;\/title&gt;&lt;h1&gt;\u65e5\u5386\u5217\u8868&lt;\/h1&gt;\n    <\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<ul>\n  #foreach($calendar in $calendars) <\/p>\n<li>$calendar.name<\/li>\n<p> #end\n<\/ul>\n<p>\u56db\u3001\u5b9e\u73b0\u4e8b\u4ef6\u63d0\u9192\u529f\u80fd<\/p>\n<ol>\n<li>\u521b\u5efa\u4e8b\u4ef6<br \/>\u7528\u6237\u53ef\u4ee5\u5728\u65e5\u5386\u4e2d\u521b\u5efa\u4e8b\u4ef6\uff0c\u5305\u62ec\u4e8b\u4ef6\u540d\u79f0\u3001\u5f00\u59cb\u65f6\u95f4\u3001\u7ed3\u675f\u65f6\u95f4\u7b49\u4fe1\u606f\u3002<\/li>\n<\/ol>\n<p>\u4ee3\u7801\u793a\u4f8b\uff1a<\/p>\n<pre>@Route(\"\/event\")\npublic class EventController extends Controller {\n\n    @Inject\n    private EventService eventService;\n\n    @Post(\"\/create\")\n    public void createEvent(String name, String startTime, String endTime) {\n        \/\/ \u521b\u5efa\u4e8b\u4ef6\n        eventService.createEvent(name, startTime, endTime);\n        renderText(\"\u4e8b\u4ef6\u521b\u5efa\u6210\u529f\uff01\");\n    }\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<ol>\n<li>\u67e5\u770b\u4e8b\u4ef6<br \/>\u7528\u6237\u53ef\u4ee5\u67e5\u770b\u67d0\u4e2a\u65e5\u5386\u4e2d\u7684\u6240\u6709\u4e8b\u4ef6\u3002<\/li>\n<\/ol>\n<p>\u4ee3\u7801\u793a\u4f8b\uff1a<\/p>\n<pre>@Route(\"\/event\")\npublic class EventController extends Controller {\n\n    @Inject\n    private EventService eventService;\n\n    @Get(\"\/list\")\n    public void listEvents(Long calendarId) {\n        \/\/ \u67e5\u8be2\u4e8b\u4ef6\u5217\u8868\n        List&lt;event&gt; events = eventService.listEvents(calendarId);\n        assign(\"events\", events);\n        render(\"event\/list.html\");\n    }\n}&lt;\/event&gt;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>HTML\u6a21\u677f\u793a\u4f8b\uff08list.html\uff09\uff1a<\/p>\n<pre>\n\n\n    &lt;title&gt;\u4e8b\u4ef6\u5217\u8868&lt;\/title&gt;&lt;h1&gt;\u4e8b\u4ef6\u5217\u8868&lt;\/h1&gt;\n    <\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<ul>\n  #foreach($event in $events) <\/p>\n<li>$event.name<\/li>\n<p> #end\n<\/ul>\n<p>\u7ed3\u8bba\uff1a<br \/>\u901a\u8fc7Webman\u6846\u67b6\uff0c\u6211\u4eec\u53ef\u4ee5\u5f88\u65b9\u4fbf\u5730\u5b9e\u73b0\u65e5\u5386\u548c\u4e8b\u4ef6\u63d0\u9192\u529f\u80fd\u3002\u53ea\u9700\u8981\u642d\u5efa\u73af\u5883\u3001\u8bbe\u8ba1\u6570\u636e\u5e93\u3001\u5b9e\u73b0\u76f8\u5e94\u7684Controller\u548cService\uff0c\u5e76\u4f7f\u7528HTML\u6a21\u677f\u6765\u6e32\u67d3\u6570\u636e\u3002\u5e0c\u671b\u672c\u6587\u80fd\u5bf9\u4f60\u7406\u89e3\u5982\u4f55\u4f7f\u7528Webman\u6846\u67b6\u5b9e\u73b0\u65e5\u5386\u548c\u4e8b\u4ef6\u63d0\u9192\u529f\u80fd\u6709\u6240\u5e2e\u52a9\u3002\u5982\u679c\u6709\u4ec0\u4e48\u95ee\u9898\uff0c\u6b22\u8fce\u63d0\u95ee\uff01<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4f7f\u7528Webman\u6846\u67b6\u5b9e\u73b0\u65e5\u5386\u548c\u4e8b\u4ef6\u63d0\u9192\u529f\u80fd\uff1f\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\u4f7f\u7528webman\u6846\u67b6\u5b9e\u73b0\u65e5\u5386\u548c\u4e8b\u4ef6\u63d0\u9192\u529f\u80fd\uff1f \u5f15\u8a00\uff1a\u5728\u73b0\u4ee3\u793e\u4f1a\u4e2d\uff0c\u65f6\u95f4\u7ba1\u7406\u53d8\u5f97\u8d8a\u6765\u8d8a\u91cd\u8981\u3002\u4f5c\u4e3a\u5f00\u53d1\u8005\uff0c\u6211\u4eec\u53ef\u4ee5\u5229\u7528Webman\u6846\u67b6\u6765\u6784\u5efa\u4e00\u4e2a\u529f\u80fd\u5f3a\u5927\u7684\u65e5\u5386\u5e94\u7528\u7a0b\u5e8f\uff0c\u5e2e\u52a9\u4eba\u4eec\u66f4\u597d\u5730\u7ba1\u7406\u81ea\u5df1\u7684\u65f6\u95f4\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528Webman\u6846\u67b6\u5b9e\u73b0\u65e5\u5386\u548c\u4e8b\u4ef6\u63d0\u9192\u529f\u80fd\uff0c\u5e76\u9644\u4e0a\u4ee3\u7801\u793a\u4f8b\u3002 \u4e00\u3001\u642d\u5efa\u73af\u5883\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u642d\u5efaWebman\u6846\u67b6\u7684\u5f00\u53d1\u73af\u5883\u3002\u8bf7\u53c2\u8003Webman\u5b98\u65b9\u6587\u6863\uff0c\u5b89\u88c5Webman\u6846\u67b6\uff0c\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Web\u9879\u76ee\u3002 \u4e8c\u3001\u6570\u636e\u5e93\u8bbe\u8ba1\u65e5\u5386\u548c\u4e8b\u4ef6\u63d0\u9192\u529f\u80fd\u9700\u8981\u4f7f\u7528\u6570\u636e\u5e93\u6765\u5b58\u50a8\u6570\u636e\u3002\u5728\u8fd9\u91cc\uff0c\u6211\u4eec\u4ee5MySQL\u6570\u636e\u5e93\u4e3a\u4f8b\u8fdb\u884c\u8bf4\u660e\u3002\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a\u201ccalendar\u201d\u7684\u6570\u636e\u5e93\uff0c\u5e76\u521b\u5efa\u4e24\u4e2a\u8868\uff1acalendar\u548cevent\u3002 \u8868calendar\u7528\u4e8e\u5b58\u50a8\u6bcf\u4e2a\u7528\u6237\u7684\u65e5\u5386\u4fe1\u606f\uff0c\u5305\u62ec\u7528\u6237ID\u3001\u65e5\u5386\u540d\u79f0\u7b49\u5b57\u6bb5\u3002\u8868event\u7528\u4e8e\u5b58\u50a8\u4e8b\u4ef6\u4fe1\u606f\uff0c\u5305\u62ec\u4e8b\u4ef6ID\u3001\u4e8b\u4ef6\u540d\u79f0\u3001\u5f00\u59cb\u65f6\u95f4\u3001\u7ed3\u675f\u65f6\u95f4\u7b49\u5b57\u6bb5\u3002\u8bf7\u6839\u636e\u5b9e\u9645\u9700\u6c42\u8bbe\u8ba1\u8868\u7ed3\u6784\uff0c\u5e76\u5728Webman\u6846\u67b6\u4e2d\u521b\u5efa\u5bf9\u5e94\u7684Model\u3002 \u4e09\u3001\u5b9e\u73b0\u65e5\u5386\u529f\u80fd \u521b\u5efa\u65e5\u5386\u7528\u6237\u53ef\u4ee5\u521b\u5efa\u591a\u4e2a\u65e5\u5386\uff0c\u6bcf\u4e2a\u65e5\u5386\u6709\u4e00\u4e2a\u552f\u4e00\u7684\u540d\u79f0\u3002\u5728Webman\u6846\u67b6\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u521b\u5efa\u4e00\u4e2aCalendarController\u6765\u5904\u7406\u76f8\u5173\u529f\u80fd\u3002 \u4ee3\u7801\u793a\u4f8b\uff1a @Route(&#8220;\/calendar&#8221;) public class CalendarController extends Controller { @Inject private CalendarService calendarService; @Post(&#8220;\/create&#8221;) public void createCalendar(String name) { \/\/ \u521b\u5efa\u65e5\u5386 calendarService.createCalendar(name); renderText(&#8220;\u65e5\u5386\u521b\u5efa\u6210\u529f\uff01&#8221;); } } \u767b\u5f55\u540e\u590d\u5236 \u67e5\u770b\u65e5\u5386\u7528\u6237\u53ef\u4ee5\u67e5\u770b\u81ea\u5df1\u521b\u5efa\u7684\u65e5\u5386\u3002\u5728Webman\u6846\u67b6\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Query\u6765\u67e5\u8be2\u6570\u636e\u5e93\u4e2d\u7684\u6570\u636e\uff0c\u5e76\u4f7f\u7528HTML\u6a21\u677f\u6765\u6e32\u67d3\u6570\u636e\u3002 \u4ee3\u7801\u793a\u4f8b\uff1a @Route(&#8220;\/calendar&#8221;) public class CalendarController extends Controller { @Inject private CalendarService calendarService; @Get(&#8220;\/list&#8221;) public void listCalendars() { \/\/ \u67e5\u8be2\u65e5\u5386\u5217\u8868 List&lt;calendar&gt; calendars = [&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-24123","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/24123","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=24123"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/24123\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=24123"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=24123"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=24123"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}