gpt4 book ai didi

java - 从soap web服务返回ObjectId

转载 作者:行者123 更新时间:2023-12-02 05:51:06 25 4
gpt4 key购买 nike

我有2个java应用程序。 Soap 服务器 (jax-ws) 和 Soap 客户端。 Soap服务器使用spring mongo和mongoDb作为数据库。所以,在我的服务器上,我有返回所有公司的方法

@WebMethod(operationName = "getCompanies")
public CompanyList getCompanies(){
CompanyList companyList = new CompanyList();
companyList.companyDocArrayList = Lists.newArrayList(orgStructService.getCompanyDocService().findAll());
return companyList;
}

公司列表类

public class CompanyList {
public ArrayList<CompanyDoc> companyDocArrayList;
}

和公司文档

public class CompanyDoc{
@Id
private ObjectId id;
private String companyName;
//getter setter
}

所以,当我调用这个方法时

 ClientService clientService = new ClientService Service().getClientServicePort();
modelMap.addAttribute("companyList", clientService.getCompanies().getCompanyDocArrayList());

在列表中的 clientService.getCompanies() 中,我得到奇怪的 objectId,例如 com.web.client.services.ws.ObjectId@45ee7ab1 (45ee7ab1 - 此值每次刷新页面都会更改)但在数据库中它是 5369fefa1d6e6712866daaea

我做错了什么?

最佳答案

似乎JAX-WS不知道如何将ObjectId对象转换为String。我不知道您如何使用文档,但我认为您可以在 CompanyDoc 对象中使用 String 而不是 ObjectId 。当您插入数据时,Spring data 会将您的 String 转换为 ObjectId,反之亦然。

public class CompanyDoc{
@Id
private String id;
private String companyName;
//getter setter
}

更多信息来自documentation

The following outlines what type conversion, if any, will be done on the property mapped to the _id document field when using the MappingMongoConverter, the default for MongoTemplate.

  • An id property or field declared as a String in the Java class will be converted to and stored as an ObjectId if possible using a Spring
    Converter. Valid conversion rules are delegated to
    the Mongo Java driver. If it cannot be converted to an ObjectId, then the value will be stored as a string in the database.
  • An id property or field declared as BigInteger in the Java class will be converted to and stored as an ObjectId using a Spring
    Converter.

关于java - 从soap web服务返回ObjectId,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23525747/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com