{"id":1999,"date":"2017-06-16T10:28:22","date_gmt":"2017-06-16T02:28:22","guid":{"rendered":"https:\/\/ai.zhousir.top\/?p=1999"},"modified":"2026-08-18T11:23:36","modified_gmt":"2026-08-18T03:23:36","slug":"springboot%e5%88%9d%e4%bd%93%e9%aa%8c","status":"publish","type":"post","link":"https:\/\/ai.zhousir.top\/?p=1999","title":{"rendered":"springboot\u521d\u4f53\u9a8c"},"content":{"rendered":"<section id=\"wenyan\" style=\"font-family: system-ui, 'Apple Color Emoji', 'Segoe UI', 'Segoe UI Symbol', 'Noto Sans', Roboto, sans-serif; line-height: 1.75; font-size: 16px; color: #000000; caret-color: #000000;\" data-provider=\"WenYan\">\n<p style=\"margin: 1em 0px;\"><strong style=\"color: #4870ac;\">Spring Boot<\/strong> \u7531 Pivotal \u63d0\u4f9b\uff0c\u76ee\u6807\u662f\u7b80\u5316\u65b0 Spring \u5e94\u7528\u7684\u521d\u59cb\u642d\u5efa\u548c\u5f00\u53d1\u8fc7\u7a0b\u3002\u5b83\u7528\u7ea6\u5b9a\u597d\u7684\u65b9\u5f0f\u505a\u914d\u7f6e\uff0c\u8ba9\u4f60\u5c11\u5199\u6837\u677f XML \/ JavaConfig\u3002\u5b98\u7f51\uff1a<a href=\"http:\/\/projects.spring.io\/spring-boot\/\" style=\"color: #4870ac; text-decoration: underline;\" target=\"_blank\">http:\/\/projects.spring.io\/spring-boot\/<\/a>\u3002<\/p>\n<p style=\"margin: 1em 0px;\">Boot \u5e76\u4e0d\u53e6\u8d77\u4e00\u5957\u95ee\u9898\u57df\uff0c\u800c\u662f\u7ed9\u5df2\u6709 Spring \u6280\u672f\u6362\u4e00\u79cd\u66f4\u77ed\u7684\u4f7f\u7528\u8def\u5f84\u3002\u719f\u6089 Spring \u751f\u6001\u7684\u4eba\u4e0a\u624b\u5f88\u5feb\uff1b\u65b0\u4eba\u4e5f\u53ef\u4ee5\u7528\u66f4\u5c11\u914d\u7f6e\u628a <strong style=\"color: #4870ac;\">Web \u5e94\u7528\u548c REST<\/strong> \u8dd1\u8d77\u6765\u3002\u4e0b\u9762\u5148\u505a\u4e00\u4e2a\u6700\u5c0f\u53ef\u8bbf\u95ee\u63a5\u53e3\uff0c\u518d\u8865\u4e0a JSP + SpringMVC \u89c6\u56fe\u3002<\/p>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u4e00\u3001\u6700\u5c0f\u53ef\u8fd0\u884c\u7684 Spring Boot<\/h2>\n<h3 style=\"padding: 0px; color: #4870ac; margin: 1.2em 0px 1em; font-size: 1.3em;\">1. Maven \u4f9d\u8d56<\/h3>\n<p style=\"margin: 1em 0px;\">\u521b\u5efa\u4e00\u4e2a Maven \u5de5\u7a0b\uff0c\u5f15\u5165 parent \u548c web starter \u5373\u53ef\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">&lt;parent&gt;\n    &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\n    &lt;artifactId&gt;spring-boot-starter-parent&lt;\/artifactId&gt;\n    &lt;version&gt;1.4.1.RELEASE&lt;\/version&gt;\n&lt;\/parent&gt;\n&lt;dependencies&gt;\n    &lt;dependency&gt;\n        &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\n        &lt;artifactId&gt;spring-boot-starter-web&lt;\/artifactId&gt;\n    &lt;\/dependency&gt;\n&lt;\/dependencies&gt;<\/code><\/pre>\n<h3 style=\"padding: 0px; color: #4870ac; margin: 1.2em 0px 1em; font-size: 1.3em;\">2. Application.java<\/h3>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">@Controller\n@SpringBootApplication\npublic class Application {\n    @RequestMapping(\"\/\")\n    @ResponseBody\n    public String helloSpringBoot() {\n        return \"welcome to springBoot \";\n    }\n\n    public static void main(String[] args) {\n        SpringApplication.run(Application.class, args);\n    }\n}<\/code><\/pre>\n<h3 style=\"padding: 0px; color: #4870ac; margin: 1.2em 0px 1em; font-size: 1.3em;\">3. \u8bbf\u95ee http:\/\/localhost:8080\/<\/h3>\n<p style=\"margin: 1em 0px;\">\u6d4f\u89c8\u5668\u6253\u5f00 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">http:\/\/localhost:8080\/<\/code>\uff0c\u9875\u9762\u5e94\u663e\u793a <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">welcome to springBoot<\/code>\u3002<\/p>\n<table style=\"display: table; text-align: left; overflow: auto; border-collapse: collapse; margin: 1.4em auto; max-width: 100%; table-layout: fixed; overflow-wrap: break-word; word-break: break-all;\" width=\"800\">\n<thead>\n<tr>\n<th style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top; text-align: center; font-weight: bold; color: #4870ac; background: #f7f7f7;\">\u6b65\u9aa4<\/th>\n<th style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top; text-align: center; font-weight: bold; color: #4870ac; background: #f7f7f7;\">\u5173\u952e\u70b9<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">parent + starter-web<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u7248\u672c\u7531 parent \u7edf\u4e00\u7ba1\u7406\uff0c\u4e0d\u5fc5\u624b\u5199\u4e00\u5806 spring jar<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\"><code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">@SpringBootApplication<\/code><\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u7b49\u4e8e\u914d\u7f6e\u7c7b + \u81ea\u52a8\u914d\u7f6e + \u7ec4\u4ef6\u626b\u63cf<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\"><code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">SpringApplication.run<\/code><\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u5185\u5d4c Tomcat\uff0cmain \u65b9\u6cd5\u76f4\u63a5\u542f\u52a8<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u4e8c\u3001\u8ba9 Spring Boot \u652f\u6301 JSP \u5e76\u8d70 SpringMVC<\/h2>\n<p style=\"margin: 1em 0px;\">\u5b98\u65b9\u5e76\u4e0d\u63a8\u8350 JSP\u3002STS \u751f\u6210\u7684\u5de5\u7a0b\u4f1a\u5728 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">src\/main\/resources\/templates<\/code> \u4e0b\u653e\u6a21\u677f\uff0c\u4e5f\u6ca1\u6709\u4f20\u7edf <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">webapp<\/code> \u76ee\u5f55\u3002\u82e5\u4ecd\u8981\u7528 JSP\uff0c\u9700\u8981\u989d\u5916\u4f9d\u8d56\u548c\u89c6\u56fe\u524d\u540e\u7f00\u3002<\/p>\n<h3 style=\"padding: 0px; color: #4870ac; margin: 1.2em 0px 1em; font-size: 1.3em;\">1. \u5f15\u5165\u4f9d\u8d56<\/h3>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">&lt;!-- tomcat \u7684\u652f\u6301 --&gt;\n&lt;dependency&gt;\n    &lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\n    &lt;artifactId&gt;spring-boot-starter-tomcat&lt;\/artifactId&gt;\n    &lt;scope&gt;provided&lt;\/scope&gt;\n&lt;\/dependency&gt;\n&lt;dependency&gt;\n    &lt;groupId&gt;org.apache.tomcat.embed&lt;\/groupId&gt;\n    &lt;artifactId&gt;tomcat-embed-jasper&lt;\/artifactId&gt;\n    &lt;scope&gt;provided&lt;\/scope&gt;\n&lt;\/dependency&gt;\n&lt;dependency&gt;\n    &lt;groupId&gt;javax.servlet&lt;\/groupId&gt;\n    &lt;artifactId&gt;jstl&lt;\/artifactId&gt;\n&lt;\/dependency&gt;<\/code><\/pre>\n<h3 style=\"padding: 0px; color: #4870ac; margin: 1.2em 0px 1em; font-size: 1.3em;\">2. application.properties<\/h3>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\"># springmvc \u524d\u540e\u7f00\u914d\u7f6e\nspring.mvc.view.prefix=\/WEB-INF\/views\/\nspring.mvc.view.suffix=.jsp<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u66f4\u63a8\u8350\u5199\u6210 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">application.yml<\/code>\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">spring:\n  mvc:\n    view:\n      prefix: \/WEB-INF\/views\/\n      suffix: .jsp<\/code><\/pre>\n<h3 style=\"padding: 0px; color: #4870ac; margin: 1.2em 0px 1em; font-size: 1.3em;\">3. LoginController.java<\/h3>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">@Controller\npublic class LoginController {\n    @RequestMapping(\"\/login\")\n    public String login() {\n        return \"login\";\n    }\n\n    @RequestMapping(\"\/login_submit\")\n    public String loginSubmit(String username, String password, Model model) {\n        model.addAttribute(\"message\", \"username = \" + username + \" password = \" + password);\n        return \"login\";\n    }\n}<\/code><\/pre>\n<h3 style=\"padding: 0px; color: #4870ac; margin: 1.2em 0px 1em; font-size: 1.3em;\">4. \u6d4f\u89c8\u5668\u8bf7\u6c42<\/h3>\n<p style=\"margin: 1em 0px;\">\u8bbf\u95ee <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">http:\/\/localhost:8080\/login<\/code>\uff0c\u4f1a\u89e3\u6790\u5230 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">\/WEB-INF\/views\/login.jsp<\/code>\u3002<\/p>\n<blockquote style=\"display: block; font-size: 0.9em; border-left: 3px solid #4870ac; padding: 0.5em 1em; margin: 0px; background: #f6f8fa; color: #40464f;\">\n<p style=\"margin: 1em 0px;\"><strong style=\"color: #4870ac;\">\u4e00\u53e5\u8bdd\u603b\u7ed3\uff1aSpring Boot \u7528 starter \u548c\u7ea6\u5b9a\u914d\u7f6e\u628a\u7b2c\u4e00\u4e2a Web \u63a5\u53e3\u7f29\u6210\u300c\u4f9d\u8d56 + \u4e00\u4e2a Application \u7c7b\u300d\uff1b\u82e5\u575a\u6301 JSP\uff0c\u8865 jasper \/ jstl \u5e76\u914d\u597d\u89c6\u56fe\u524d\u540e\u7f00\u5373\u53ef\u63a5\u5230 SpringMVC\u3002<\/strong><\/p>\n<\/blockquote>\n<\/section>\n","protected":false},"excerpt":{"rendered":"<p>Spring Boot \u7531 Pivotal \u63d0\u4f9b\uff0c\u76ee\u6807\u662f\u7b80\u5316\u65b0 Spring \u5e94\u7528\u7684\u521d\u59cb\u642d\u5efa\u548c\u5f00\u53d1\u8fc7\u7a0b\u3002\u5b83\u7528\u7ea6 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[93],"tags":[184,186],"_links":{"self":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/1999"}],"collection":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1999"}],"version-history":[{"count":1,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/1999\/revisions"}],"predecessor-version":[{"id":2000,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/1999\/revisions\/2000"}],"wp:attachment":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1999"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1999"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1999"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}