目录
1.搭建springboot项目
2.新增controller
3.新增html页面
4.修改配置
5.本地运行及测试
6.部署到线上
7.常见问题
7.1Circular view path [index]: would dispatch back to the current handler URL [/index] again
7.2 Whitelabel Error Page
8.源码下载地址
1.搭建springboot项目

?
?
2.新增controller


?

?HelloController.java中敲入如下代码:
package com.example.demo.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class HelloController {
@RequestMapping("/index")
public String show(){
return "index";
}
}
3.新增html页面



?index.html文件内容如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>login</title>
</head>
<body>
<form role="form" action = "" method="post">
账号:<input type="text" id="name" name = "name"> <br>
密码:<input type="password" id = "password" name = "password"> <br>
<input type="submit" id = "login" value = "login">
</form>
</body>
</html>
4.修改配置
pom.xml文件中,新增如下配置:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
如果不加,访问controll中的地址时,就无法跳转到index.html.
5.本地运行及测试

?运行日志如下:
Connected to the target VM, address: '127.0.0.1:56180', transport: 'socket'
? . ? ____ ? ? ? ? ?_ ? ? ? ? ? ?__ _ _ ?/\\ / ___'_ __ _ _(_)_ __ ?__ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ ?\\/ ?___)| |_)| | | | | || (_| | ?) ) ) ) ? ' ?|____| .__|_| |_|_| |_\__, | / / / / ?=========|_|==============|___/=/_/_/_/ ?:: Spring Boot :: ? ? ? ? ? ? ? ?(v2.5.3)
2021-08-10 08:57:03.366 ?INFO 18020 --- [ ? ? ? ? ? main] com.example.demo.DemoApplication ? ? ? ? : Starting DemoApplication using Java 1.8.0_181 on LAPTOP-FALL with PID 18020 (D:\work\intellijmy\springbootwebdemo\target\classes started by 86183 in D:\work\intellijmy\springbootwebdemo) 2021-08-10 08:57:03.507 ?INFO 18020 --- [ ? ? ? ? ? main] com.example.demo.DemoApplication ? ? ? ? : No active profile set, falling back to default profiles: default 2021-08-10 08:57:12.517 ?INFO 18020 --- [ ? ? ? ? ? main] o.s.b.w.embedded.tomcat.TomcatWebServer ?: Tomcat initialized with port(s): 8080 (http) 2021-08-10 08:57:12.577 ?INFO 18020 --- [ ? ? ? ? ? main] o.apache.catalina.core.StandardService ? : Starting service [Tomcat] 2021-08-10 08:57:12.577 ?INFO 18020 --- [ ? ? ? ? ? main] org.apache.catalina.core.StandardEngine ?: Starting Servlet engine: [Apache Tomcat/9.0.50] 2021-08-10 08:57:13.047 ?INFO 18020 --- [ ? ? ? ? ? main] o.a.c.c.C.[Tomcat].[localhost].[/] ? ? ? : Initializing Spring embedded WebApplicationContext 2021-08-10 08:57:13.048 ?INFO 18020 --- [ ? ? ? ? ? main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 8881 ms 2021-08-10 08:57:20.596 ?INFO 18020 --- [ ? ? ? ? ? main] o.s.b.w.embedded.tomcat.TomcatWebServer ?: Tomcat started on port(s): 8080 (http) with context path '' 2021-08-10 08:57:20.643 ?INFO 18020 --- [ ? ? ? ? ? main] com.example.demo.DemoApplication ? ? ? ? : Started DemoApplication in 27.756 seconds (JVM running for 42.529)

6.部署到线上
参考《IDEA如何快速打包可执行的jar和运行jar》
7.常见问题
7.1Circular view path [index]: would dispatch back to the current handler URL [/index] again
【现象】
2021-08-09 18:17:24.484 ERROR 16396 --- [nio-8080-exec-3] o.a.c.c.C.[.[.[/].[dispatcherServlet] ? ?: Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Circular view path [index]: would dispatch back to the current handler URL [/index] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.)] with root cause
javax.servlet.ServletException: Circular view path [index]: would dispatch back to the current handler URL [/index] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.) ?? ?at org.springframework.web.servlet.view.InternalResourceView.prepareForRendering(InternalResourceView.java:210) ~[spring-webmvc-5.3.9.jar:5.3.9] ?? ?at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:148) ~[spring-webmvc-5.3.9.jar:5.3.9] ?? ?at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:316) ~[spring-webmvc-5.3.9.jar:5.3.9] ?? ?at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1397) ~[spring-webmvc-5.3.9.jar:5.3.9] ?? ?at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1142) ~[spring-webmvc-5.3.9.jar:5.3.9] ?? ?at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1081) ~[spring-webmvc-5.3.9.jar:5.3.9] ?? ?at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:963) ~[spring-webmvc-5.3.9.jar:5.3.9] ?? ?at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) ~[spring-webmvc-5.3.9.jar:5.3.9] ?? ?at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898) ~[spring-webmvc-5.3.9.jar:5.3.9] ?? ?at javax.servlet.http.HttpServlet.service(HttpServlet.java:655) ~[tomcat-embed-core-9.0.50.jar:4.0.FR] ?? ?at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) ~[spring-webmvc-5.3.9.jar:5.3.9] ?? ?at javax.servlet.http.HttpServlet.service(HttpServlet.java:764) ~[tomcat-embed-core-9.0.50.jar:4.0.FR]
【解决方法】
pom.xml文件中,新增如下配置:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
7.2 Whitelabel Error Page
【现象】

?【解决方法】
?pom.xml文件中,新增如下配置:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
8.源码下载地址
https://download.csdn.net/download/jlq_diligence/20951611
|