新手学习springboot遇到一个thymeleaf问题。
出错信息:Circular view path [success]: would dispatch back to the current handler URL [/success] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.)
我自己搜索的结果:可能是因为view和path同名导致的问题,我尝试改过controller里面的(“/success”),但是问题并没有解决。
这是我的controller代码:
这是我的html代码:
这是我的pom里面的主要的依赖:
添加配置
spring.thymeleaf.cache=false
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html
spring.thymeleaf.mode=LEGACYHTML5
看一下是不是ModelAndView这个类的包导错了:
import org.springframework.web.servlet.ModelAndView
直接跳转的建议采用下面的配置类
@Configuration
public class SpringMvcConfig implements WebMvcConfigurer {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
// 跳转
registry.addViewController("/success").setViewName("success");
}
}
终于解决了,我在pom.xml文件里修改了一些版本问题。在spring-boot-starter-parent后面添加了版本1.5.12.RELEASE。
在springboot-04-web-restfulcrud后面添加了jar。运行后还是有错误,当然这个错误被解决了。目前的错误是:An error happened during template parsing (template: "class path resource [templates/success.html]")。后来我把success.html文件除