maven 创建 jersey 项目
如果没找到 jersey archetype, 下载 maven 的 archetype xml, 然后导入 archetypes
运行
右击 main.java -> Run As -> Java Application
如果 pom.xml 报错: Missing artifact com.sun.jersey:jersey-client:jar:${jersey-
version}, 则需要修改 jersey 版本号, 找到 pom.xml 中的
${jersey-version}
改成
1.19.1
运行成功,在 Console 栏位下会显示
支持返回 json 数据对象
在 pom.xml 添加
com.owlike
genson
0.99
在 java 文件中就可直接返回对象
@GET
@Path("hello")
@Produces(MediaType.APPLICATION_JSON)
public UserInfo hello(){
UserInfo user = new UserInfo();
user._id = "id";
user._name = "haha";
return user;
}
public class UserInfo{
String _id;
String _name;
public String getId(){
return this._id;
}
public void setId(String id){
this._id= id;
}
public String getName(){
return this._name;
}
public void setName(String name){
this._name = name;
}
}