Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaSpring5Get和FindByidMongo MongoOneRorResume_Java_Spring_Mongodb_Spring Boot_Spring Webflux - Fatal编程技术网

JavaSpring5Get和FindByidMongo MongoOneRorResume

JavaSpring5Get和FindByidMongo MongoOneRorResume,java,spring,mongodb,spring-boot,spring-webflux,Java,Spring,Mongodb,Spring Boot,Spring Webflux,这里是Spring新手,试图通过findById(id,Object)在mongo db中进行GEThttp查询 但它似乎不起作用。我可以POST和PUT但是当通过ID调用查询时,我会得到这个错误mononerrorResume 我正在使用嵌入式MongoDB 控制器 公共类ContentController{ 公共静态最终字符串内容_V_1_CONT=“/contents/v1/CONT/”; 私人最终内容服务; @自动连线 公共ContentController(ContentServi

这里是Spring新手,试图通过findById(id,Object)在mongo db中进行GEThttp查询

但它似乎不起作用。我可以POSTPUT但是当通过ID调用查询时,我会得到这个错误mononerrorResume

  • 我正在使用嵌入式MongoDB
控制器

公共类ContentController{
公共静态最终字符串内容_V_1_CONT=“/contents/v1/CONT/”;
私人最终内容服务;
@自动连线
公共ContentController(ContentService ContentService){
this.contentService=contentService;
}
@GetMapping(path=“{id}”,生成=
MediaType.APPLICATION_JSON_UTF8_值)
公共Mono getContent(@PathVariable字符串id){
System.out.println(contentService.getContent(id));//
单身汉简历
返回contentService.getContent(id);
}
@后映射(路径=),生成=
MediaType.APPLICATION_JSON_UTF8_值,消耗=
MediaType.APPLICATION_JSON_UTF8_值)
公共Mono createContent(@RequestBody Mono content){
返回contentService.createContent(content);
}
服务实施

public final ReactiveMongoOperations ReactiveMongoOperations;
@自动连线
public ContentServiceImplementation(反应性MongoOperations反应性MongoOperations){
this.reactiveMongoOperations=reactiveMongoOperations;
}
@凌驾
公共内容(字符串id){
返回reactivemongoperations.findById(id,Content.class);
}
@凌驾
公共Mono createContent(Mono contentMono){
返回reactivemongoperations.save(contentMono);
}
数据配置不知道这是否有用

@Bean
公共反应mongoDatabaseFactory mongoDatabaseFactory(MongoClient MongoClient){
返回新的SimpleReactiveMongoDatabaseFactory(mongoClient,数据库名称);
}
@豆子
公共反应MongoOperations反应MongoTemplate(反应mongoDatabaseFactory mongoDatabaseFactory){
返回新的ReactiveMongoTemplate(mongoDatabaseFactory);
}

Lmk如果我遗漏了一些关键信息

您的问题可能来自控制器,您可以这样声明您的路径:

@GetMapping(path = "{id}", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
因此,除非在控制器类映射的末尾有一个
/
,否则您将遇到问题,因为您的最终URL如下所示:

http://localhost:8080/my/route/get1
而不是:

http://localhost:8080/my/route/get/1
您的
@PathVariable
看起来也很奇怪,请尝试执行以下操作:

@PathVariable("id") String id

为了确保Spring将
{id}
映射到您的
@PathVariable

您的问题可能来自您的控制器,您可以这样声明您的路径:

@GetMapping(path = "{id}", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
因此,除非在控制器类映射的末尾有一个
/
,否则您将遇到问题,因为您的最终URL如下所示:

http://localhost:8080/my/route/get1
而不是:

http://localhost:8080/my/route/get/1
您的
@PathVariable
看起来也很奇怪,请尝试执行以下操作:

@PathVariable("id") String id

确保Spring将映射
{id}
到您的
@PathVariable

我尝试更改path变量,但仍然没有得到任何结果,我得到的响应状态为200,但响应对象仍然为空。我还更新了上面的代码,以便您可以看到路由路径,我确实按照您所写的那样设置了路径。我尝试更改path变量,但仍然没有得到响应g nothing,我得到的响应状态为200,但响应对象仍然为空。我还更新了上面的代码,以便您可以看到路由路径,我确实按照您所写的方式设置了路径。发现我的错误,是在模型中,错误地键入了getId getter方法。当我将id切换为id时,我的id类似于so@id private String content\u id它全部插入播放找到了我的错误,它在模型中,错误地输入了getId getter方法。当我将id切换为id时,我的id像是@id private String content\u id