Spring boot访问静态资源
访问静态资源
添加静态资源
直接访问
访问index.html
@Controller
public class HelloController {
@RequestMapping({
"/","/index.html"})
public String index(){
return "index";
}
}
自定义WebMvcConfigurerAdapter
访问login.html
//使用WebMvcConfigurerAdapter可以来扩展SpringMVC的功能
//@EnableWebMvc 全面接管SpringMVC
@Configuration
public class MyMvcConfig extends WebMvcConfigurerAdapter {
//所有的WebMvcConfigurerAdapter组件都会一起起作用
@Bean //将组件注册在容器
public WebMvcConfigurerAdapter webMvcConfigurerAdapter() {
WebMvcConfigurerAdapter adapter = new WebMvcConfigurerAdapter() {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("login");
registry.addViewController("/index.html").setViewName("login");
registry.addViewController("/main.html").setViewName("dashboard");
}
};
return adapter;
}
}
还没有评论,来说两句吧...