SpringBoot学习日记 -- 20190624

SpringBoot学习日记 – 20190624

  1. @Basic
  2. @Slf4j
  3. BeanUtils.copyProperties(Object source, Object target)
  4. 引申阅读

@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文件)

  1. https://blog.csdn.net/zhuoxiuwu/article/details/78619645
  2. https://www.ibm.com/developerworks/cn/java/j-lo-asm30/
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值