返回頁面需要引入
<!--html--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <!--jsp--> <dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-jasper</artifactId> </dependency>
設置默認頁面
方案1:controller里添加一個"/"的映射路徑
@RequestMapping("/") public String index(Model model, HttpServletResponse response) { model.addAttribute("name", "simonsfan"); return "/index"; }
方案二:設置默認的View跳轉頁面
@Configuration public class DefaultView extends WebMvcConfigurerAdapter { @Override public void addViewControllers(ViewControllerRegistry registry) { registry.addViewController("/").setViewName("index"); registry.setOrder(Ordered.HIGHEST_PRECEDENCE); super.addViewControllers(registry); } }
如上兩種方式均可實現在springboot中設置默認頁面跳轉。