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



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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM