springboot view resolver

View resolver: Simply put, forward the user request to the corresponding page

Method 1: application.properties

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

Method 2: Java class processing
 

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

 

Guess you like

Origin blog.csdn.net/qq_36521848/article/details/106578906