在我当前的项目中,我有 2 个模块 ModuleA 和 ModuleB,在 ModuleA 和 ModuleB 中,我有一个名为“Student”的类(相同的类名,相同的属性,但出于某种目的,ModuleA 必须调用 ModuleB 来执行实际任务) 。他们通过 Web 服务相互通信。现在我希望 ModuleA Web 服务调用 ModuleB 代理来执行实际任务。
在我的 ModuleA Web 服务中,我有一个创建记录的方法:
public void createStudent(ModuleA.Student student){
// Here will call ModuleB proxy to do the actual task which is create.
*moduleBFacade().createStudent( );*
}
在我的 ModuleB 代理中:
public void createStudent(ModuleB.Student student){}
所以现在的问题是,我无法将 moduleA 对象传递到 createStudent 方法中,因为它只接受 moduleB 对象作为参数。
知道如何解决这个问题吗?请给我一些建议。
最佳答案
当您使用 WS 调用时,您可以将 moduleA.Student 转换为 xml,然后更改 xml 的命名空间,然后从 xml 实例化 moduleB.Student 对象。
类似于:
String xmlA = moduleA.Student.toXml();
//Change namespace. Also, Compare the genrated xml of ModuleA and ModuleB.
ModuleB.BStudent studentB= StudentDocument.Factory.parse(xmlA, ..);//second argument can be diff namespace
*moduleBFacade().createStudent(studentB);
关于java - 如何将两个不同的对象映射在一起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1943743/