About java architecture experience

Beginning of previous knowledge to organize the systematic documentation, will share the experience of previous framework set up for everyone

 

First, open the jar package

1. Open global exception capture

Benefits: In the business code, do not need to focus on the return value, do not care about the format returned to the client, internal affairs special attention needs to be rolled back,

2. Example:

Provide two documents, BussException exception class, ExceptionInterceptor abnormal interceptor

2.1BussException Code: back to the client a uniform format

The return value is defined, the definition of prompt content, define the return code code

2.2 intercept ExceptionInterceptor

Can

@ExceptionHandler({BussException.class})

Logo intercept abnormal, and abnormal results returned for processing, the results are returned to the friendly page

3. Application:

You need to create the project in a class that inherits ExceptionInterceptor interceptors, and marked notes @Configuration

Use the business code:

Back to tips Results:

 

Here is a simple example, and the other: If you do not want to write the class to inherit ExceptionInterceptor, can increase spring.handler profiles jar package, point ExceptionInterceptor, Spring finished loading, it will automatically load the interceptor. Such a loading if mybatis and dubbo, etc. are also used.

 

 

Guess you like

Origin blog.csdn.net/rongshisuo/article/details/90757849