• 2024-06-12SpringBoot 多文件打包下载
    第一种@RestController@RequestMapping("/download")publicclassDownloadController{@GetMapping("/files")publicResponseEntity<InputStreamResource>downloadFiles()throwsIOException{//
  • 2024-05-06RestTemplate返回结果乱码的两种解决方案
    以下代码调用某接口时出现乱码:HttpHeadershttpHeaders=newHttpHeaders();httpHeaders.add("Content-Type","application/json;charset=utf-8");org.springframework.http.HttpEntity<String>httpEntity=neworg.springframework.http.HttpEntity<
  • 2024-01-20spring boot 文件下载最好设置nosniff
    实际上就是添加X-Content-Type-Optionsnosniff规避浏览器嗅探,规避一些问题参考代码以下是一个部分参考代码@GetMapping("/{filename:.+}")publicResponseEntity<Resource>downloadFile(@PathVariableStringfilename)throwsIOException{Res
  • 2023-11-10SprigMvc文件下载
    @RequestMapping(method=RequestMethod.GET,value="/down")publicResponseEntity<byte[]>DownLoad(HttpServletRequestrequest,Stringfilename){//获取文件的真实路径StringrealPath=request.getServletContext().getRealPath("/WEB-INF/d
  • 2023-09-20简单使用RestTemplate发起get请求
    Stringurl="https://erp.sunjoin.cn/business/TbCompany/list?pageNum=1&pageSize=10&regionId=";//创建RestTemplate实例RestTemplaterestTemplate=newRestTemplate();//设置请求头比如token//和设置请求类型application/json:用于
  • 2023-09-01Gateway跨域请求配置
    importorg.springframework.context.annotation.Bean;importorg.springframework.context.annotation.Configuration;importorg.springframework.http.HttpHeaders;importorg.springframework.http.HttpMethod;importorg.springframework.http.HttpStatus;importor