SpirngBoot-添加视图控制器

WebMvcConfigurerAdapter.addViewControllers()

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
@SpringBootApplication
public class Main extends WebMvcConfigurerAdapter {
@Bean
public InternalResourceViewResolver viewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/pages/");
resolver.setSuffix(".jsp");
return resolver;
}
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/home").setViewName("myhome");
registry.addViewController("/hello").setViewName("helloworld");
registry.addRedirectViewController("/home", "/hello");
registry.addStatusController("/detail", HttpStatus.BAD_REQUEST);
}
}

ParameterizableViewController

直接用ParameterizableViewController

坚持技术分享,您的支持将鼓励我继续创作!