Spring boot中请求的转换
2019-02-05 本文已影响0人
飞翔的企鹅lw
Spring boot 2.0默认是直接访问templates下的index.html
如何解决?
两种方法:
1、使用requestingmapping在controller中转发
@Controller
public class HelloController {
@RequestMapping({"/","/index.html"})
public String index(){
return "login";
}
}
2、spring boot默认直接访问templates中的index页面,可以使用如下配置类的方法改变访问页面
@Configuration
public class MyMvcConfigimplements WebMvcConfigurer {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("login");
registry.addViewController("/index").setViewName("login");
}
}