package org.springframework.data.domain;
import org.springframework.data.util.ProxyUtils;
/**
* Support for query by example (QBE). An {@link Example} takes a {@code probe} to define the example. Matching options
* and type safety can be tuned using {@link ExampleMatcher}.
*
* @author Christoph Strobl
* @author Mark Paluch
* @author Oliver Gierke
* @param <T> the type of the probe.
* @since 1.12
*/
public interface Example<T> {
/**
* Create a new {@link Example} including all non-null properties by default.
*
* @param probe must not be {@literal null}.
* @return
*/
static <T> Example<T> of(T probe) {
return new TypedExample<>(probe, ExampleMatcher.matching());
}
/**
* Create a new {@link Example} using the given {@link ExampleMatcher}.
*
* @param probe must not be {@literal null}.
* @param matcher must not be {@literal null}.
* @return
*/
static <T> Example<T> of(T probe, ExampleMatcher matcher) {
return new TypedExample<>(probe, matcher);
}
/**
* Get the example used.
*
* @return never {@literal null}.
*/
T getProbe();
/**
* Get the {@link ExampleMatcher} used.
*
* @return never {@literal null}.
*/
ExampleMatcher getMatcher();
/**
* Get the actual type for the probe used. This is usually the given class, but the original class in case of a
* CGLIB-generated subclass.
*
* @return
* @see ProxyUtils#getUserClass(Class)
*/
@SuppressWarnings("unchecked")
default Class<T> getProbeType() {
return (Class<T>) ProxyUtils.getUserClass(getProbe().getClass());
}
}
Example
猜你喜欢
转载自blog.csdn.net/weixin_34216107/article/details/87048290
今日推荐
周排行