1. Log section definition
@Aspect @Component public class LogAspect { @Around(value =
"@annotation(log)") public Object log(ProceedingJoinPoint joinPoint, Log log)
throws Throwable { Object result = joinPoint.proceed(); //do something else
Map<String,Object> map = new HashMap<>(); map.put("userDo",result); Object id =
new SimpleTemplateEngine().createTemplate(log.id()).make(map); Object content =
new SimpleTemplateEngine().createTemplate(log.content()).make(map); return
result; } }
2. Log annotation definition
@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME) @Inherited @Documented public @interface
Log { String id() default ""; String content() default ""; }
3. Entity class definition
@Data public class UserDo { private Long id; private String userName; private
int age; }
4. Interface and implementation definition
public interface UserService { UserDo add(UserDo userDo); } @Component public
class UserServiceImpl implements UserService { @Override @Log(id =
"${userDo.id}", content = "${userDo}") public UserDo add(UserDo userDo) {
userDo.setId(1L); userDo.setUserName(" Zhang San "); userDo.setAge(18); return userDo; }
}
Technology