方式一:
通过application.properties配置文件进行设置
项目启动后直接访问templates下的html
spring.resources.static-locations=classpath:/templates/
spring.freemarker.suffix=.html
spring.freemarker.template-loader-path=classpath:/templates/
方式二:
通过ClassPathResource获取resources下的HTML文件
通过OutputStream输出流将HTML文件写到浏览器
@RequestMapping(value = "/test", method = RequestMethod.GET)
public void test(HttpServletRequest request, HttpServletResponse response) throws IOException {
//使用ClassPathResource获取resources下的HTML文件
ClassPathResource resource = new ClassPathResource("temp.html");
//获取文件的输入流
InputStream in = resource.getInputStream();
// 创建输出流
OutputStream out = response.getOutputStream();
// 缓存区
byte buffer[] = new byte[1024