使用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状 ...
随机推荐
- Learning How To Code Neural Networks
原文:https://medium.com/learning-new-stuff/how-to-learn-neural-networks-758b78f2736e#.ly5wpz44d This i ...
- JAVA 读取计算机中相关信息
java读取 计算机 cup号 读取版本号 显卡 .. . . ........ .. . . . package com.swt.common.util; import java.io.Buffer ...
- nyoj-659-推断三角形(大坑)
推断三角形 时间限制:1000 ms | 内存限制:65535 KB 难度: 描写叙述 小明非常喜欢研究三角形.如今,小明已经知道三角形的三条边.假设三条边能组成三角形,小明就会非常高兴,他就会得 ...
- android模拟器使用gps定位
在模拟器上获取GPS信息时,使用Location loc = LocationManager.getLastKnownLocation("gps");来获取location信息,但 ...
- 【读书笔记】Flickr 网站用户标签的质量控制对策
1.一些背景 标签技术重要意义 标签技术如今已经被广泛应用于包括网络书签.博客.播客.视频分享等在内的多种 Web2. 0 服务 Flickr简介 Flickr 是一集图片存放 交友 组群 邮件等功能 ...
- ubuntu server vsftpd 虚拟用户及目录
ubuntu server vsftpd 虚拟用户及目录 一:需求场景: 在ubuntu server上开设一个虚拟网站,在网站目录建立一个ftp目录,允许用户通过ftp上传网站文件到网站目录: 同时 ...
- 触发器三(行级DML触发器)(学习笔记)
行级DML触发器 每当一条记录出现更新操作时进行触发操作定义时要定义FOR EACH ROW 使用":old.字段"和":new.字段"标识符 No. 触发语句 ...
- faster rcnn测试VOC2012的问题
Traceback (most recent call last): File "./tools/test_net.py", line 90, in test_net(net, i ...
- inode备忘
文件名 -> inode -> device block 转自:http://www.cnblogs.com/itech/archive/2012/05/15/2502284.html 一 ...
- java数组转json
public String toJsonObject(String[] list) { String json="["; for (int i=0;i<list.length ...