| # localhost:8080/car/1/owner/aaa |
| |
| @GetMapping("/car/{id}/owner/{username}") |
| public Map<String,Object> getCar(@PathVariable("id") Integer id, |
| @PathVariable("username") String name, |
| @PathVariable Map<String,String> pv |
| ){ |
| Map<String,Object> map = new HashMap<>(); |
| map.put("id",id); |
| map.put("name",name); |
| map.put("pv",pv); |
| return map; |
| } |
| # localhost:8080/car |
| |
| @GetMapping("/car") |
| public Map<String,Object> getCar(@RequestHeader("User-Agent") String userAgent, |
| @RequestHeader Map<String,String> header){ |
| Map<String,Object> map = new HashMap<>(); |
| map.put("userAgent",userAgent); |
| map.put("headers",header); |
| return map; |
| } |
| # localhost:8080/car?age=18&inters=aaa&inters=bbb |
| |
| @GetMapping("/car") |
| public Map<String,Object> getCar(@RequestParam("age") Integer age, |
| @RequestParam("inters") List<String> inters, |
| @RequestParam Map<String,String> params |
| ){ |
| Map<String,Object> map = new HashMap<>(); |
| map.put("age",age); |
| map.put("inters",inters); |
| map.put("params",params); |
| return map; |
| } |
| # localhost:8080/car |
| |
| @GetMapping("/car") |
| public Map<String,Object> getCar(@CookieValue("_ga") String _ga, |
| @CookieValue("_ga") Cookie cookie){ |
| Map<String,Object> map = new HashMap<>(); |
| map.put("_ga",_ga); |
| System.out.println(cookie.getName()+"===>"+cookie.getValue()); |
| return map; |
| } |
| <form action="/save" method="post"> |
| 测试@RequestBody获取数据 <br/> |
| 用户名:<input name="userName"/> <br> |
| 邮箱:<input name="email"/> |
| <input type="submit" value="提交"/> |
| </form> |
| |
| @PostMapping("/save") |
| public Map postMethod(@RequestBody String content){ |
| Map<String,Object> map = new HashMap<>(); |
| map.put("content",content); |
| return map; |
| } |
| # localhost:8080/goto |
| |
| @Controller |
| public class RequestController { |
| |
| |
| @GetMapping("/goto") |
| public String goToPage(HttpServletRequest request){ |
| |
| request.setAttribute("msg","成功了..."); |
| request.setAttribute("code",200); |
| return "forward:/success"; |
| } |
| |
| @ResponseBody |
| @GetMapping("/success") |
| public Map success(@RequestAttribute(value = "msg",required = false) String msg, |
| @RequestAttribute(value = "code",required = false)Integer code, |
| HttpServletRequest request){ |
| Object msg1 = request.getAttribute("msg"); |
| Map<String,Object> map = new HashMap<>(); |
| map.put("reqMethod_msg",msg1); |
| map.put("annotation_msg",msg); |
| return map; |
| } |
| |
| } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 字符编码:从基础到乱码解决
· 提示词工程——AI应用必不可少的技术