A self-defined exception handling class is defined by using the exception handling mechanism of springmvc. After testing:
- 1
RuntimeException thrown by
- can be captured.
- if you customize the exception class and throw it manually, you can also catch.
- but the mysql exception does not go into the exception handling class . (such as
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException
)
exception handling class:
@ControllerAdvice
public class CustomerExceptionResolver implements HandlerExceptionResolver {
@ExceptionHandler(Exception.class)
@ResponseBody
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception e) {
e.printStackTrace();
//
log.error(":",e);
....
service method:
public ResponseResult selectByName4Smart(String name) throws CustomException {
//mapper
//mysql,
//
List<String> certNos = customerMapper.selectCertNosLikeName(name);
...