andEqualTo(String property, Object value):设置属性等于指定值的条件。 andNotEqualTo(String property, Object value):设置属性不等于指定值的条件。
Example example = new Example(User.class);
example.createCriteria().andEqualTo("age", 25);
andGreaterThan(String property, Object value):设置属性大于指定值的条件。
andGreaterThanOrEqualTo(String property, Object value):设置属性大于等于指定值的条件。
andLessThan(String property, Object value):设置属性小于指定值的条件。
andLessThanOrEqualTo(String property, Object value):设置属性小于等于指定值的条件。
Example example = new Example(User.class);
example.createCriteria().andGreaterThan("age", 25)
.andLessThan("salary", 50000);
andBetween(String property, Object value1, Object value2):设置属性在指定区间内的条件。
andNotBetween(String property, Object value1, Object value2):设置属性不在指定区间内的条件。
Example example = new Example(User.class);
example.createCriteria().andBetween("age", 20, 30)
.andNotBetween("salary", 10000, 30000);
andIn(String property, Iterable<?> values):设置属性在给定集合中的条件。
andNotIn(String property, Iterable<?> values):设置属性不在给定集合中的条件。
Example example = new Example(User.class);
example.createCriteria().andIn("department", Arrays.asList("IT", "Finance"))
.andNotIn("role", Arrays.asList("Admin", "Manager"));
andIsNull(String property):设置属性为空的条件。
andIsNotNull(String property):设置属性不为空的条件。
Example example = new Example(User.class);
example.createCriteria().andIsNull("email")
.andIsNotNull("phone");
andLike(String property, String value):设置属性模糊匹配指定值的条件。
andNotLike(String property, String value):设置属性不模糊匹配指定值的条件。
Example example = new Example(User.class);
example.createCriteria().andLike("name", "Joh%")
.andNotLike("address", "%Apartment%");
andCondition(String condition):根据自定义的条件表达式添加条件。
Example example = new Example(User.class);
example.createCriteria().andCondition("age > 20 and salary < 60000");
and():使用 AND 连接当前条件。
or():使用 OR 连接当前条件。
Example example = new Example(User.class);
example.createCriteria()
.andGreaterThan("age", 20)
.andLessThan("salary", 60000)
.or()
.andEqualTo("name", "Alice");
9、多条件组合
createCriteria():创建一个条件对象,可以在该对象上设置多个条件并进行组合。
Example example = new Example(User.class);
Example.Criteria criteria = example.createCriteria();
criteria.andEqualTo("department", "HR");
criteria.andGreaterThan("age", 30);
criteria.andLessThan("salary", 80000);
setDistinct(boolean distinct):设置是否进行去重查询。
Example example = new Example(User.class);
example.setDistinct(true);
setOrderByClause(String orderByClause):设置排序规则。
Example example = new Example(User.class);
example.setOrderByClause("age DESC, salary ASC");
selectProperties(String… properties):设置要查询的字段。
Example example = new Example(User.class);
example.selectProperties("name", "age", "email");
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。