Requirements describe
Every table has a creation time, a modification time, and every time you add or modify data, how do you get the database to fill in the data automatically without having to manually set the value? According to the official website documentation, we can implement an interceptor to automatically populate the time data in the database layer.
The specific implementation
Step 1: Create two annotations, one for each field
Step 2: Create an Interceptor that implements the Interceptor interface
Matters needing attention
If breakpoint debugging finds that the interceptor is not in effect, see if SpringBoot has scanned the package
role
-
Less cumbersome code development and more focus on business layer development
-
Decoupled, no need to worry about time to create, as soon as the requirements change, only need to modify the interceptor
-
It can be used as a low-level adaptation and can be achieved by simply adding annotations