zhangzhenhuajack / spring-data-jpa-guide

spring-data-jpa-guide,Spring Data JPA实战,SpringDataJpa详解
http://www.jackzhang.cn/spring-data-jpa-guide/
365 stars 159 forks source link

没找到 query by example 实例代码 #5

Open ghost opened 6 years ago

zhangzhenhuajack commented 6 years ago
Customer customer = new Customer();
customer.setName("Jack");
customer.setAddress("上海");

//创建匹配器,即如何使用查询条件
ExampleMatcher matcher = ExampleMatcher.matching() //构建对象
        .withMatcher("name", GenericPropertyMatchers.startsWith()) //姓名采用“开始匹配”的方式查询
        .withIgnorePaths("focus");  //忽略属性:是否关注。因为是基本类型,需要忽略掉
//创建实例
Example<Customer> ex = Example.of(customer, matcher); 

//查询
List<Customer> ls = dao.findAll(ex);

//输出结果
for (Customer bo:ls)
{
    System.out.println(bo.getName());
}