springboot设置默认访问路径

曾经终败给现在 2022-03-11 16:34 581阅读 0赞
idea中设置项目访问http://localhost:8080或者http://localhost:8080/index.html都跳转到login.html
1、引入jquery-webjar
  1. <dependency>
  2. <groupId>org.webjars</groupId>
  3. <artifactId>jquery</artifactId>
  4. <version>3.3.1</version>
  5. </dependency>
2、在springboot/config/MyMvcConfig.java编写
以前的
  1. @Configuration
  2. public class MyMvcConfig extends WebMvcConfigurerAdapter {
  3. @Override
  4. public void addViewControllers(ViewControllerRegistry registry) {
  5. registry.addViewController("/").setViewName("login");
  6. registry.addViewController("/index.html").setViewName("login");
  7. }
  8. }

中的WebMvcConfigurerAdapter已经失效了,过期了,所以用实现WebMvcConfigurer方法代替。

最新的
  1. @Configuration
  2. public class MyMvcConfig implements WebMvcConfigurer {
  3. //一系列实现方法
  4. @Override
  5. public void addViewControllers(ViewControllerRegistry registry) {
  6. registry.addViewController("/").setViewName("login");
  7. registry.addViewController("/index.html").setViewName("login");
  8. }
  9. }

发表评论

表情:
评论列表 (有 0 条评论,581人围观)

还没有评论,来说两句吧...

相关阅读