POST,PUT和DELETE Http请求

In this post we will understand how to implement POST (Create), PUT (Update) and DELETE (Remove) operations in the REST web service.

在本文中,我们将了解如何在REST Web服务中实现POST (创建), PUT (更新)和DELETE (删除)操作。

@POST
@Produces(MediaType.APPLICATION_XML)
public String addStudent(Student student)
{
	
    return studentService.addStudent(student);

}

@PUT
@Produces(MediaType.APPLICATION_XML)
@Path("/{rollno}")
public Student updateStudent(@PathParam("rollno")int rollno ,Student student)
{
	student.setRollNo(rollno);
	return studentService.update(student);
}

@DELETE
@Produces(MediaType.APPLICATION_XML)
@Path("/{rollno}")
public String removeStudent(@PathParam("rollno") int rollno)
{
return studentService.delete(rollno);

}

The following methods are added to the Students class and annotated with the @POST, @PUT and @DELETE annotations. The important point to note here is that the @POST method is implemented at the {Root-Path}/Students/.

下面的这些方法加入到Students类,并与注释@POST@PUT@DELETE注解。 这里要注意的重要一点是@POST方法是在{Root-Path} / Students /上实现的。

Therefore, it is the responsibility of the application to generate the roll no and create a new record. The rollno will not be sent in the POST request.

因此,应用程序有责任生成滚动号并创建新记录。 rollno将不会在POST请求中发送。

One more important point to note is that, the browser can only send a GET request. So to send the POST, PUT and DELETE request we need to install a REST client. We will install the rest client in the next lesson and send the respective requests from the REST client.

还有一点需要注意的是,浏览器只能发送GET请求。 因此,要发送POST,PUT和DELETE请求,我们需要安装REST客户端。 我们将在下一课中安装其余客户端,并发送来自REST客户端的相应请求。

翻译自: https://www.studytonight.com/rest-web-service/post-put-and-delete

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值