1、
说道跳转,先说一下springBoot web的结构
其中static 中放的是可一直接访问的数据 ,比如[http://localhost:8080/helloWorld.html]
可以直接访问html
templates 中放置的是跳转的数据
2、jar包依赖
Springboot有自己默认的模板引擎。一定要引用相应的依赖包。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
这里注意:静态页面的return默认是跳转到/static/index.html,当在pom.xml中引入了thymeleaf组件,动态跳转会覆盖默认的静态跳转,默认就会跳转到/templates/index.html,注意看两者return代码也有区别,动态有或没有html后缀都可以。
3、注解
注解使用@Controller 而不是@RestController
4、ModelAndView
跳转可以包含视图和数据
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("test1");
modelAndView.addObject("key", 12345);
//System.out.println("test");
return modelAndView;
上例可以跳转到test1视图中,并带上key值