• @RequestBody的理解


    What you are asking for is fundamentally wrong. POST requests sends data in a body payload, which is mapped via @RequestBody@RequestParam is used to map data through the URL parameters such as /url?start=foo. What you are trying to do is use @RequestParam to do the job of @RequestBody.

    Alternative solutions for REST controllers

    • Introduce a DTO class. It is the most preferred and clean method.
    • If you really want to avoid creating a class, you can use @RequestBody Map<String, String> payload. Be sure to include 'Content-Type': 'application/json' in your request header.
    • If you really want to use @RequestParam, use a GET request instead and send your data via URL parameters.

    Alternative solutions for MVC controllers

    • Introduce a DTO class and use it with annotation @ModelAttribute.
    • If you transform the form data into JSON, you can use @RequestBody Map<String, String> payload. To do this, please see this answer.

    It is not possible to map form data encoded data directly to a Map<String, String>.

  • 相关阅读:
    23.2 编写笨的程序
    python面向对象
    面向对象封装
    python新式类删改查
    os模块sys模块 进度条实例
    选课系统练习程序
    python类相关
    xml模块
    json&pickle模块shelve模块
    Python写的ATM程序
  • 原文地址:https://www.cnblogs.com/sidesky/p/15185929.html
Copyright © 2020-2023  润新知