Getting started with myeclipse development rest Service

Source: Internet
Author: User
Document directory
  • Step 1: create a web service project;
  • Step 2: Create a class

Myeclipse supports the rest service, which is very convenient for development. Here is an example of a computer:

Functions: addition, subtraction, multiplication, and Division;

The effect is as follows:



Key points of the rest service: each service or anything has a URI;

Step 1: create a web service project; Step 2: Create a class
Package Org. xiazdong. service; import javax. WS. rs. get; import javax. WS. rs. path; import javax. WS. rs. pathparam; import javax. WS. rs. produces; import COM. sun. jersey. SPI. resource. singleton; @ produces ("text/plain") @ path ("Calculator ") @ singletonpublic class myservice {@ get // sets this service as a GET request service @ path ("Add/{ID }") // firstrest/calculator/Add/1 + 1 Public String add (@ pathparam ("ID") string s) {string [] Ss = S. split ("\ +"); Return S + "=" + String. valueof (integer. parseint (ss [0]) + integer. parseint (ss [1]);} @ get @ path ("sub/{ID }") // firstrest/calculator/Add/1-1public string sub (@ pathparam ("ID") string s) {string [] Ss = S. split ("\-"); Return S + "=" + String. valueof (integer. parseint (ss [0])-integer. parseint (ss [1]);} @ get @ path ("Mult/{ID }") // firstrest/calculator/Add/1*1 Public String mult (@ pathparam ("ID") string s) {string [] Ss = S. split ("\ *"); R Eturn S + "=" + String. valueof (integer. parseint (ss [0]) * integer. parseint (ss [1]);} @ get @ path ("DIV/{ID}") // firstrest/calculator/Add/1 ~ 1 Public String Div (@ pathparam ("ID") string s) {string [] Ss = S. Split ("~ "); Return S +" = "+ String. valueof (integer. parseint (ss [0])/integer. parseint (ss [1]);}

@ Post // set this service as a POST request service @ path ("add") Public String add (@ formparam ("TT") string S) {// TT is the namestring [] Ss = s of textfield of the form. split ("\ +"); Return S + "=" + String. valueof (integer. parseint (ss [0]) + integer. parseint (ss [1]);}

Zookeeper ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

The difference between rest and RPC.

  • Rest emphasizes that resources have unique Uris, while RPC is more powerful (verb) and is called by unified interfaces.
  • Rest regression was originally designed for HTTP. RPC only uses HTTP as the transmission protocol.
  • Rest is driven by hypertext; RPC is driven by methods.
  • Rest emphasizes the semantic visibility of HTTP Communication, which is embodied by the message header and standard HTTP method. RPC encapsulates the semantics in the HTTP message body.

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.