package de.vogella.jersey.todo.resources;
import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.Consumes;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import de.vogella.jersey.todo.dao.TodoDao;
import de.vogella.jersey.todo.model.Todo;
//Will map the resource to the URL todos
@Path("/todos")
public class TodosResource {
// Allows to insert contextual objects into the class,
// e.g. ServletContext, Request, Response, UriInfo
@Context
UriInfo uriInfo;
@Context
Request request;
// Return the list of todos to the user in the browser
@GET
@Produces(MediaType.TEXT_XML)
public List<Todo> getTodosBrowser() {
List<Todo> todos = new ArrayList<Todo>();
todos.addAll( TodoDao.instance.getModel().values() );
return todos;
}
// Return the list of todos for applications
@GET
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public List<Todo> getTodos() {
List<Todo> todos = new ArrayList<Todo>();
todos.addAll( TodoDao.instance.getModel().values() );
return todos;
}
// retuns the number of todos
// Use http://localhost:8080/de.vogella.jersey.todo/rest/todos/count
// to get the total number of records
@GET
@Path("count")
@Produces(MediaType.TEXT_PLAIN)
public String getCount() {
int count = TodoDao.instance.getModel().size();
return String.valueOf(count);
}
@POST
@Produces(MediaType.TEXT_HTML)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public void newTodo(
@FormParam("id") String id,
@FormParam("summary") String summary,
@FormParam("description") String description,
@Context HttpServletResponse servletResponse
) throws IOException {
Todo todo = new Todo(id,summary);
if (description!=null){
todo.setDescription(description);
}
TodoDao.instance.getModel().put(id, todo);
URI uri = uriInfo.getAbsolutePathBuilder().path(id).build();
Response.created(uri).build();
servletResponse.sendRedirect("../create_todo.html");
}
// Defines that the next path parameter after todos is
// treated as a parameter and passed to the TodoResources
// Allows to type http://localhost:8080/de.vogella.jersey.todo/rest/todos/1
// 1 will be treaded as parameter todo and passed to TodoResource
@Path("{todo}")
public TodoResource getTodo(
@PathParam("todo") String id) {
return new TodoResource(uriInfo, request, id);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
JerseyTest.rar (40个子文件)
JerseyTest
.project 1KB
.settings
.jsdtscope 503B
org.eclipse.wst.common.component 460B
org.eclipse.jdt.core.prefs 395B
org.eclipse.wst.common.project.facet.core.xml 345B
org.eclipse.wst.jsdt.ui.superType.container 49B
org.eclipse.wst.jsdt.ui.superType.name 6B
src
de
vogella
jersey
todo
dao
TodoDao.java 659B
resources
TodosResource.java 3KB
TodoResource.java 2KB
model
Todo.java 714B
client
Tester.java 2KB
first
Hello.java 1KB
jaxb
client
Test.java 1KB
jaxb
TodoResource.java 813B
model
Todo.java 572B
client
Test.java 1KB
build
classes
de
vogella
jersey
todo
dao
TodoDao.class 2KB
resources
TodoResource.class 3KB
TodosResource.class 4KB
model
Todo.class 1KB
client
Tester.class 3KB
first
jaxb
client
Test.class 2KB
Hello.class 928B
jaxb
TodoResource.class 982B
model
Todo.class 842B
client
Test.class 2KB
WebContent
create_todo.html 438B
WEB-INF
create_todo.html 438B
web.xml 935B
lib
jsr311-api-1.1.1.jar 45KB
jersey-server-1.1.5.1.jar 567KB
jersey-client-1.1.5.1.jar 88KB
jersey-core-1.1.5.1.jar 336KB
asm-3.1.jar 42KB
jettison-1.1.jar 66KB
jackson-core-asl-1.1.1.jar 102KB
jersey-json-1.1.5.1.jar 128KB
META-INF
MANIFEST.MF 39B
.classpath 834B
共 40 条
- 1
人生如代码
- 粉丝: 33
- 资源: 91
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于yolov5识别算法实现的DNF自动脚本源码.zip
- 基于Python实现的自动化办公项目.zip
- 基于python实现的基于PyQt5和爬虫的小说阅读系统.zip
- 机械设计整经机上纱自动化sw20非常好的设计图纸100%好用.zip
- Screenshot_20240427_031602.jpg
- 网页PDF_2024年04月26日 23-46-14_QQ浏览器网页保存_QQ浏览器转格式(6).docx
- 直接插入排序,冒泡排序,直接选择排序.zip
- 在排序2的基础上,再次对快排进行优化,其次增加快排非递归,归并排序,归并排序非递归版.zip
- 实现了7种排序算法.三种复杂度排序.三种nlogn复杂度排序(堆排序,归并排序,快速排序)一种线性复杂度的排序.zip
- 冒泡排序 直接选择排序 直接插入排序 随机快速排序 归并排序 堆排序.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页