jpa criteria compare two strings in without considering spaces

落花浮王杯 提交于 2020-12-12 11:31:22

问题


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

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(" ", "") + "%")

Thanks


回答1:


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(" ", "") + "%"
       )


来源:https://stackoverflow.com/questions/42278886/jpa-criteria-compare-two-strings-in-without-considering-spaces

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!