SpringBoot学习日记 – 20190624
- @Basic
- @Slf4j
- BeanUtils.copyProperties(Object source, Object target)
- 引申阅读
@Basic
简单定义“属性–表”映射
@Target({METHOD, FIELD})
@Retention(RUNTIME)
public @interface Basic {
/**
* (Optional) Defines whether the value of the field or property should
* be lazily loaded or must be eagerly fetched. The <code>EAGER</code>
* strategy is a requirement on the persistence provider runtime
* that the value must be eagerly fetched. The <code>LAZY</code>
* strategy is a hint to the persistence provider runtime.
* If not specified, defaults to <code>EAGER</code>.
*/
FetchType fetch() default EAGER;
/**
* (Optional) Defines whether the value of the field or property may be null.
* This is a hint and is disregarded for primitive types; it may
* be used in schema generation.
* If not specified, defaults to <code>true</code>.
*/
boolean optional() default true;
}
@Slf4j
与lombok配合,可以省略 private final Logger logger = LoggerFactory.getLogger(XXX.class);
@Slf4j
public class LoggerTest {
private final Logger logger = LoggerFactory.getLogger(LoggerTest.class);
/**
* 一、传统方式实现日志
*/
@Test
public void test1(){
logger.debug("debug message");
logger.warn("warn message");
logger.info("info message");
logger.error("error message");
logger.trace("trace message");
}
/**
* 二、注解方式实现日志
*/
@Test
public void test2(){
log.debug("debug message");
log.warn("warn message");
log.info("info message");
log.error("error message");
log.trace("trace message");
}
}
BeanUtils.copyProperties(Object source, Object target) 用的反射技术,比较耗时。(同名复制,非同名则不作操作),一个更好的办法是利用ReflectASM(原理是ASM字节码技术)
引申阅读 (Java ASM技术介绍,屏蔽class字节码地址偏移信息,利用封装接口实现修改.class文件)