{"id":2192,"date":"2021-09-26T03:27:22","date_gmt":"2021-09-25T19:27:22","guid":{"rendered":"https:\/\/www.develop-note.com\/blog\/?p=2192"},"modified":"2022-02-16T17:50:24","modified_gmt":"2022-02-16T09:50:24","slug":"webapp-mvc-webapi","status":"publish","type":"post","link":"https:\/\/www.develop-note.com\/blog\/2021\/09\/26\/webapp-mvc-webapi\/","title":{"rendered":"D-19 \u7db2\u9801\u7ad9\u53f0 ? webapp ? mvc ? webapi"},"content":{"rendered":"<h1>\u7db2\u9801\u7ad9\u53f0\u521d\u9ad4\u9a57<\/h1>\n<p>\u5728\u6628\u65e5\u6700\u5f8c\u5927\u982d\u8ddf\u5c0f\u5149\u8aaa<code>c#<\/code>\u7684\u4ecb\u7d39\u544a\u4e00\u6bb5\u843d\u4e86\uff0c\u6240\u4ee5\u4eca\u5929\u958b\u59cb\u6703\u9032\u5165\u7db2\u9801\u7ad9\u53f0\u76f8\u95dc\u77e5\u8b58\u7684\u4ecb\u7d39\uff0c\u6240\u4ee5\u4eca\u5929\u5c0f\u5149\u6703\u5b78\u7fd2\u5230\u751a\u9ebc\u6771\u897f\u5462\u3002<\/p>\n<p><!--more--><\/p>\n<h2>\u7db2\u9801\u7ad9\u53f0<\/h2>\n<p>\u300c\u524d\u8f29\uff0c\u5feb\u4f86\u958b\u767c\u7db2\u9801\u7a0b\u5f0f\u5427\u3002\u300d<br \/>\n\u5728\u4f11\u606f\u4e00\u5929\u4e4b\u5f8c\uff0c\u5c0f\u5149\u4e00\u5927\u65e9\u5230\u516c\u53f8\u5c31\u795e\u91c7\u5955\u5955\u5730\u8acb\u5927\u982d\u544a\u8a34\u4ed6\u5982\u4f55\u958b\u767c\u7db2\u9801\u7a0b\u5f0f\u3002\u4e0d\u904e\u76f8\u5c0d\u65bc\u5c0f\u5149\u7684\u795e\u91c7\u5955\u5955\u5927\u982d\u4eca\u5929\u986f\u5f97\u6709\u6c23\u7121\u529b\u5730\u8eb2\u5728\u9700\u6c42\u6587\u4ef6\u5f8c\u9762\u57cb\u982d\u82e6\u5e79\uff0c\u76f4\u5230\u904e\u4e86\u4e94\u5206\u9418\u5f8c\u624d\u62ac\u982d\u4e26\u4e14\u9019\u6a23\u56de\u7b54\u3002<br \/>\n\u300c\u7b49\u7b49\u7b49&#8230;\u4f60\u9700\u8981\u7b49\u6211\u597d\u4e00\u9663\u5b50\uff0c\u6211\u9700\u8981\u5148\u628a\u9019\u6771\u897f\u5b8c\u6210\u3002\u300d<br \/>\n\u300c\u4f60\u5148\u56de\u5230\u4f4d\u5b50\u5750\uff0c\u8b93\u6211\u4f86\u544a\u8a34\u4f60\u5427\u3002\u300d<br \/>\n\u807d\u5230\u9019\u53e5\u8a71\uff0c\u5c0f\u5149\u62ac\u982d\u4e00\u770b\u539f\u4f86\u662f\u8001K\u524d\u8f29\uff0c\u5c0f\u5149\u6709\u807d\u5927\u982d\u8aaa\u904e\u4ed6\u662f\u4e4b\u524d\u5e36\u5927\u982d\u7684\u524d\u8f29\u3002<br \/>\n\u300c\u524d\u8f29\u8b1d\u8b1d\u4f60\u4e86\uff0c\u6211\u5148\u7e7c\u7e8c\u8d95\u5c08\u6848\u3002\u300d<br \/>\n\u5927\u982d\u4e00\u898b\u5230\u6709\u6551\u5175\u4f86\u6551\u706b\uff0c\u8d95\u7dca\u8aaa\u8072\u8b1d\u8b1d\u5f8c\u53c8\u57cb\u982d\u56de\u5230\u9700\u6c42\u6587\u4ef6\u4e4b\u4e2d\u4e86\u3002<br \/>\n\u300c\u4f86\u5427\uff0c\u6211\u5011\u5148\u4f86\u770b\u770b\u5982\u4f55\u7522\u751f\u4e00\u500b\u7db2\u9801\u5c08\u6848\u5427\u3002\u300d<br \/>\n\u63a5\u4e0b\u4f86\u8001K\u9019\u9ebc\u5c0d\u5c0f\u5149\u8aaa\u3002<\/p>\n<h3>\u7522\u751f\u7db2\u9801\u5c08\u6848 webapp<\/h3>\n<p>\u4e0d\u66c9\u5f97\u5927\u5bb6\u9084\u8a18\u4e0d\u8a18\u5f97\u4e4b\u524d\u6240\u5b78\u7684\u6771\u897f\u5176\u4e2d\u6709\u4e00\u62db\u53eb\u505a<a href=\"https:\/\/docs.microsoft.com\/zh-tw\/dotnet\/core\/tools\/dotnet-new\" title=\"dotnet new\" rel=\"nofollow noopener\" target=\"_blank\">dotnet new<\/a>\uff0c\u6240\u4ee5\u4eca\u5929\u6211\u5011\u5c31\u4f7f\u7528<code>dotnet new<\/code>\u4f86\u7522\u751f\u4e00\u500b\u7db2\u9801\u5c08\u6848\uff0c\u6240\u4ee5\u4f9d\u820a\u662f\u5148\u7522\u751f\u4e00\u500b\u76ee\u9304\uff0c\u4e26\u4e14\u57f7\u884cdotnet new\u7684\u6307\u4ee4\uff0c\u8a73\u7d30\u5167\u5bb9\u8acb\u898b\u4ee5\u4e0b\u8aaa\u660e\u3002<\/p>\n<pre><code class=\"language-bash\">mkdir webapp\ncd webapp\ndotnet new webapp<\/code><\/pre>\n<p>\u76f8\u4fe1\u6709\u770b\u6211\u5011\u4e4b\u524d\u6587\u7ae0\u7684\u8b80\u8005\u5011\u61c9\u8a72\u4e0d\u964c\u751fdotnet new\u9019\u6307\u4ee4\uff0c\u53ea\u4e0d\u904e\u6211\u5011\u7576\u6642\u662f\u4f7f\u7528<code>dotnet new consloe<\/code>\u4f86\u7522\u751f\u547d\u4ee4\u5217\u5c08\u6848\uff0c\u73fe\u5728\u6211\u5011\u7522\u751f\u7684\u662f\u6709\u5305\u542b<code>razor<\/code>\u7684web page\u5c08\u6848\u3002<br \/>\n\u6240\u4ee5\u63a5\u4e0b\u4f86\u53ea\u8981\u57f7\u884c<code>dotnet run<\/code>\u4e4b\u5f8c\u6211\u5011\u7b2c\u4e00\u500b\u7db2\u9801\u7a0b\u5f0f\u5c31\u5b8c\u6210\u4e86\u3002<\/p>\n<h3>\u7db2\u9801\u5c08\u6848\u985e\u578b<\/h3>\n<p>\u525b\u525b\u7522\u751f\u7684\u662fdotnetcore\u5167\u5efa\u7684\u7db2\u9801\u7a0b\u5f0f\u7684\u7bc4\u672c\u4e4b\u4e00<a href=\"https:\/\/docs.microsoft.com\/zh-tw\/aspnet\/core\/razor-pages\/\" title=\"razor pages\" rel=\"nofollow noopener\" target=\"_blank\">razor pages<\/a>\uff0c\u9664\u4e86<code>webapp<\/code>\u4e4b\u5916\u5e38\u7528\u7684\u9084\u6709<code>mvc<\/code>\u8ddf<code>webapi<\/code>\uff0c\u7576\u7136\u6709\u8208\u8da3\u7684\u4e5f\u53ef\u4ee5\u7528<code>angular<\/code>\u6216<code>reactredux<\/code>\u9019\u7a2espa\u5c08\u6848\uff0c\u4e0d\u904e\u9019\u6b21\u5148\u4ecb\u7d39mvc\u8207webapi\u5c08\u6848<\/p>\n<h4>mvc<\/h4>\n<p><a href=\"https:\/\/zh.wikipedia.org\/wiki\/MVC\" title=\"MVC\" rel=\"nofollow noopener\" target=\"_blank\">MVC<\/a>\u76f8\u4fe1\u8b80\u8005\u5011\u61c9\u8a72\u90fd\u4e0d\u964c\u751f\uff0c\u4e3b\u8981\u662f\u628a\u7db2\u9801\u7a0b\u5f0f\u5206\u6210<code>Controler<\/code>\u8ddf<code>View<\/code>\u4e26\u4e14\u4e4b\u9593\u7528<code>Model<\/code>\u4e32\u63a5\u8d77\u4f86\uff0c\u81f3\u65bc<code>View<\/code>\u7684\u90e8\u5206\u5f8c\u7e8c\u6703\u4ecb\u7d39\u600e\u9ebc\u7528<code>razor<\/code>\u4f86\u6e32\u67d3\u756b\u9762\u3002<\/p>\n<h4>webapi<\/h4>\n<p>\u76f8\u8f03\u65bc<code>mvc<\/code>\u4f86\u8aaa<code>webapi<\/code>\u5c31\u55ae\u7d14\u8a31\u591a\uff0c\u56e0\u61c9\u524d\u5f8c\u7aef\u5206\u96e2\uff0c\u6240\u4ee5\u5c11\u4e86view\u7684\u90e8\u5206\u53ea\u9700\u8981\u5c08\u5fc3\u5728controler\u4e0a\u7684\u958b\u767c\uff0c\u4e0d\u904e\u6b63\u56e0\u70ba\u5982\u6b64\u5c0d\u65bc\u7121\u72c0\u614b\u7684\u7db2\u9801\u7a0b\u5f0f\u4f86\u8aaawebapi\u7684\u8655\u7406\u66f4\u9700\u8981\u6ce8\u610f\u3002<\/p>\n<h3>\u7db2\u9801\u7a0b\u5f0f\u6a94\u6848\u7d50\u69cb<\/h3>\n<p>\u525b\u525b\u4ecb\u7d39\u5b8c\u985e\u578b\u4e4b\u5f8c\u6211\u5011\u73fe\u5728\u4f86\u770b\u770b\u7a76\u7adf<code>cli<\/code>\u5e6b\u6211\u5011\u7522\u751f\u4e86\u751a\u9ebc\u6a94\u6848\uff0c\u76f8\u4fe1<code>MVC<\/code>\u4e00\u958b\u8d77\u4f86\u61c9\u8a72\u6703\u662f\u770b\u5230\u4ee5\u4e0b\u7684\u76ee\u9304\u7d50\u69cb\u3002<\/p>\n<pre><code class=\"language-bash\">.\n\u251c\u2500\u2500Controllers\n\u251c\u2500\u2500Models\n\u251c\u2500\u2500Views\n\u251c\u2500\u2500wwwroot\n\u251c\u2500Program.cs\n\u2514\u2500Startup.cs<\/code><\/pre>\n<p>\u5176\u4e2d\u5c31\u5982\u540c\u76ee\u9304\u540d\u7a31\u5c07Model\u3001View\u3001Controller\u653e\u7f6e\u65bc\u76f8\u5c0d\u61c9\u7684\u4f4d\u7f6e\uff0c\u81f3\u65bc<code>Program.cs<\/code>\u5c31\u662f\u7a0b\u5f0f\u7684\u9032\u5165\u9ede\uff0c\u9084\u6709\u4ee5\u5f8c\u7684\u8b80\u53d6\u8a2d\u5b9a\u64cb\u4e5f\u5beb\u5728\u9019\u908a\u3002\u53e6\u5916\u4e00\u500b<code>Startup.cs<\/code>\u53ef\u4ee5\u53c3\u8003<a href=\"https:\/\/docs.microsoft.com\/zh-tw\/aspnet\/core\/fundamentals\/startup\" title=\"startup\" rel=\"nofollow noopener\" target=\"_blank\">startup<\/a>\u7684\u8aaa\u660e\uff0c\u5176\u4e2d\u5f88\u591a\u95dc\u65bc\u7db2\u9801\u7a0b\u5f0f\u6703\u76f8\u4f9d\u5230\u7684\u5143\u4ef6\u6216\u662f\u8a2d\u5b9a\u6a94\u5247\u662f\u5728\u9019\u500b\u6a94\u6848\u5167\u505a\u6ce8\u5165\u7684\u52d5\u4f5c\u3002<\/p>\n<h2>\u5f8c\u8a18<\/h2>\n<p>\u300c\u524d\u8f29\uff0c\u6c92\u60f3\u5230\u9019\u6a23\u6211\u5c31\u53ef\u4ee5\u505a\u4e00\u500b\u7db2\u9801\u7a0b\u5f0f\u4e86\u300d<br \/>\n\u807d\u5b8c\u8001K\u7684\u4ecb\u7d39\u8b93\u5c0f\u5149\u4e00\u4e0b\u5c31\u5efa\u7acb\u4e86\u81ea\u5df1\u7684\u7db2\u9801\u7a0b\u5f0f\uff0c\u9019\u8b93\u5c0f\u5149\u975e\u5e38\u8208\u596e\u3002<br \/>\n\u300c\u4e0d\u904e\u9019\u53ea\u662f\u7522\u751f\u800c\u5df2\u5594\uff0c\u4f60\u9084\u8981\u5b78\u8457\u7dad\u8b77\u4ed6\u5594\uff0c\u56e0\u6b64\u4f60\u9700\u8981\u4e86\u89e3\u4e00\u4e0b\u76f8\u95dc\u7684\u77e5\u8b58\u624d\u884c\uff0c\u6240\u4ee5\u63a5\u4e0b\u4f86\u5e7e\u5929\u6211\u6703\u518d\u8a73\u7d30\u7684\u544a\u8a34\u4f60\u7db2\u9801\u7a0b\u5f0f\u7684\u76f8\u95dc\u77e5\u8b58\u3002\u300d<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7db2\u9801\u7ad9\u53f0\u521d\u9ad4\u9a57 \u5728\u6628\u65e5\u6700\u5f8c\u5927\u982d\u8ddf\u5c0f\u5149\u8aaac#\u7684\u4ecb\u7d39\u544a\u4e00\u6bb5\u843d\u4e86\uff0c\u6240\u4ee5\u4eca\u5929\u958b\u59cb\u6703\u9032\u5165\u7db2\u9801\u7ad9\u53f0\u76f8\u95dc\u77e5\u8b58\u7684\u4ecb\u7d39\uff0c\u6240\u4ee5\u4eca\u5929 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.develop-note.com\/blog\/2021\/09\/26\/webapp-mvc-webapi\/\" class=\"more-link\">\u95b1\u8b80\u5168\u6587<span class=\"screen-reader-text\">\u3008D-19 \u7db2\u9801\u7ad9\u53f0 ? webapp ? mvc ? webapi\u3009<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[2],"tags":[90,96,92,106],"class_list":["post-2192","post","type-post","status-publish","format-standard","hentry","category-develop","tag-2021ironman","tag-dotnet-cli","tag-dotnetcore","tag-razor"],"_links":{"self":[{"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/posts\/2192","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/comments?post=2192"}],"version-history":[{"count":19,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/posts\/2192\/revisions"}],"predecessor-version":[{"id":2630,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/posts\/2192\/revisions\/2630"}],"wp:attachment":[{"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/media?parent=2192"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/categories?post=2192"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/tags?post=2192"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}