我可以在Liferay实体中保存对象吗?

发布于 2025-02-10 18:41:15 字数 601 浏览 2 评论 0原文

我已经通过service.xml创建了Liferay实体。我可以将JSON对象保存在字符串列中并像API一样返回此值吗?现在,对“ JSON”的响应是这样的:

{
    "name": "test",
    "time": 1656067273906,
    "longitude": 00.00000,
    "latitude": 00.00000,
    "Json": "{"name":"test", "depth":"0", "main":"true", "power":"0"}",
    "description": "test",
}

但是我希望在没有引号的情况下获得“ json”价值,例如:

{
        "name": "test",
        "time": 1656067273906,
        "longitude": 00.00000,
        "latitude": 00.00000,
        "Json": {"name":"test", "depth":"0", "main":"true", "power":"0"},
        "description": "test",
}

I have created liferay entity by service.xml. Can I save Json object inside string column and return this value like object from api? Now the response for "json" is this:

{
    "name": "test",
    "time": 1656067273906,
    "longitude": 00.00000,
    "latitude": 00.00000,
    "Json": "{"name":"test", "depth":"0", "main":"true", "power":"0"}",
    "description": "test",
}

But I hope to obtain "json" value without quotes, like this:

{
        "name": "test",
        "time": 1656067273906,
        "longitude": 00.00000,
        "latitude": 00.00000,
        "Json": {"name":"test", "depth":"0", "main":"true", "power":"0"},
        "description": "test",
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

○愚か者の日 2025-02-17 18:41:15

如果您在service.xml中编写的实体具有远程服务属性设置为true,例如,

<entity name="Employee" local-service="true" remote-service="true" uuid="true" trash-enabled="true">

和一个名为的文本字段info(例如)在其中存储一个JSON字符串,然后可以在&lt;您的服务模块src&gt;/service/impl/employeeserviceimpl.java中编写方法包含来自服务实体的数据。例如,您可以将方法添加到employserviceimpl

public JSONObject myCustomMethod(long entityId) throws Exception {
    Employee employee EmployeeLocalServiceUtil.getEmployee(entityId);
    JSONObject result = JSONFactoryUtil.createJSONObject();
    result.put("name", employee.getName());
    result.put("Json", JSONFactoryUtil.createJSONObject(employee.getInfo()));
    return result;
}

之后,运行buildservice任务,然后构建 deploy> exploy 捆。您会找到mycustompothod作为JSONWS API。

If the entity you wrote in service.xml has the remote-service attribute set to true, for example

<entity name="Employee" local-service="true" remote-service="true" uuid="true" trash-enabled="true">

and a text field named info (for example) in which you store a JSON string, then you can write a method in <your service module src>/service/impl/EmployeeServiceImpl.java that returns a JSONObject containing the data from your service entities. For example you can add a method to EmployeeServiceImpl class

public JSONObject myCustomMethod(long entityId) throws Exception {
    Employee employee EmployeeLocalServiceUtil.getEmployee(entityId);
    JSONObject result = JSONFactoryUtil.createJSONObject();
    result.put("name", employee.getName());
    result.put("Json", JSONFactoryUtil.createJSONObject(employee.getInfo()));
    return result;
}

After that, run the buildService task then build and deploy your bundles. You will find myCustomMethod as JSONWS Api.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文