22 lines
1.3 KiB
HTML
22 lines
1.3 KiB
HTML
<div class="cnblogs_code">
|
||
<pre><span style="color: #0000ff;">import</span><span style="color: #000000;"> org.springframework.web.bind.annotation.ControllerAdvice;
|
||
</span><span style="color: #0000ff;">import</span><span style="color: #000000;"> org.springframework.web.bind.annotation.ExceptionHandler;
|
||
</span><span style="color: #0000ff;">import</span><span style="color: #000000;"> org.springframework.web.bind.annotation.ResponseBody;
|
||
|
||
</span><span style="color: #008000;">/**</span><span style="color: #008000;">
|
||
* </span><span style="color: #808080;">@author</span><span style="color: #008000;"> dcrenl: 2020-10-12 19:47:39
|
||
</span><span style="color: #008000;">*/</span><span style="color: #000000;">
|
||
@ControllerAdvice
|
||
</span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span><span style="color: #000000;"> GlobalExceptionHandler {
|
||
|
||
|
||
@ResponseBody
|
||
@ExceptionHandler(Exception.</span><span style="color: #0000ff;">class</span><span style="color: #000000;">)
|
||
</span><span style="color: #0000ff;">public</span><span style="color: #000000;"> String globalException(Exception ex) {
|
||
|
||
</span><span style="color: #0000ff;">return</span><span style="color: #000000;"> ex.getMessage();
|
||
}
|
||
}</span></pre>
|
||
</div>
|
||
<p> </p>
|
||
<p>本文参考:https://www.cnblogs.com/magicalSam/p/7198420.html</p> |