首先我们要知道@PutMapping,@DeleteMapping的作用:
@PutMapping:“对应修改操作,表明是一个修改URL映射”。
@DeleteMapping:“对应删除,表明是一个删除URL映射”
使用ajax的put提交方式
$.ajax({
url:"http://127.0.0.1/typeList",
type:"PUT",
data:data,
success:function (result) {
}
});
使用ajax的delete提交方式
var ids = [1,2,3];
$.ajax({
url:"http://127.0.0.1/typeList/"+ids,
type:"DELETE",
success:function (result) {
}
});
如果是使用springmvc需要在web.xml中加入过滤器
<!-- 使用Rest风格的URI,将页面普通的post请求转为指定的delete或者put请求 -->
-<filter>
<filter-name>HiddenHttpMethodFilter</filter-name>
<filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
</filter>
-<filter-mapping>
<filter-name>HiddenHttpMethodFilter</filter-name>
<servlet-name>springmvc</servlet-name>
</filter-mapping>
-<filter>
<filter-name>HttpPutFormContentFilter</filter-name>
<filter-class>org.springframework.web.filter.HttpPutFormContentFilter</filter-class>
</filter>
-<filter-mapping>
<filter-name>HttpPutFormContentFilter</filter-name>
<servlet-name>springmvc</servlet-name>
</filter-mapping>
@PutMapping注解和@DeleteMapping的使用
@RestController
@RequestMapping("typeList")
//解决跨域问题
//@CrossOrigin("http://localhost:63342")
public class TypeListController {
@Autowired
private TypeListService typeListService;
@PutMapping
public ResponseEntity<Void> updateTypeList(AoaTypeList typeList){
int count = typeListService.updateTypeList(typeList);
return new ResponseEntity<> ((count>0)?HttpStatus.OK:HttpStatus.BAD_REQUEST);
}
@DeleteMapping("{ids}")
public ResponseEntity<Void> delByTypeId(@PathVariable("ids") Long[] ids){
int count = typeListService.deleteTypeList(ids);
return new ResponseEntity<>((count>0)?HttpStatus.OK:HttpStatus.BAD_REQUEST);
}
)
这篇内容如果对您有所帮助,记得帮我点赞鼓励下啦,谢谢!~
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。