SpringBoot设置首页(默认页)跳转

 

方案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中设置默认页面跳转。

 

相关文章:

  • 2021-11-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-06
  • 2022-02-10
  • 2022-01-12
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-04-17
  • 2021-10-04
  • 2021-06-04
  • 2021-07-08
  • 2022-12-23
  • 2021-09-10
相关资源
相似解决方案