spring boot 项目中同时支持jsp ftl 映射

最近在一个项目中会用到之前项目的jsp模板,因为springboot默认是不支持jsp的

解决如下:

在主配置类中添加组件:(启动类:Application.java)

//jsp
	@Bean
	public ViewResolver getJspViewResolver() {
		InternalResourceViewResolver internalResourceViewResolver = new InternalResourceViewResolver();
		internalResourceViewResolver.setPrefix("/WEB-INF/jsp/");
		internalResourceViewResolver.setSuffix(".jsp");
		internalResourceViewResolver.setOrder(1);
		return internalResourceViewResolver;
	}

//freemaker	
	@Bean
	public FreeMarkerViewResolver getFreeMarkerViewResolver(){
		FreeMarkerViewResolver freeMarkerViewResolver = new FreeMarkerViewResolver();
		freeMarkerViewResolver.setPrefix("");
		freeMarkerViewResolver.setSuffix(".ftl");
		freeMarkerViewResolver.setOrder(0);
		freeMarkerViewResolver.setRequestContextAttribute("request");
		freeMarkerViewResolver.setContentType("text/html;charset=UTF-8");
		return freeMarkerViewResolver;
	}

那么就可以映射到/WEB-INF/jsp下的jsp文件

你可能感兴趣的:(spring)