springboot视图解析器

视图解析器:简单来说,将用户请求转到对应页面

方式一:application.properties

#配置视图解析器
spring.mvc.view.prefix=/WEB-INF/pages/
spring.mvc.view.suffix=.jsp

方式二:Java类处理
 

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();
    }
}

猜你喜欢

转载自blog.csdn.net/qq_36521848/article/details/106578906