jpa条件在不考虑空格的情况下比较两个字符串 [英] jpa criteria compare two strings in without considering spaces

查看:84
本文介绍了jpa条件在不考虑空格的情况下比较两个字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为这是一个基本问题,但我一直在努力寻找答案.

I think that it is a basic question, but I'm struggling to get an answer.

问题是:使用 CriteriaBuilder 和Predicate如何在不考虑中间空格的情况下比较字符串.例如:"CH 525 kV AREIA 1077 PR" . CriteriaBuilder 库中没有替换"功能.

The question is: using CriteriaBuilder and Predicate how can I compare strings without considering spaces in the middle. For example: "CH 525 kV AREIA 1077 PR". There isn't a "replace" function in CriteriaBuilder library.

cb.like(equipamento.get(EquipamentoBO_.txNomeLongo), "%" + dto.getTxNomeEquipamento().toUpperCase().replace(" ", "") + "%")

谢谢

推荐答案

有一个 function 方法,如果您将 REPLACE 用作函数,该方法应该可以为您解决问题使用:

There is a function method which should do the trick for you if you use REPLACE as the function to use:

cb.like(
          cb.function("REPLACE"
                 , String.class
                 , equipamento.get(EquipamentoBO_.txNomeLongo)
                 , cb.literal(" ")
                 , cb.literal(""))
          , "%" + dto.getTxNomeEquipamento().toUpperCase().replace(" ", "") + "%"
       )

这篇关于jpa条件在不考虑空格的情况下比较两个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆