美文网首页
Example 查询

Example 查询

作者: 你说这个谁懂啊 | 来源:发表于2020-03-13 22:37 被阅读0次
    TestEntity entity = new TestEntity();
    entity.setFieldA(str);
    Example<TestEntity> example = Example.of(entity);
    testRepository.findAll(example);
    
    // 当心Entity中的非Null属性都会成为Where条件,属性应全部使用包装类型,并避免赋予初值,或使用ExampleMatcher的withIgnorePaths忽略改属性。
    class TestEntity { String fieldA; String fieldB = 'x'; int fieldC; Boolean fieldD }
    TestEntity entity = new TestEntity();
    entity.setFieldA(str);
    // where fieldA = 'str' and fieldB = 'x' and fieldC = 0
    testRepository.findAll(Example.of(entity));
    // where fieldA = 'str'
    testRepository.findAll(Example.of(entity, 
        ExampleMatcher.matching().withIgnorePaths("fieldB").withIgnorePaths("fieldC"));
    

    Query By Example
    Spring Data JPA 实例查询

    相关文章

      网友评论

          本文标题:Example 查询

          本文链接:https://www.haomeiwen.com/subject/xdkushtx.html