使用DELETE方式进行交互

说明:ResponseData为自定义返回体{String code, String msg, List<?> data}

PollutionData 为一个entity  属性部分包含{String id, String name}

CodeEnum、MsgEnum为自定义枚举类,定义了一些常量

两种方式皆测试过

环境:win7+idea2018.2+jdk10.0.2+springboot  前端编辑工具为hbuilder

两种方式:

1、

//方法一 使用POST+ _method:"DELETE" + filter(springboot不需要我们配置)
//这里的传输对象为json对象,后台直接接受
var r=confirm("方法一:确认删除该条数据?");
if(r){
//var data = {_method:"DELETE", id:"456456",name:"征集"};
var data = {_method:"DELETE"};//_method:"DELETE"必须,其他属性看你需求
$.ajax({
url:"http://192.168.2.116:8080/pollution/delete/1786vdsds863",
type:"POST",
data:data,
dataType:"json",
success:function(result){
alert(result.msg);
} });
}
@DeleteMapping("/pollution/delete/{id}")
public ResponseData deletePollutionById(@PathVariable("id")String id, @RequestBody PollutionData data){
System.out.println(id);
System.out.println(data);
return new ResponseData(CodeEnum.SUCCESS.getCode(),MsgEnum.SUCCESS.getMsg(),null);
}

2、

//方法二 使用DELETE请求
//这是的传输对象为json字符串 后台使用@RequestBody注解解析该字符串并将字符串映射到对应实体上
var r=confirm("方法二:确认删除该条数据?");
if(r){
var id = "123133";
var jsonstr = { id: id,
name: "12345"};
console.log(jsonstr);
$.ajax({
url:"http://192.168.2.116:8080/pollution/delete/" + id,
type:"DELETE",
contentType:"application/json",//设置请求参数类型为json字符串
data:JSON.stringify(jsonstr),//将json对象转换成json字符串发送
dataType:"json",
success:function(result){
alert(result.msg);
} });
} /**如果不需要传递参数,可以不写下面的几项
* contentType:"application/json",//设置请求参数类型为json字符串
data:JSON.stringify(jsonstr),//将json对象转换成json字符串发送
dataType:"json",
*/
@DeleteMapping("/pollution/delete/{id}")
public ResponseData deletePollutionById(@PathVariable("id")String id, @RequestBody PollutionData data){
System.out.println(id);
System.out.println(data);
return new ResponseData(CodeEnum.SUCCESS.getCode(),MsgEnum.SUCCESS.getMsg(),null);
}

参考:https://blog.csdn.net/liuyuanjiang109/article/details/78972644

Spring Boot @DeleteMapping的更多相关文章

  1. Spring Boot(spring mvc升级版)

    周末挤出了一些时间,学了点东西,总结了一下,可能还有自己理解不到位的地方,希望大家一起交流学习,好东西要大家一起分享嘛~.时间有点紧张,所以样式没有来及做很好的调整,大家就凑活着看吧. Spring ...

  2. Spring Boot 注解的使用

    Spring Boot 优于Spring mvc ,SSM,SSH 的一个亮点就是他使用了好多的注解. 1. @Autowired 这个注解的作用是将其他的类,接口引入,类似于之前的类的初始化等,用这 ...

  3. Spring Boot快速入门(二):http请求

    原文地址:https://lierabbit.cn/articles/4 一.准备 postman:一个接口测试工具 创建一个新工程 选择web 不会的请看Spring Boot快速入门(一):Hel ...

  4. Spring Boot with Spring-Data-JPA学习案例

    0x01 什么是Spring Boot? Spring Boot是用来简化Spring应用初始搭建以及开发过程的全新框架,被认为是Spring MVC的"接班人",和微服务紧密联系 ...

  5. Spring Boot系列(一) Spring Boot准备知识

    本文是学习 Spring Boot 的一些准备知识. Spring Web MVC Spring Web MVC 的两个Context 如下图所示, 基于 Servlet 的 Spring Web M ...

  6. Spring Boot 2.x (十):构建优雅的RESTful接口

    RESTful 相信在座的各位对于RESTful都是略有耳闻,那么RESTful到底是什么呢? REST(Representational State Transfer)表述性状态转移是一组架构约束条 ...

  7. 使用Spring Boot Actuator将指标导出到InfluxDB和Prometheus

    使用Spring Boot Actuator将指标导出到InfluxDB和Prometheus   Spring Boot Actuator是Spring Boot 2发布后修改最多的项目之一.它经过 ...

  8. 【转】Spring Boot 构建应用——快速构建 Spring Boot 应用

    Spring Boot 简化了 Spring 应用开发,不需要配置就能运行 Spring 应用,Spring Boot 的自动配置是通过 Spring 4.x 的条件注解 @Conditional 来 ...

  9. 前端页面调用Spring boot接口发生的跨域问题

    最近要重构一个基于spring boot的后端API服务,需要再本地测试.在本地测试时,运行在本地的前端页面发送一个ajax请求访问后端API,然后浏览器报错blocked CORS policy. ...

随机推荐

  1. poj_3250 单调栈

    题目大意 N头牛排成一列,每头牛A都能看到它前面比它矮的牛i,若前面有一个比他高的牛X,则X之前的牛j,A都无法看到.给出N头牛的高度,求出这N头牛可以看到牛的数目的总数. 题目分析 画图之后,可以很 ...

  2. C/C++ 智能指针简单剖析

    导读 最近在补看<C++ Primer Plus>第六版,这的确是本好书,其中关于智能指针的章节解析的非常清晰,一解我以前的多处困惑.C++面试过程中,很多面试官都喜欢问智能指针相关的问题 ...

  3. chkcofnig-minimal-script

    author :headsen chen date: 2018-06-04  12:02:27  #!/bin/bash for i in `chkconfig --list |awk '{print ...

  4. ERROR in [copy-webpack-plugin] unable to locate "D:/xxx/xxx/xxx"

    vue打包的时候npm run build报错 ERROR in [copy-webpack-plugin] unable to locate "D:/xxx/xxx/xxx" 这 ...

  5. QQ空间发表日志的图片上传功能实现

    w间接促使了用户注意图片的顺序,进一步优化的方向的是手指触动或鼠标点击来同时进行图片的增删和调序,避免精确的数字输入. 有效code <form action="wcon/wact&q ...

  6. php composer,update-ca-trust

    安装 ComposerComposer 需要 PHP 5.3.2+ 才能运行. $ curl -sS https://getcomposer.org/installer | php这个命令会将 com ...

  7. Storm-源码分析-LocalState (backtype.storm.utils)

    LocalState A simple, durable, atomic K/V database. *Very inefficient*, should only be used for occas ...

  8. python自然语言处理——学习笔记:Chapter3纠错

    2017-12-06更新:很多代码执行结果与书中不一致,是因为python的版本不一致.如果发现有问题,可以参考英文版: http://www.nltk.org/book/ 第三章,P87有一段处理h ...

  9. qemu进程页表和EPT的同步问题

    背景分析: 在之前分析EPT violation的时候,没有太注意qemu进程页表和EPT的关系,从虚拟机运行过程分析,虚拟机访存使用自身页表和EPT完成地址转换,没有用到qemu进程页表,所以也就想 ...

  10. 【我的Android进阶之旅】Jenkins挂载slave节点,增强分布式编译的效率

    由于公司的Jenkins任务越来越多,而且所有的Android Jenkins任务都在同一台服务器上进行编译,而且该服务器配置Jenkins任务最多3个任务同时运行,所以有时候大家一起编译的时候,只能 ...