环境

系统: windows 11
工具: java, idea, git bash


Controller

接口常见有以下几种方式

在这里插入图片描述
其中: Tobj
在这里插入图片描述

调用脚本

我的是windows 系统,使用 git bash 窗口运行, 用 cmd 或者 power shell 会有问题

curl -X GET 'http://localhost:18011/.../testTobjBody?dateVal=dateVal&mark=mark' 
  
curl -X POST 'http://localhost:18011/.../testTobjBody' -H 'Content-Type: application/x-www-form-urlencoded' --data 'mark=mark&dateVal=dateVal'
  
curl -X POST 'http://localhost:18011/.../testTobjBody' -H 'Content-Type: application/json' --data-raw '{"dateVal":"dateVal","mark":"mark"}'

运行结果

红框标注说明是有问题

testMap(String mark,String dateVal,HttpServletRequest request)

在这里插入图片描述

testMap(Map map,HttpServletRequest request)

在这里插入图片描述

testTobj(Tobj tobj, HttpServletRequest request)

在这里插入图片描述

testMapBody(@RequestBody Map map,HttpServletRequest request)

在这里插入图片描述

testTobjBody(@RequestBody Tobj tobj, HttpServletRequest request)

在这里插入图片描述


总结

使用 (String mark,String dateVal, HttpServletRequest request) 和 (Tobj tobj, HttpServletRequest request) 结果一样,GET 和 POST(application/xwwwformurlencoded) 都可获取参数

使用 (@RequestBody Map map, HttpServletRequest request) 和 (@RequestBody Tobj tobj, HttpServletRequest request) 结果一样,POST(application/json) Map,Tobj 可获取参数值, 但 HttpServletRequest 获取不到参数

使用(Map map, HttpServletRequest request) 三种调用,Map都获取不到参数值, 但HttpServletRequest 可获取值


—————— 但行好事莫问前程,你若盛开蝴蝶自来

原文地址:https://blog.csdn.net/ShayneLee8/article/details/134717074

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任

如若转载,请注明出处:http://www.7code.cn/show_46886.html

如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱suwngjj01@126.com进行投诉反馈,一经查实,立即删除

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注