😊

【Spring Boot】ファイルアップロードの際のファイルサイズチェックのサンプルコード

に公開
package com.example.springPractical.util;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.multipart.MaxUploadSizeExceededException;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

@ControllerAdvice
public class FileControllerAdvice {
	@ExceptionHandler(MaxUploadSizeExceededException.class)
	public String maxUploadSizeException(MaxUploadSizeExceededException e, RedirectAttributes redirectAttributes){ 
		  redirectAttributes.addFlashAttribute("errorMessage","ファイルサイズが違います"); 
		return "redirect:/itemCreate";
	}
}

Udemyで講座を公開中!
https://zenn.dev/codek2/articles/e9e44f3e0023fb

X(旧Twitter)
https://twitter.com/kunchan2_

Zenn 本
https://zenn.dev/codek2?tab=books

Youtube
https://www.youtube.com/@codek2_studio

Discussion