SpringBoot設置首頁(默認頁)跳轉


SpringBoot設置首頁(默認頁)跳轉spring

 

方案1:controller裏添加一個"/"的映射路徑springboot

@RequestMapping("/")
public String index(Model model, HttpServletResponse response) {
model.addAttribute("name", "simonsfan");
return "/index";
}
方案二:設置默認的View跳轉頁面app

@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中設置默認頁面跳轉。ide

相關文章
相關標籤/搜索