文章目录
环境
系统: windows 11
工具: java, idea, git bash
Controller
接口常见有以下几种方式
其中: Tobj
调用脚本
我的是windows 系统,使用 git bash 窗口运行, 用 cmd 或者 power shell 会有问题
bash
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/x-www-form-urlencoded) 都可获取参数值
使用 (@RequestBody Map map, HttpServletRequest request) 和 (@RequestBody Tobj tobj, HttpServletRequest request) 结果一样,POST(application/json) Map,Tobj 可获取参数值, 但 HttpServletRequest 获取不到参数值
使用(Map map, HttpServletRequest request) 三种调用,Map都获取不到参数值, 但HttpServletRequest 可获取值
------------------ 但行好事莫问前程,你若盛开蝴蝶自来