org.springframework.beans.BeanUtils#copyProperties(java.lang.Object, java.lang.Object)使用记录

属性类型必须一致,即使字段名称相同的情况下,也无法赋值。如:

package com.mbv.sc.midsvc.service.impl;

import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.math.BigDecimal;

public class TestCopy {


    @Data
    static class A {
        private BigDecimal totalQty;
    }

    @Data
    static class B {
        private Integer totalQty;
    }

    public static void main(String[] args) {
        A a = new A();
        a.setTotalQty(new BigDecimal("6"));
        B b = new B();
        BeanUtils.copyProperties(a, b);
//输出 TestCopy.B(totalQty=null) System.out.println(b); } }

 

posted on 2020-11-04 16:00  ngu2020  阅读(171)  评论(0编辑  收藏  举报