您的位置:首页 > 编程语言 > Java开发

idea springboot+springsecurity项目html界面跳转

2018-03-16 20:04 483 查看
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

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  html界面跳转