Micronaut JSON帖子去除了引号 [英] Micronaut JSON post strip the Quotes

查看:144
本文介绍了Micronaut JSON帖子去除了引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Micronaut Controller中,使用JSON对象解析发布请求.我希望它不包括引号,但在数据库插入中将引号引起来.

In Micronaut Controller parsing the post request using JSON object. I expect it to not include quotes, but it quotes in the database insert.

像这样发布:

curl -X POST --header "Content-Type: application/json" -d '{"bookid":3,"name":"C++"}'  http://localhost:8880/book/save

保存如下:

String bookid=JSON?.bookid
  String name=JSON?.name
def b =bookService.save(bookid,name

在数据库中存储如下:

+--------+-------+
| bookid | name  |
+--------+-------+
| 3      | "C++" |
+--------+-------+

我希望书名只是C++

谢谢 SR

推荐答案

您没有提供有关项目的足够信息以了解发生了什么,但是该项目位于

You haven't provided enough information about your project to know what is going on but the project at https://github.com/jeffbrown/sfgroupsjsonbinding/tree/master demonstrates how the built in binding stuff works. See the README.md file there.

https://github.com. /jeffbrown/sfgroupsjsonbinding/blob/3ff4e8b39ba5fda9956ebfc67cd0b9e5d940b8f2/src/main/groovy/sfgroupsjsonbinding/BookController.groovy

package sfgroupsjsonbinding

import io.micronaut.http.annotation.Controller
import io.micronaut.http.annotation.Get
import io.micronaut.http.annotation.Post

@Controller('/book')
class BookController {

    private PersonService personService

    BookController(PersonService personService) {
        this.personService = personService
    }

    @Get('/')
    List<Person> list() {
        personService.list()
    }

    @Post('/')
    Person save(Person person) {
        personService.save person
    }

    @Get('/{id}')
    Person get(long id) {
        personService.get id
    }
}

与应用交互

 $ curl -H "Content-Type: application/json" -d '{"name":"Jeff"}' http://localhost:8080/book
{"name":"Jeff","id":1}
 $ 
 $ curl -H "Content-Type: application/json" -d '{"name":"Jake"}' http://localhost:8080/book
{"name":"Jake","id":2}
 $ 
 $ curl -H "Content-Type: application/json" -d '{"name":"Zack"}' http://localhost:8080/book
{"name":"Zack","id":3}
 $ 
 $ curl http://localhost:8080/book
[{"name":"Jeff","id":1},{"name":"Jake","id":2},{"name":"Zack","id":3}]
 $ 
 $ curl http://localhost:8080/book/1
{"name":"Jeff","id":1}
 $ 
 $ curl http://localhost:8080/book/2
{"name":"Jake","id":2}
 $ 
 $ curl http://localhost:8080/book/3
{"name":"Zack","id":3}
 $ 

这篇关于Micronaut JSON帖子去除了引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆