跟着视频,用给的源码来整个项目,奈何给的源码真是bug百出!
前端是一个登录页面得表单,截取了一部分。与此html没有关系。
后端Controller
@Controller
public class IndexController {
@GetMapping("/login")
public String loginPage() {
return "login";
}
运行得时候就会出现网页显示这种错误:
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.)
翻译如下:
发生意外错误(类型=内部服务器错误,状态= 500)。 循环视图路径[登录]:将再次分派回当前的处理程序URL [/
login]。检查您的ViewResolver设置!(提示:由于默认视图名称的生成,这可能是未指定视图的结果。)
javax.servlet.ServletException:循环视图路径[登录]:将再次分派回当前处理程序URL [/
login]。检查您的ViewResolver设置!(提示:这可能是一个未指定的视图的结果,由于默认视图名称生成。)
搜索之后网上提示说将@Controller换为@RestController,然后return“ login” 但是在网页中显示得是login这个字符串,不是我要得结果。后来问了实训老师(大佬),看了后原来我没有引入thymeleat模板引擎得maven依赖,导致直接访问templates目录下的html不能访问。就会爆出此错误。
templetes与springboot中静态资源目录不一样,templates需要依靠引入thymeleat依赖来实现类似静态目录直接访问得功能****还应该注意的是,当在html中使用thymeleat语法得时候在html中加入以下一段代码xmlns:th="http://www.thymeleaf.org"否则也会爆出此类错误,还应该注意springboot主类的位置问题,位置应该高于src中其他类
<html lang="en" xmlns:th="http://www.thymeleaf.org">