What I want is to filter and search for sheet music with Examplematcher and Examples from 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.
Try this
ExampleMatcher matcher = ExampleMatcher.matching()
.withMatcher("componist", exact())
.withMatcher("key", exact())
.withMatcher("instrument",exact());
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.