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;
/**
* 系统默认界面设置
*
* @auther hzy
* @data 2018/4/28 9:59
* @QQ 291471000
*/
@Configuration
public class DefaultView extends WebMvcConfigurerAdapter {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
// login页面在 templates 文件夹下
registry.addViewController("/").setViewName("login");
registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
super.addViewControllers(registry);
}
}
上述写法其实对等于
@RequestMapping("/")
public String view(){
return "login";
}
本文介绍了一种通过Spring MVC配置默认视图控制器的方法,利用这种方式可以轻松地为Web应用指定默认显示的视图页面。

1万+

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



