如何运行查询
select * from companies where data->>'inn' like '%12%'
使用org.springframework.data.jpa.domain.Specification
?
class CompanySpecification : Specification<Company>{
override fun toPredicate(root: Root<Company>, query:CriteriaQuery<*>, criteriaBuilder: CriteriaBuilder): Predicate? {
return criteriaBuilder.like(root.get("data-->inn"), "%12%")
}
}
答案 0 :(得分:0)
我找到了解决方案
class CompanySpecification : Specification<Company> {
override fun toPredicate(root: Root<Company>, query: CriteriaQuery<*>, builder: CriteriaBuilder): Predicate {
return builder.like(builder.function("jsonb_extract_path_text", String::class.java, root.get<String>("data"), builder.literal("inn")), "12%")
}
}