lickysee's recent timeline updates
lickysee

lickysee

V2EX member #453844, joined on 2019-11-18 15:00:05 +08:00
Today's activity rank 13002
lickysee's recent replies
Jun 16, 2020
Replied to a topic by piapia123 程序员 如何缓解理财亏损带来的心理不适
大不了从头再来
Jun 11, 2020
Replied to a topic by yumc Java 关于 spring data jpa 的一些业务问题
大致上的思路就是将判断如果是空就不进行查询这种重复的代码提取出来,返回一个 Specification,然后结合官方给出来的例子,进行条件的拼接。

参照官方文档 Example 98. Combined Specifications
Jun 11, 2020
Replied to a topic by yumc Java 关于 spring data jpa 的一些业务问题
提供一个自己的思路,代码仅供参考,希望对你有帮助。
```
public class SpecificationUtil {

public static <T> Specification<T> stringLike(
final String field,
final String param
) {
return skipNullAndBlank(
param,
(builder, root) -> builder.like(root.get(field), "%" + param + "%")
);
}


private static <T> Specification<T> skipNullAndBlank(
String p,
BiFunction<CriteriaBuilder, Root<T>, Predicate> f
) {
return ((Specification<T>) (root, query, builder) -> {
if (Strings.isBlank(p)) {
return query.getGroupRestriction();
} else {
return f.apply(builder, root);
}
});
}
}
```
Jun 11, 2020
Replied to a topic by yumc Java 关于 spring data jpa 的一些业务问题
About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1143 Online   Highest 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 18ms · UTC 18:11 · PVG 02:11 · LAX 11:11 · JFK 14:11
♥ Do have faith in what you're doing.