美文网首页SpringBoot
Spring boot中请求的转换

Spring boot中请求的转换

作者: 飞翔的企鹅lw | 来源:发表于2019-02-05 16:54 被阅读0次

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");

                }

         }

相关文章

网友评论

    本文标题:Spring boot中请求的转换

    本文链接:https://www.haomeiwen.com/subject/hbsvsqtx.html