25 Aralık 2017 Pazartesi

JAX-RS @MatrixParam Anotasyonu

constructor
URL içindeki key=value; şeklindeki parametrenin key ismini alır.

Örnek
Şöyle yaparız.
package com.domain.mypackage;
import javax.ws.rs.Consumes;
import javax.ws.rs.Produces;
import javax.ws.rs.GET;
import javax.ws.rs.MatrixParam;
import javax.ws.rs.Path;

// It's good practice to include a version number in the path so you can have
// multiple versions deployed at once. That way consumers don't need to upgrade
// right away if things are working for them.
@Path("calc/1.0")
public class CalculatorV1_0 {
  @GET
  @Consumes("text/plain")
  @Produces("text/plain")
  @Path("addTwoNumbers")
  public String add(@MatrixParam("firstNumber") int n1,
                    @MatrixParam("secondNumber") int n2) {
    return String.valueOf(n1 + n2);
  }
}
Çağırmak için şöyle yaparız.
http://localhost:8080/myContext/rest/calc/1.0/addTwoNumbers;firstNumber=2;secondNumber=3

Hiç yorum yok:

Yorum Gönder