package com.onepro.custom.utils.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
@Configuration
public class DefaultView extends WebMvcConfigurerAdapter {
public static String LOGIN_USER = "loginUser";
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("forward:/index.html");
registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
super.addViewControllers(registry);
}
}
注 : 静态页面放在 src/main/resources/static 里面
本文介绍了一个使用Spring MVC配置默认视图控制器的例子。通过继承WebMvcConfigurerAdapter并覆盖addViewControllers方法,可以轻松地设置应用程序的基础路由。此外,还说明了如何将静态资源文件放置在项目的src/main/resources/static目录下。
1530

被折叠的 条评论
为什么被折叠?



