How to create Liferay JSON web service for existin

2019-06-14 04:14发布

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.

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.

1条回答
走好不送
2楼-- · 2019-06-14 04:33

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>

This will create FooServiceImpl and FooLocalServiceImpl that you can use to implement your business logic, without any attached database table.

查看更多
登录 后发表回答