1. 创建一个有web的springboot项目
2. 在src/main/java中创建一个FileController
代码如下:
@Controller
public class FileController {
@RequestMapping(value = "/api/v1/gopage")
public Object index() {
return "index";
}
private static final String filePath = "F:\\javaStudy\\demo\\src\\main\\resources\\static\\images\\";
@RequestMapping(value = "upload")
@ResponseBody
public JsonData upload(@RequestParam("head_img") MultipartFile file, HttpServletRequest request) {
//file.isEmpty(); 判断图片是否为空
//file.getSize(); 图片大小进行判断
String name = request.getParameter("name");
System.out.println("用户名:"+name);
// 获取文件名
String fileName = file.getOriginalFilename();
System.out.println("上传的文件名为:" + fileName);
// 获取文件的后缀名,比如图片的jpeg,png
String suffixName = fileName.substring(fileName.lastIndexOf