【问题标题】:How to send JSON @RequestBody if using MAP in java?如果在 java 中使用 MAP,如何发送 JSON @RequestBody?
【发布时间】:2019-11-29 06:50:43
【问题描述】:

**如果我作为 Map 传递,我如何将控制器中的 Json 数据作为 @RequestBody 传递。我想手动传递值。我在下面提到了我的源代码。 . . **

    @RestController
public class CustomerController {
    private static final Logger logger = LoggerFactory.getLogger(CustomerController.class);

    @Autowired
    private CustomerService customerService;

    @PostMapping("/customer/save")
    public Result save(@RequestBody Map<String, Object> custData){

        logger.info(" :::::::::::::::::::: CoreCustomer Create Method ::::::::::::::::::::::");
        Result result = customerService.save(custData);
        return result;

    }
    @GetMapping("/customer")
    public Result getAll(){
        logger.info("::::::::::::::::::::: GetAll Method in Customer ::::::::::::::::::");
        Result result = customerService.getAll();
        return result;

    }

我的 Swagger UI 在下面:enter image description here

在上图中,我无法获得内置输入字段。有人可以帮我解决这个问题。

【问题讨论】:

  • 您的代码看起来正确。如果您使用@RequestBody 注释参数,则JSON 将放在Map 中。您究竟是如何测试 REST 调用的?你可以试试 Postman 或 cURL 吗?

标签: java spring-boot swagger-ui swagger-2.0


【解决方案1】:

使用 Swagger 不需要在 Controller 方法中使用 @ApiImplicitParam 注解?

【讨论】:

    猜你喜欢
    • 2019-06-04
    • 2015-08-17
    • 1970-01-01
    • 2015-11-09
    • 1970-01-01
    • 2019-03-31
    • 2015-11-30
    • 1970-01-01
    • 2013-10-17
    相关资源
    最近更新 更多