问题提出
新建一个web项目
此时:return “login”; login下会有波浪线提示(这里没有,因为我已经导入了Thymelea 依赖)
想要启动项目主程序,
1)访问:http://localhost:8080/ 默认跳转到index.html界面,结果报错404
2)访问:http://localhost:8080/ login 跳转到login.html界面,结果报错500
500报错大致信息:
There was an unexpected error (type=Internal Server Error, status=500).
Circular view path [login]: would dispatch back to the current handler URL [/login] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.)
javax.servlet.ServletException: Circular view path [login]: would dispatch back to the current handler URL [/login] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.)
问题解决
需要导入thymeleaf依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
然后就可以实现通过Controller实现页面跳转了!
注:thymeleaf和jsp并不能很好的兼容,这里暂不支持jsp页面