1.后端Controller
package com.example.demopro.controller.Upload;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import javax.imageio.ImageIO;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.HashMap;
import java.util.Map;
@RestController
public class UploadController {
//本机的文件路径
//String pathname = "/Users/wanna/Desktop/blog/UserLoginDemo/Demo/demopro/src/main/resources/file/logo";
//服务器的文件路径
String pathname = "/java/file/logo";
@RequestMapping(value = "/file/getlogo", method = RequestMethod.GET)
public void GetLogo(HttpServletRequest request, HttpServletResponse response) throws IOException {
//获取用户输入的用户名
String username = SecurityContextHolder.getContext().getAuthentication().getName();
String filename = "logo_" + username + ".jpg"; //根据用户名生成文件名
File file = new File(pathname, filename);
FileInputStream fis;