【发布时间】:2016-04-04 06:21:30
【问题描述】:
我想使用 jersey 实现来制作 JAX-RS Web 服务。 我需要一个带有 3 个参数的 post 方法。
@POST
@Path ("/addData")
@produce(MediaType.Application_Json)
@Consume(MediaType.Application_JSON)
public User addData(int id, String name, String pass){
User u = new User();
u.setId(id);
u.setName(name);
u.setPass(pass);
return u;
}
@POST
@Path ("/addData")
@produce(MediaType.Application_Json)
@Consume(MediaType.Application_JSON)
public User addSingleData(int id){
User u = new User();
u.setId(id);
return u;
}
有一个单独的用户类如下:
public class User{
int id;
String name;
String pass;
// here are the getter setter and constructors
}
首先,我可以使用 jersey-media-moxy-2.3.jar 文件转换为 JSON(我不想使用 maven)。因为这个 jar 文件没有将内容转换为 json,但是如果我使用 maven,它可以在 post 方法中没有参数的情况下正常工作。
其次,如果我只使用一个参数,如何在方法体中获取参数。即第二种方法
三、post方法中如何使用多个参数。
第四,进一步我需要上传和下载图像。如何做到这一点。
最后,我无法获取 json 格式的数据。
注意:我正在为 android 手机制作网络服务。我将通过 andorid 使用它。
【问题讨论】:
-
为什么不想使用maven? maven 是一个构建工具和依赖管理软件... maven 和 JSON 无关。
-
我建议您阅读有关框架的信息,jersey.java.net/documentation/latest/user-guide.html 或只是阅读有关 Jax-rs 的信息,gitbook.com/book/dennis-xlc/restful-java-with-jax-rs-2-0-en/…
标签: java android json jersey jax-rs