视图解析器:简单来说,将用户请求转到对应页面
方式一:application.properties
1 2 3 | #配置视图解析器 spring.mvc.view.prefix=/WEB-INF/pages/ spring.mvc.view.suffix=.jsp |
方式二:Java类处理
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.ViewResolver; import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; import org.springframework.web.servlet.view.InternalResourceViewResolver; /** * * 配置视图解析器 * @author szxx * @since 06/02/2020 */ @Configuration @EnableWebMvc public class MvcViewConfig extends WebMvcConfigurerAdapter { @Bean public ViewResolver getViewResolver() { InternalResourceViewResolver resolver = new InternalResourceViewResolver(); resolver.setPrefix("/WEB-INF/pages/"); resolver.setSuffix(".jsp"); return resolver; } @Override public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) { configurer.enable(); } } |