环境

系统: 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 可获取值


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

发表回复

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