commit
ccc324d142
14 changed files with 140 additions and 15 deletions
@ -0,0 +1,19 @@ |
||||
package com.msdw.tms.common.utils; |
||||
|
||||
import javax.servlet.ServletOutputStream; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.io.ByteArrayOutputStream; |
||||
import java.io.IOException; |
||||
|
||||
public class DownloadUtils { |
||||
public void download(ByteArrayOutputStream byteArrayOutputStream, HttpServletResponse response, String returnName) throws IOException { |
||||
response.setContentType("application/octet-stream"); |
||||
returnName = response.encodeURL(new String(returnName.getBytes(), "iso8859-1")); //保存的文件名,必须和页面编码一致,否则乱码
|
||||
response.addHeader("content-disposition", "attachment;filename=" + returnName); |
||||
response.setContentLength(byteArrayOutputStream.size()); |
||||
ServletOutputStream outputstream = response.getOutputStream(); //取得输出流
|
||||
byteArrayOutputStream.writeTo(outputstream); //写到输出流
|
||||
byteArrayOutputStream.close(); //关闭
|
||||
outputstream.flush(); //刷数据
|
||||
} |
||||
} |
@ -0,0 +1,19 @@ |
||||
package com.msdw.tms.config; |
||||
|
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry; |
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; |
||||
|
||||
@Configuration |
||||
public class CorsConfig implements WebMvcConfigurer { |
||||
|
||||
@Override |
||||
public void addCorsMappings(CorsRegistry registry) { |
||||
registry.addMapping("/**") |
||||
.allowedOrigins("*") |
||||
.allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS") |
||||
.allowCredentials(true) |
||||
.maxAge(3600) |
||||
.allowedHeaders("*"); |
||||
} |
||||
} |
Binary file not shown.
Loading…
Reference in new issue