标签:传参 PutMapping springmvc HttpStatus ids typeList ajax 注解 DeleteMapping
首先我们要知道@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);
}
)
这篇内容如果对您有所帮助,记得帮我点赞鼓励下啦,谢谢!~
标签:传参,PutMapping,springmvc,HttpStatus,ids,typeList,ajax,注解,DeleteMapping 来源: https://blog.csdn.net/qq_54223170/article/details/116499814
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。