【问题标题】:I just want to get "value" in json document. (in Spring-boot)我只想在 json 文档中获取“价值”。 (在春季启动)
【发布时间】:2021-11-22 20:41:45
【问题描述】:

我从邮递员那里把它作为正文发送:"userId":"11"。

 @PostMapping(value="/logout",consumes = "application/json")
  public void logout(@RequestBody String userId){
   ordersService.logout(userId);
}

然后 return 持有 userId= "{\r\n "userId":"11"\r\n}" ,但我只想获取值 11。我不想获取密钥。我该怎么做?

【问题讨论】:

    标签: json spring-boot key


    【解决方案1】:

    这应该做的工作

        @RequestMapping(
           path = "/logout",
           method = RequestMethod.PUT,
           produces = MediaType.APPLICATION_JSON_UTF8_VALUE
        )
        public void logout(@NotNull @RequestBody Long userId)
        {
            ordersService.logout(userId);
        }
    

    【讨论】:

    • @RequestMapping(method = RequestMethod.PUT, path = "/logout", consumes = "application/json") public void logout(@RequestBody Map payload) { ordersService.logout (payload.get("userId").toString()); }
    • 我收到如下错误:readStartDocument 只能在 CurrentBSONType 为 DOCUMENT 时调用,而 CurrentBSONType 为 STRING 时不能调用。
    • 我该怎么办?
    猜你喜欢
    • 2017-06-19
    • 1970-01-01
    • 2021-05-23
    • 1970-01-01
    • 1970-01-01
    • 2017-09-11
    • 2015-04-18
    • 2017-06-24
    • 2015-08-22
    相关资源
    最近更新 更多