1.不用thymeleaft 模板,直接controller层跳转
controller层跳转
@RequestMapping("/")
public String index1()
{
return "index1.html";
}
----------------------------------------------------------------------------------------------------------------
index1.html文件放在main->webapp下
如果项目路径不是默认webaap 文件。可以通过project struction ->modules->添加web ,设置路径为"/";
2.用thymeleaft 模板,直接controller层跳转
controller层跳转
@RequestMapping("/")
public String index1()
{
return "index1";
}
(1).在写controller层之前,需要先引入maven 依赖
具体在pom.xml文件中添加
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency>
(2).在application.properties/application.yml 中加入
spring.thymeleaf.view.prefix=/WEB-INF/templates/
spring.thymeleaf.view.suffix=.jsp
-----------------------------------------------------------------------------------
index1.html 需要放在WEB-INF->templates文件夹中
3.用thymeleaf 模板,继承WebMvcConfigureAdapter重写addViewControllers 方法
在方法里添加controller
@Override extends public void addViewControllers(ViewControllerRegistry registry) { registry.addViewController("/").setViewName("index1"); } springboot版本记得降级, 由于目前在idea中直接创建springboot项目,springboot 的父依赖版本一般为2.0.0.release,记得改为1.4.3.release版本 否则无法继承WebMvcConfigureAdapter
(1).在写controller层之前,需要先引入maven 依赖
具体在pom.xml文件中添加
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency>
(2).在application.properties/application.yml 中加入
spring.thymeleaf.view.prefix=/WEB-INF/templates/
spring.thymeleaf.view.suffix=.jsp