First, source code analysis
Look at the source code to write your own custom exception view
resolveErrorView () function first calls a function that returns the ModelAndView, required for the function parameter is a string of a status code, and a map collection, which is error information
The figure below is the function
The figure function you determine whether to provide a dynamic error page templates / error / under
If a direct view name and return an error message
If you do not provide the figure below
Then check whether there is a static error page
The figure is a static error page determination logic
this.resourceProperties.getStaticLocations()
The return of a few static pages springboot default folder
Each cycle find a folder for errors page
If the cycle is over are not found return null
Second, the view custom exception
If we want to customize their view is abnormal rewrite resolveErrorView () function
But we do not need to judge the trouble to write, direct return ModelAndview with a view name and error messages