Liferay7 BPM Portal Development 34:liferay7 External service class generation (Restservice Get Url)

Source: Internet
Author: User

Developing an external service class that does not rely on service builder in Liferay7 is very concise and requires only 2 points of annotation:

    • Defined in the front of the class:

@ApplicationPath ("/pathxxx")

    • Method before definition:

@GET
@Path ("/actionxxx")
@Produces ("Text/plain")

Example: getting a registered user

Import Com.liferay.portal.kernel.model.user;import Com.liferay.portal.kernel.service.userlocalservice;import Java.util.collections;import Java.util.set;import Javax.ws.rs.applicationpath;import Javax.ws.rs.GET;import Javax.ws.rs.path;import Javax.ws.rs.produces;import Javax.ws.rs.core.application;import Org.osgi.service.component.annotations.component;import org.osgi.service.component.annotations.reference;@ Applicationpath ("/allUsers ") @Component (Immediate=true, property = {"jaxrs.application=true"}, Service= Application.class) Public classUsersrestservice extends Application {@Override PublicSet<object>getsingletons () {returnCollections.singleton ((Object) This); } @GET @Path ("/list ") @Produces ("Text/plain")     PublicString getAllUsers () {StringBuilder result=NewStringBuilder ();  for(User User: _userlocalservice.getusers (-1, -1) {result.append (User.getfullname ())). Append (", \ n"); }        returnresult.tostring (); } @Reference Public voidSetuserlocalservice (Userlocalservice userlocalservice) {_userlocalservice=Userlocalservice; }    Privateuserlocalservice _userlocalservice;}

OSGi syntax is really concise.

Liferay7 BPM Portal Development 34:liferay7 External service class generation (Restservice Get Url)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.