[英]Spring Data ExampleMatchers by Example returns empty array
What I want is to filter and search for sheet music with Examplematcher and Examples from Spring.我想要的是使用 Examplematcher 和来自 Spring 的示例来过滤和搜索乐谱。 This is not going so smoothly as I thought.这并不像我想象的那么顺利。 I hope you know what the solution is because I am stuck on it.我希望你知道解决方案是什么,因为我被困在它上面。 It is a spring boot application.它是一个弹簧启动应用程序。
Below my endpoint to filter:在我的端点下方进行过滤:
@GetMapping("/sheetmusic/filter")
public List<SheetMusic> getSheetMusicByFilter(@RequestBody Map<String,String> body){
String componist = body.get("componist");
String key = body.get("key");
String instrument = body.get("instrument");
SheetMusic sheetMusic = new SheetMusic(componist,key,instrument);
ExampleMatcher matcher = ExampleMatcher.matching()
.withMatcher("componist", new ExampleMatcher.GenericPropertyMatcher().exact())
.withMatcher("key",new ExampleMatcher.GenericPropertyMatcher().exact())
.withMatcher("instrument",new ExampleMatcher.GenericPropertyMatcher().exact());
Example<SheetMusic> example = Example.of(sheetMusic, matcher);
List<SheetMusic> sheetMusics = sheetMusicRepository.findAll(example);
return sheetMusics;
}
The problem is that the list of sheetMusics is empty, I am 100% sure I have a sheetmusic in the database with a componist name as : 'Alan Walker' but it still returns nothing.问题是 sheetMusics 的列表是空的,我 100% 确定我在数据库中有一个 sheetmusic,其组合名称为:'Alan Walker',但它仍然没有返回任何内容。
Try this尝试这个
ExampleMatcher matcher = ExampleMatcher.matching()
.withMatcher("componist", exact())
.withMatcher("key", exact())
.withMatcher("instrument",exact());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.