4
回答
这是什么情况?属性中间不能有大写字母吗?
利用AWS快速构建适用于生产的无服务器应用程序,免费试用12个月>>>   

这是很简单的domain类:

public class Zyd extends KoalaAbstractEntity{
private String zydName;//名称
private String generalManagerName ;//总经理名称
private String generalManagerPhone;//总经理电话
private String zydMode;//
private String brand;//
private String commissionerName ;//
private String commissionerPhone ;//
private String secondaryStoreName;//
private String deliveryAdress ;//
private String regionManagerName ;
private String regionManagerPhone;
get set 

自动生成的dto

System.out.println(DumpUtilities.dump(zydDTO));
Zyd zyd = new Zyd();
try {
        BeanUtils.copyProperties(zyd, zydDTO);
        } catch (Exception e) {
        e.printStackTrace();
        }
System.out.println(DumpUtilities.dump(zyd));

这是打印的信息:很多属性没有copy上,好象有什么规律

{String zydName="aaa";String zydMode="bbb";String generalManagerName="ccc";String commissionerName="fff";String regionManagerName="kkk";String commissionerPhone="hhh";String regionManagerPhone="lll";String secondaryStoreName="iii";String deliveryAdress="jjj";String brand="eee";String generalManagerPhone="ddd";}
{String zydName=null;String generalManagerName="ccc";String generalManagerPhone="ddd";String zydMode=null;String brand="eee";String commissionerName="fff";String commissionerPhone="hhh";String secondaryStoreName=null;String deliveryAdress="jjj";String regionManagerName=null;String regionManagerPhone=null;}


举报
regalechina...
发帖于4年前 4回/356阅

以下是问题补充:

共有4个答案 最后回答: 4年前

路过绑定吧,从代码上看不出问题。

应该不是大写的问题。因为java的习惯用法就是camel命名。

不知道你set get是怎么写的,这个地方才是关键,你需要贴上来更多的代码。

public class ZydDTO implements Serializable {


private Long id;



private String zydName;


@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date opDate;

@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date opDateEnd;

private String memo;


private String zydMode;


private String generalManagerName;


private String commissionerName;


private String regionManagerName;


private String commissionerPhone;


private String regionManagerPhone;


private String opMan;


private String secondaryStoreName;


private String deliveryAdress;


private String brand;


private String generalManagerPhone;





public void setZydName(String zydName) { 
this.zydName = zydName;
}


public String getZydName() {
return this.zydName;
}





public void setOpDate(Date opDate) { 
this.opDate = opDate;
}


@JsonSerialize(using = JsonDateSerializer.class)
public Date getOpDate() {
return this.opDate;
}

public void setOpDateEnd(Date opDateEnd) { 
this.opDateEnd = opDateEnd;
}


@JsonSerialize(using = JsonDateSerializer.class)
public Date getOpDateEnd() {
return this.opDateEnd;
}




public void setMemo(String memo) { 
this.memo = memo;
}


public String getMemo() {
return this.memo;
}





public void setZydMode(String zydMode) { 
this.zydMode = zydMode;
}


public String getZydMode() {
return this.zydMode;
}





public void setGeneralManagerName(String generalManagerName) { 
this.generalManagerName = generalManagerName;
}


public String getGeneralManagerName() {
return this.generalManagerName;
}





public void setCommissionerName(String commissionerName) { 
this.commissionerName = commissionerName;
}


public String getCommissionerName() {
return this.commissionerName;
}





public void setRegionManagerName(String regionManagerName) { 
this.regionManagerName = regionManagerName;
}


public String getRegionManagerName() {
return this.regionManagerName;
}





public void setCommissionerPhone(String commissionerPhone) { 
this.commissionerPhone = commissionerPhone;
}


public String getCommissionerPhone() {
return this.commissionerPhone;
}





public void setRegionManagerPhone(String regionManagerPhone) { 
this.regionManagerPhone = regionManagerPhone;
}


public String getRegionManagerPhone() {
return this.regionManagerPhone;
}





public void setOpMan(String opMan) { 
this.opMan = opMan;
}


public String getOpMan() {
return this.opMan;
}





public void setSecondaryStoreName(String secondaryStoreName) { 
this.secondaryStoreName = secondaryStoreName;
}


public String getSecondaryStoreName() {
return this.secondaryStoreName;
}





public void setDeliveryAdress(String deliveryAdress) { 
this.deliveryAdress = deliveryAdress;
}


public String getDeliveryAdress() {
return this.deliveryAdress;
}





public void setBrand(String brand) { 
this.brand = brand;
}


public String getBrand() {
return this.brand;
}





public void setGeneralManagerPhone(String generalManagerPhone) { 
this.generalManagerPhone = generalManagerPhone;
}


public String getGeneralManagerPhone() {
return this.generalManagerPhone;
}

zyd的get,set代码是eclipse自动生成的

public String getZydName() {
return zydName;
}
public void setZydName(String zydName) {
this.zydName = zydName;
}
public String getGeneralManagerName() {
return generalManagerName;
}
public void setGeneralManagerName(String generalManagerName) {
this.generalManagerName = generalManagerName;
}
public String getGeneralManagerPhone() {
return generalManagerPhone;
}
public void setGeneralManagerPhone(String generalManagerPhone) {
this.generalManagerPhone = generalManagerPhone;
}
public String getZydMode() {
return zydMode;
}
public void setZydMode(String zydMode) {
this.zydMode = zydMode;
}
public String getBrand() {
return brand;
}
public void setBrand(String brand) {
this.brand = brand;
}
public String getCommissionerName() {
return commissionerName;
}
public void setCommissionerName(String commissionerName) {
this.commissionerName = commissionerName;
}
public String getCommissionerPhone() {
return commissionerPhone;
}
public void setCommissionerPhone(String commissionerPhone) {
this.commissionerPhone = commissionerPhone;
}
public String getSecondaryStoreName() {
return secondaryStoreName;
}
public void setSecondaryStoreName(String secondaryStoreName) {
this.secondaryStoreName = secondaryStoreName;
}
public String getDeliveryAdress() {
return deliveryAdress;
}
public void setDeliveryAdress(String deliveryAdress) {
this.deliveryAdress = deliveryAdress;
}
public String getRegionManagerName() {
return regionManagerName;
}
public void setRegionManagerName(String regionManagerName) {
this.regionManagerName = regionManagerName;
}
public String getRegionManagerPhone() {
return regionManagerPhone;
}
public void setRegionManagerPhone(String regionManagerPhone) {
this.regionManagerPhone = regionManagerPhone;
}



import java.util.Collection;
import java.util.List;


import org.dozer.DozerBeanMapper;


import com.google.common.collect.Lists;


/**
 * 简单封装Dozer, 实现深度转换Bean<->Bean的Mapper.实现:
 * 
 * 1. 持有Mapper的单例.
 * 2. 返回值类型转换.
 * 3. 批量转换Collection中的所有对象.
 * 4. 区分创建新的B对象与将对象A值复制到已存在的B对象两种函数.
 * 
 * @author calvin
 */
public class BeanMapper {


/**
* 持有Dozer单例, 避免重复创建DozerMapper消耗资源.
*/
private static DozerBeanMapper dozer = new DozerBeanMapper();


/**
* 基于Dozer转换对象的类型.
*/
public static <T> T map(Object source, Class<T> destinationClass) {
return dozer.map(source, destinationClass);
}


/**
* 基于Dozer转换Collection中对象的类型.
*/
public static <T> List<T> mapList(Collection sourceList, Class<T> destinationClass) {
List<T> destinationList = Lists.newArrayList();
for (Object sourceObject : sourceList) {
T destinationObject = dozer.map(sourceObject, destinationClass);
destinationList.add(destinationObject);
}
return destinationList;
}


/**
* 基于Dozer将对象A的值拷贝到对象B中.
*/
public static void copy(Object source, Object destinationObject) {
dozer.map(source, destinationObject);
}

/**
* 基于Dozer将对象B的值拷贝到对象A中.
*/
public static void copyProperties(Object destinationObject, Object source) {
dozer.map(source, destinationObject);
}
}


顶部