小编Jig*_*igu的帖子

如何使ExampleMatcher只匹配一个属性?

如何实现ExampleMatcher,从我的类中随机匹配一个属性并忽略其他属性?

假设我的课程是这样的:

Public Class Teacher() {
    String id;
    String name;
    String address;
    String phone;
    int area;
    ..other properties is here...
}
Run Code Online (Sandbox Code Playgroud)

如果我想按名称匹配:

Teacher TeacherExample = new Teacher("Peter");

ExampleMatcher matcher = ExampleMatcher.matchingAny()
.withStringMatcher(ExampleMatcher.StringMatcher.CONTAINING)
.withIgnoreCase()
.withIgnorePaths("id", "address", "phone","area",...);   //no name 
Run Code Online (Sandbox Code Playgroud)

如果我想按地址匹配:

ExampleMatcher matcher = ExampleMatcher.matchingAny()
.withStringMatcher(ExampleMatcher.StringMatcher.CONTAINING)
.withIgnoreCase()
.withIgnorePaths("id", "name", "phone","area",...); //no address
Run Code Online (Sandbox Code Playgroud)

所以我需要重复withIgnorePaths(..)如何避免这种情况?

java matcher query-by-example spring-data

8
推荐指数
1
解决办法
8367
查看次数

标签 统计

java ×1

matcher ×1

query-by-example ×1

spring-data ×1