根据RestClient
Class的create()方法
public static <T, R> T create(final Class<T> remoteService, final RemoteCallback<R> callback, Integer... successCodes) {
return create(remoteService, null, callback, null, successCodes);
}
在您提供的示例中;当使用 create() 方法 Errai 得到 CustomerService 类时remoteService
,经过多次操作;
Errai 使用他们使用Java Reflection API的errai-codegen库来解析和实现这个 CustomerService 接口。
简单解析时;
让我使用您提供的示例来解释这些规则。
Customer customer = new Customer("new name", "new last name", "new postal code");
RestClient.create(CustomerService.class, callback).updateCustomer(240193, customer);
Errai 将创建像
example.com/cusomers/240193
因为@PathParam("id") 注释规则正在向url 添加参数,并且根据Errai 的entityParameter 规则customer
将在使用PUT 发送数据时进行编组。
@PUT
@Path("/{id}")
@Consumes("application/json")
@Produces("application/json")
public Customer updateCustomer(@PathParam("id") long id, Customer customer); //- See more at: http://errai-blog.blogspot.com.tr/2011/10/jax-rs-in-gwt-with-errai.html#sthash.2GTQtIg8.dpuf
如果您在此处查看setEntityParameter 方法中存在异常,请再注意一点;
每个方法只允许一个非注释实体参数:
这意味着您不能在您在 Errai 中发送的 Class 中定义具有超过 1 个非注释参数的方法。