1. Set the file upload size limit:

Yml configuration file Settings:

spring:
   servlet:
     multipart:
       max-file-size: 10MB
       max-request-size: 100MB
Copy the code

2. Front-end page:

3, the control layer

package com.jf3q.study.control; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.multipart.MultipartFile; import java.io.File; import java.io.IOException; @Controller @Slf4j public class RegControl { @GetMapping("/toreg") public String toreg(){ return "register"; } /** ** usually encounter their own can not solve the bug problem can come to programming q&A platform reward q&A, * can not solve the money, address: https://www.jf3q.com/ * @param username * @param password * @param faceImg * @param lifeimg * @return */ @PostMapping("/reg") public String reg( @RequestParam("username") String username, @RequestParam("username") String password, @RequestParam("faceImg") MultipartFile faceImg, @RequestParam("lifeimg") MultipartFile[] lifeimg ) throws IOException { The info (" username: {}, password: {}, faceImg: {}, lifeimg: {} ", username, password, faceImg. GetSize (), lifeimg. Length); if(! faceImg.isEmpty()){ String originalFilename = faceImg.getOriginalFilename(); Faceimg. transferTo(new File("E:\\upload\\"+originalFilename)); } if(lifeimg.length > 0){ for(MultipartFile img :lifeimg){ if(! img.isEmpty()){ String originalFilename = img.getOriginalFilename(); TransferTo (new File("E:\\upload\\"+originalFilename)); // Get the name of the uploaded File img.transferTo(new File("E:\\upload\\"+originalFilename)); } } } return "login"; }}Copy the code

4. If there is an interceptor, the interceptor is set to release

@Override public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(new LoginInterceptor()) .addPathPatterns("/**") // All requests are blocked, Including static resources. ExcludePathPatterns ("/", "/ login", "/ toreg", "/ reg", "/ img / * *", "/ js / * *", "/ CSS / * *", "/ favicon. Ico"); // Set the path not to intercept}Copy the code

5. The effect is as follows:

What do you not understand can ask me 1913284695