Exception Handling

Controller Advice

The @ControllerAdvice is an annotation, to handle the exceptions globally.

Exception Handler

The @ExceptionHandler is an annotation used to handle the specific exceptions and sending the custom responses to the client.

Update URL: http://localhost:8071/products/9

Interceptor

  • preHandle() method − This is used to perform operations before sending the request to the controller. This method should return true to return the response to the client.
  • postHandle() method − This is used to perform operations before sending the response to the client.
  • afterCompletion() method − This is used to perform operations after completing the request and response.

Servlet Filter

https://p.130014.xyz/2021/03/06/Servlet_URL-min.pngServlet_URL

  • SimpleFilter

File Handling

File Upload

@RequestMapping(value = "/upload", method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public String fileUpload(@RequestParam("file") MultipartFile file) {
   return null;
}

File Download

  • FileDownloadController
  • http://localhost:8071/download