[英]Dozer, how to map using methods result
Have for exemple two classes : 例如有两节课:
public class A
{
public int doSomething()
{
return 12;
}
}
public class B
{
private int something;
public int getSomething()
{
return something;
}
public void setSomething(int s)
{
something = s;
}
}
Can I map the result of doSomething()
in A
to something in B
? 我可以将
A
中doSomething()
的结果映射到B
中A
某个对象吗?
Thanks for your answers :) 感谢您的回答:)
I don't think it is possible , because Dozer do field to field level mapping by using reflection , now it can be implicit (if fields name are same) and explicit (if fields name are different.) . 我认为这是不可能的,因为Dozer通过使用反射来进行字段到字段级别的映射,现在它可以是隐式的(如果字段名称相同)和显式的(如果字段名称不同)。 So, if you want to use Dozer you should have corresponding source and destination field available in your source and destination clasess.
因此,如果要使用推土机,则源和目标分类中应具有相应的源和目标字段。
But in your Class A
, I am not able to see anyfield , so how you will do the mapping. 但是在您的
Class A
,我看不到任何字段,因此您将如何进行映射。 More importantly setter and getter for any field should also be present otherwise you will get a run time exception until and unless you are using custom getter and setter method approach, same is missing in your Class A
. 更重要的是,还应该存在任何字段的setter和getter,否则除非您使用自定义的getter和setter方法方法,否则您将获得运行时异常,而在
Class A
则缺少该方法。
Please have a look at dozer framework . 请看一下推土机框架 。
Thanks 谢谢
我没有做这个自己,但你可以尝试定制提到get / set方法途径这里
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.