使用Spring boot开发RestFul 风格项目PUT/DELETE方法不起作用
在使用Spring boot 开发restful 风格的项目,put、delete方法不起作用,解决办法。
实体类Student
@Data
public class Student { private String id;
private String name;
private int age;
private String sex; @Override
public String toString() {
return ToStringBuilder.reflectionToString(this);
}
}
controller
@RestController
public class GreetingController { @RequestMapping(value = "/demo1/student", method = RequestMethod.POST)
public void addStudent(Student student) {
System.out.println(student);
System.out.println("添加成功");
} @RequestMapping(value = "/demo1/student", method = RequestMethod.PUT)
public void updateStudent(Student student) {
System.out.println(student);
System.out.println("更新成功");
} @RequestMapping(value = "/demo1/student", method = RequestMethod.GET)
public Student getAtudentById(String id) {
System.out.println("接收到的的参数" + id);
Stuent s = new Student();
s.setId("");
s.setName("google");
s.setAge();
return s;
} @RequestMapping(value = "/demo1/student", method = RequestMethod.DELETE)
public void delStudent(Student student) {
System.out.println(student);
System.out.println("删除成功");
} }
使用put 更新接口调用,参数无法传递过去。解决办法是在需要组装的参数前面添加注解 @RequestBody
修改如下:
@RequestMapping(value = "/demo1/student", method = RequestMethod.PUT)
public void updateStudent(@RequestBody Student student) {
System.out.println(student);
System.out.println("更新成功");
}
即可成功调用
delete 接口修改方法相同
使用Spring boot开发RestFul 风格项目PUT/DELETE方法不起作用的更多相关文章
- Spring Boot构建 RESTful 风格应用
Spring Boot构建 RESTful 风格应用 1.Spring Boot构建 RESTful 风格应用 1.1 实战 1.1.1 创建工程 1.1.2 构建实体类 1.1.4 查询定制 1.1 ...
- Spring Boot开发RESTful接⼝服务及单元测试
Spring Boot开发RESTful接⼝服务及单元测试 常用注解解释说明: @Controller :修饰class,⽤来创建处理http请求的对象 @RestController :Spring ...
- Spring Boot2 系列教程(三十一)Spring Boot 构建 RESTful 风格应用
RESTful ,到现在相信已经没人不知道这个东西了吧!关于 RESTful 的概念,我这里就不做过多介绍了,传统的 Struts 对 RESTful 支持不够友好 ,但是 SpringMVC 对于 ...
- Spring Boot 之restful风格
步骤一:restful风格是什么? 我们知道在做web开发的过程中,method常用的值是get和post.可事实上,method值还可以是put和delete等等其他值. 既然method值如此丰富 ...
- Spring Boot (2) Restful风格接口
Rest接口 动态页面jsp早已过时,现在流行的是vuejs.angularjs.react等前端框架 调用 rest接口(json格式),如果是单台服务器,用动态还是静态页面可能没什么大区别,如果服 ...
- 使用Spring Boot开发Web项目(二)之添加HTTPS支持
上篇博客使用Spring Boot开发Web项目我们简单介绍了使用如何使用Spring Boot创建一个使用了Thymeleaf模板引擎的Web项目,当然这还远远不够.今天我们再来看看如何给我们的We ...
- spring boot 开发环境搭建(Eclipse)
Spring Boot 集成教程 Spring Boot 介绍 Spring Boot 开发环境搭建(Eclipse) Spring Boot Hello World (restful接口)例子 sp ...
- 八个开源的 Spring Boot 前后端分离项目,一定要收藏!
八个开源的 Spring Boot 前后端分离项目 最近前后端分离已经在慢慢走进各公司的技术栈,不少公司都已经切换到这个技术栈上面了.即使贵司目前没有切换到这个技术栈上面,我们也非常建议大家学习一下前 ...
- 使用Spring MVC开发RESTful API
第3章 使用Spring MVC开发RESTful API Restful简介 第一印象 左侧是传统写法,右侧是RESTful写法 用url描述资源,而不是行为 用http方法描述行为,使用http状 ...
随机推荐
- Discuz 学习笔记一 :getgdc 和get_client_ip
Getgdc函数 discuz有一个超级变量的自定义函数: function getgpc($k, $type='GP') { $type = strtoupper($type); ...
- [Backbone] Verying Views
Below we have our AppointmentsView instance rendering and then taking the rendered HTML and insertin ...
- 【Android 百度地图实战】2.几种地图图层的显示
具体代码官网API已提供,地址在这. 效果图如下: 主要代码: // 创建选项菜单 @Override public boolean onCreateOptionsMenu(Menu menu) { ...
- DevExpress学习02——DevExpress 14.1的汉化
汉化资源: 汉化补丁:dxKB_A421_DXperience_v14.1_(2014-06-09):http://www.t00y.com/file/86576990 汉化工具:DXperience ...
- 消息队列的使用场景(转载c)
作者:ScienJus链接:https://www.zhihu.com/question/34243607/answer/58314162来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业 ...
- C# 编程实现串口通信
http://blog.sina.com.cn/s/blog_6c67dab30101p3vn.html ----------------------------------------------- ...
- 微信小程序-开发入门(一)
微信小程序已经火了一段时间了,之前一直也在关注,就这半年的发展来看,相对原生APP大部分公司还是不愿意将主营业务放到微信平台上,以免受制于腾讯,不过就小程序的应用场景(用完即走和二维码分发等)还是很值 ...
- cydia源
http://apt.91.com http://apt.178.com Flex 2的官方安装源是 getdelta.co
- JavaWeb get请求乱码处理
乱码终极解决方案 Author:Marydon 一.安装好eclipse/myeclipse后,先将开发环境改成UTF-8; 更改工作空间编码方式 window-->preferences- ...
- python之模块csv之CSV文件一次写入多行
# -*- coding: utf-8 -*- #python 27 #xiaodeng #CSV文件一次写入多行 import csv #csv文件,是一种常用的文本格式,用以存储表格数据,很多程序 ...