如何为现有表创建Liferay JSON Web服务? [英] How to create Liferay JSON web service for existing tables?
问题描述
我正在开发一个移动应用程序,该应用程序可以从基于Liferay的门户检索数据.我正在使用JSON Web服务来访问数据,例如博客条目.如何为现有表制作新的Web服务?我发现的每个教程都以一个新实体(即数据库表)的定义开始,但是我不需要.我只想以系统ws无法提供的方式访问现有数据,例如过滤具有特定结构的Web内容.
I am developing a mobile app which retrieves data from a Liferay-based portal. I am using JSON web services to access the data which works well for e.g. Blog Entries. How can I make a new web service for existing tables? Each tutorial I have found starts with the definition of a new entity (i.e. database table), but I don't need that. I just want to access existing data in such a way which is not provided by system ws, e.g. to filter web content which have a specific structure.
注意:我也尝试了一种解决方法,我设法做出了一个struts动作,该动作打印出所需的JSON数据并返回null.在浏览器中输入操作的地址时,会看到JSON字符串.但是,如果将其放在移动应用程序中,则会看到一个HTML代码,似乎它已被重定向到门户的主页.
Note: I tried also a workaround, I managed to make a struts action which prints out the desired JSON data and returns null. When I enter the address for the action in a browser, I see the JSON string. But if I put it in my mobile app, I see an HTML code, it seems that it is redirected to the home page of the portal.
推荐答案
如果您不想使用servicebuilder定义新的实体,可以使用整洁的技巧:只需将该实体留空,即可定义一个类型,但不定义任何字段,例如没有基础表.然后,通过委派任何您想要访问的持久性(甚至没有任何持久性)来实现您的方法.
Neat trick if you don't want to define a new entity with servicebuilder: Just leave the entity empty, this defines just a type, but no fields, e.g. no underlying table. Then implement your methods by just delegating to whatever persistence you'd like to access (or even without any persistence).
<Entity name="Foo" local-service="true" remote-service="true">
</Entity>
这将创建FooServiceImpl和FooLocalServiceImpl,可用于实现业务逻辑,而无需附加任何数据库表.
This will create FooServiceImpl and FooLocalServiceImpl that you can use to implement your business logic, without any attached database table.
这篇关于如何为现有表创建Liferay JSON Web服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!