filter

Get request information in a non intrusive way , You must think of filters . The filter can get two messages ,HttpServletRequest And HttpServletResponse, You'll think I can get the information I want with these two objects . Let's try to get the corresponding information

4d089f5738f90783a676c390b4a9168f.png

 picture .png


Customize HttpServletRequest

1. Write a class input stream inheritance ServletInputStream Class :

 picture .png

2. Write a custom Request Inherit HttpServletRequestWrapper:

 picture .png

3. Be accomplished

 picture .png

 picture .png

 picture .png

Customize HttpServletResponse

 

1. Write a class output stream inheritance ServletOutputStream Class :

 picture .png

 

2. Write a custom Response Inherit HttpServletResponseWrapper:

 picture .png

3. Be accomplished

 picture .png

 picture .png

AOP The way

 

 picture .png

07e495a6bf8fbf92f2de13d260921265.png

 picture .png

Breakpoint tracking under the source code

1. First write a test class

 picture .png

2. Break point

 picture .png

 

3. From here we can see that the input parameter is from getMethodArgumentValues Acquired , Let's take a look at the source code

 

 picture .png

4. Method from parameter MethodParameter Object acquisition , Let's take a look at this class

 picture .png

5. Here's the parameter name , I'll break it again , See if this parameter name is what you want

 picture .png

6. Fabulous , This is the desired parameter name , then this.resolvers.resolveArgument Is to get the parameter value , So let's see resolvers Where is the assignment made

 picture .png

here

 picture .png

Everything comes to him who waits

See where to call this method

 picture .png

Go in and have a look

 picture .png

 picture .png

The object processor settings of the input and output parameters are all here . Take a look at the origin of this class

 

 picture .png

 

The general explanation is

Support custom parameter and return value type. You can add
* {@link #setCustomReturnValueHandlers} and {@link #setCustomReturnValueHandlers},
* perhaps , Reconfigure all parameters and return value types ,
* Use {@link #setArgumentResolvers} and {@link #setReturnValueHandlers}

 picture .png

 picture .png

 

Write custom MethodArgumentResolver

 picture .png

 

Write custom HandlerMethodReturnValueHandler

 picture .png

 

Add in / out parameter processor

 picture .png

 picture .png

Printing effect

 picture .png

 picture .png

 

 picture .png


 

-----------------END---------------------

Previous hot articles :

*【 Design patterns 】 The plane is too big Egan Can't pull

*【 Design patterns - Prototype 】Egan The last chance to get a raise

*【 Design patterns 】 Manager dobby is looking for Egan gossip

*【 Design patterns 】 Vow not to stay up late

*  The server suddenly goes down and restarts docker in redis Can't start

*  jdbc sql How to efficiently and elegantly solve the dictionary table data conversion

*  NIO Introduction --Buffer buffer

*  NIO Introduction --Channel passageway > Direct buffer

Pay attention to my oh

 picture .png