2

我正在使用 liferay 并希望将图像存储在我的 MySQL 数据库中。我的 service.xml 是这样的:

<entity name="DLApp" local-service="true" remote-service="true">
    <column name="blobId" type="long" primary="true" />
    <column name="desc" type="String" />
    <column name="image" type="Blob" />
</entity>

当我构建服务时,我收到 BUILD SUCCESSFUL 消息,但在 blobuploadModelImpl 类中的包 com.test.blob.upload 中出现错误。

我应该如何编写函数将图像存储在数据库中并检索它?

4

2 回答 2

1

I had same issue with Blob, so I changed it to String type, it was enought to store images up to 10 MB as string, I have used MySql as database and those column was mapped as LONGTEXT. Also field should be 'hinted' in model hints as CLOB, See example below.

<entity name="UserExt" local-service="true" remote-service="true">
    <column name="photo" type="String" />
</entity>

<model-hints>
    <model name="com.project.model.UserExt">
                <field name="photo" type="String">
            <hint-collection name="CLOB" />
        </field>
       </model>
</model-hints>

Alternativelly you can store your images to Liferay's image gallery.

于 2013-10-29T08:19:01.487 回答
0

假设我的实体名称是 SB_Claims 所以我通常在 SB_ClaimsModelImpl.java 类中得到一个错误

     sb_ClaimsModelImpl._ContentBlobModel = null;

sb_ClaimsModelImpl 变量未声明或定义。我们只是在服务构建操作之后声明了这个变量。如果您再次构建服务,则此代码将被服务构建器删除。始终在构建服务之后使用此代码,然后不构建服务,只需部署您的 portlet。这将解决问题。在下面我只是修改那个类。

    @Override
    public void resetOriginalValues() 
    {
SB_ClaimsModelImpl sb_ClaimsModelImpl=this;
sb_ClaimsModelImpl._ContentBlobModel = null;
     }

希望这对某人有帮助。

于 2014-02-05T06:50:42.130 回答