springmvc访问根路径时默认跳转到指定页
解决方法:
以下代码就是配置springmvc访问根路径时默认跳转到首页,例如访问localhost:8080时跳转到首页。
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
@Configuration
class DefaultPageForword extends WebMvcConfigurerAdapter {
public void addViewControllers(ViewControllerRegistry registry) {
String defaultPage = "/index";//这里可以读取配置文件的值
registry.addViewController("/").setViewName("forward:" + defaultPage);
registry.setOrder(-2147483648);
super.addViewControllers(registry);
}
}
向大家推荐《Activiti工作流实战教程》:https://xiaozhuanlan.com/activiti