public static Specification<Model> listSpec(Query query) {
return (root, query, cb) -> {
List<Predicate> predicates = new ArrayList<>();
if (null != query.getKeyWord()) {
predicates.add(cb.like(root.get("title"), "\'%" + query.getKeyWord() + "%\'"));
}
return cb.and(predicates.toArray(new Predicate[predicates.size()]));
};
调试后没有匹配的结果
Hibernate: select sell0_.cfid as cfid1_2_, sell0_.address as address2_2_, sell0_.area as area3_2_, sell0_.area_id as area_id4_2_, sell0_.browse as browse5_2_, sell0_.cf_thumb as cf_thumb6_2_, sell0_.cf_type as cf_type7_2_, sell0_.city as city8_2_, sell0_.city_id as city_id9_2_, sell0_.collection as collect10_2_, sell0_.constructionarea as constru11_2_, sell0_.creat_time as creat_t12_2_, sell0_.is_delete as is_dele13_2_, sell0_.foundertype as founder14_2_, sell0_.frontage as frontag15_2_, sell0_.industry as industr16_2_, sell0_.landarea as landare17_2_, sell0_.is_license as is_lice18_2_, sell0_.license_mark as license19_2_, sell0_.officearea as officea20_2_, sell0_.oldamountland as oldamou21_2_, sell0_.paymoney as paymone22_2_, sell0_.paystatus as paystat23_2_, sell0_.paytime as paytime24_2_, sell0_.phone as phone25_2_, sell0_.phonedisplay as phonedi26_2_, sell0_.point_x as point_x27_2_, sell0_.point_y as point_y28_2_, sell0_.propertysituation as propert29_2_, sell0_.province as provinc30_2_, sell0_.provinceid as provinc31_2_, sell0_.push_time as push_ti32_2_, sell0_.push_type as push_ty33_2_, sell0_.report as report34_2_, sell0_.sell_tag as sell_ta35_2_, sell0_.status as status36_2_, sell0_.taxation as taxatio37_2_, sell0_.title as title38_2_, sell0_.totalprice as totalpr39_2_, sell0_.transfermode as transfe40_2_, sell0_.unitprice as unitpri41_2_, sell0_.update_time as update_42_2_, sell0_.userid as userid43_2_, sell0_.workshoparea as worksho44_2_ from cf_sell sell0_ where sell0_.is_delete=0 and sell0_.is_license=1 and sell0_.status=1 and (sell0_.title like ?) order by sell0_.browse desc limit ?, ?
答案 0 :(得分:1)
predicates.add(cb.like(root.get("title"), "%" + query.getKeyWord() + "%"));
尝试排除'
字符如果您没有包含前导'
字符的标题。