繁体   English   中英

使用Json不能保存多个字符串

[英]Can't save more than one string using Json

我有个问题。 我一直在做一个简单的REST应用程序项目,现在我需要从http客户端发送JSON以创建实体。 当我发送一个属性时可以,但是当我写另一个属性时,它将第二个属性存储到同一字符串中。 看起来像这样(实际实体在列表“ toDos”中):

{
    "id": 1,
    "name": "block2",
    "archive": null,
    "toDos": [
        {
            "id": 2,
            "text": "{\n  \"text\" : \"my third todo\",\n  \"scaryness\" : 1,\n  \"hardness\" : 1\n}",
            "scaryness": null,
            "hardness": null,
            "ready": false,
            "createdOn": "2018-11-10T19:19:23.32207"
        }
    ]
}

我的POST请求:

POST http://localhost:8080/todos/create-todo/1
Content-Type: application/json

{
  "text" : "my third todo",
  "scaryness" : 1,
  "hardness" : 1
}

我在github上的项目: https : //github.com/FedosovMax/to-do-app

请帮助我找出如何将恐惧和硬度传送到正确的地方。 如果需要其他信息,请给我写信。

这是我在RestController中的错误,接下来是我的代码:

@PostMapping(value = "/create-todo/{blockId}")
@ResponseStatus(HttpStatus.CREATED)
public void createToDo(@PathVariable long blockId, @RequestBody String text, Scaryness scaryness, Hardness hardness){
    toDoService.saveToDo(text, scaryness, hardness, blockId);
}

因此将其另存为一个字符串。 现在我的RestController看起来像:

@PostMapping(value = "/create-todo/{blockId}")
@ResponseStatus(HttpStatus.CREATED)
public void createToDo(@PathVariable long blockId, @RequestBody ToDo toDo){
    toDoService.saveToDo(toDo, blockId);
}

它运作正常。

 {
    "id": 1,
    "name": "block2",
    "archive": null,
    "toDos": [
        {
            "id": 2,
            "text": "my third todo",
            "scaryness": 1,
            "hardness": 2,
            "ready": false,
            "createdOn": null
        }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM