spring - JsonParseException : Invalid JSON input. 位置 : 9. 字符: '.'

标签 spring mongodb spring-boot spring-mongodb mongorepository

我正在使用 MongoDB 和 Spring Boot 2.0.1.RELEASE。一切似乎都运行良好。我能够使用 MongoRepository 正确执行 CRUD 操作。当我像

这样使用 mongodb 查询时
@Query(value = "{address.city:?0}")
public List<Hotel> findByCity(String city);

@Query(value = "{address.country:?0}")
public List<Hotel> findByCountry(String country);

当我尝试使用 url localhost:8090/hotels/address/city/Rome 访问数据时,我收到以下响应错误

{
    "timestamp": "2018-05-04T04:51:43.549+0000",
    "status": 500,
    "error": "Internal Server Error",
    "message": "Invalid JSON input. Position: 9. Character: '.'.",
    "path": "/hotels/address/city/rome"
}

控制台登录如下:

Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.bson.json.JsonParseException: Invalid JSON input. Position: 9. Character: '.'.] with root cause

org.bson.json.JsonParseException: Invalid JSON input. Position: 9. Character: '.'.

我不知道为什么会收到 无效的 JSON 输入。位置:9. 字符:'.'. 当我执行GET请求时?

我哪里错了?

最佳答案

缺少引号; @Query(value = "{'address.country':?0}")

——尼尔·伦恩

这对我也有用。

关于spring - JsonParseException : Invalid JSON input. 位置 : 9. 字符: '.',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50167424/

相关文章:

java - @CrossOrigin 注释在 IntelliJ 中停止编译

java.lang.NoClassDefFoundError : org/springframework/expression/BeanResolver

java - 方面未在运行时执行(Spring 3、AspectJ)

javascript - Async/await 未按预期顺序执行

Mongodb:经过身份验证的用户太多

mongodb - Docker-compose和mongoDB:无法在任何兼容版本下启动WiredTiger?

java - 使用计时器进行 ScheduleAtFixedRate

Spring Boot : Can't infer the SQL type to use for an instance of java. time.LocalDateTime

java - 在 JSP 中按 "Delete"键从服务器端删除 ArrayList 条目

java - Spring Integration 和原型(prototype)范围之谜