查询DSL NumberPath之类的操作不起作用。下面是代码
BooleanBuilder whereClause = new BooleanBuilder();
if(columnType!=null && columnType.equalsIgnoreCase("Long")){
Number searchNumb= (Number)filterMap.get("searchText");
Long searchText=searchNumb.longValue();
NumberPath<Long> longColumn =
Expressions.numberPath(Long.class,query,searchType);
whereClause.and( longColumn.like("%"+searchText+"%") );
}
return logRepository.findAll(whereClause, pageable);
下面是生成的SQL的日志
017-05-15 10:14:31.007 TRACE 11396 --- [ main] o.h.engine.query.spi.HQLQueryPlan : Find: select commonLog
from CommonLog commonLog
where str(commonLog.processId) like ?1 escape '!'
2017-05-15 10:14:31.007 TRACE 11396 --- [ main] o.hibernate.engine.spi.QueryParameters : Named parameters: {1=%164%}
2017-05-15 10:14:31.022 DEBUG 11396 --- [ main] org.hibernate.SQL : select commonlog0_.id as id1_1_, commonlog0_.imei as imei2_1_, commonlog0_.log_date as log_date3_1_, commonlog0_.process_id as process_4_1_ from common_log commonlog0_ where cast(commonlog0_.process_id as varchar) like ? escape '!' limit ? offset ?
Hibernate: select commonlog0_.id as id1_1_, commonlog0_.imei as imei2_1_, commonlog0_.log_date as log_date3_1_, commonlog0_.process_id as process_4_1_ from common_log commonlog0_ where cast(commonlog0_.process_id as varchar) like ? escape '!' limit ? offset ?
2017-05-15 10:14:31.022 TRACE 11396 --- [ main] o.h.r.j.i.ResourceRegistryStandardImpl : Registering statement [org.apache.tomcat.jdbc.pool.StatementFacade$StatementProxy[Proxy=1192555591; Query=select commonlog0_.id as id1_1_, commonlog0_.imei as imei2_1_, commonlog0_.log_date as log_date3_1_, commonlog0_.process_id as process_4_1_ from common_log commonlog0_ where cast(commonlog0_.process_id as varchar) like ? escape '!' limit ? offset ?; Delegate=select commonlog0_.id as id1_1_, commonlog0_.imei as imei2_1_, commonlog0_.log_date as log_date3_1_, commonlog0_.process_id as process_4_1_ from common_log commonlog0_ where cast(commonlog0_.process_id as varchar) like ? escape '!' limit ? offset ?]]
2017-05-15 10:14:31.022 TRACE 11396 --- [ main] o.h.e.jdbc.internal.JdbcCoordinatorImpl : Registering last query statement [org.apache.tomcat.jdbc.pool.StatementFacade$StatementProxy[Proxy=1192555591; Query=select commonlog0_.id as id1_1_, commonlog0_.imei as imei2_1_, commonlog0_.log_date as log_date3_1_, commonlog0_.process_id as process_4_1_ from common_log commonlog0_ where cast(commonlog0_.process_id as varchar) like ? escape '!' limit ? offset ?; Delegate=select commonlog0_.id as id1_1_, commonlog0_.imei as imei2_1_, commonlog0_.log_date as log_date3_1_, commonlog0_.process_id as process_4_1_ from common_log commonlog0_ where cast(commonlog0_.process_id as varchar) like ? escape '!' limit ? offset ?]]
2017-05-15 10:14:31.038 TRACE 11396 --- [ main] o.h.type.descriptor.sql.BasicBinder : binding parameter [1] as [VARCHAR] - [%164%]
但是当我在PGAdmin上运行带有绑定值的生成的sql时,它会给出一个结果,下面是我在PgAdmin上运行的sql。
select count(commonlog0_.id) as col_0_0_ from common_log commonlog0_ where
cast(commonlog0_.process_id as varchar) like '%164%' escape '!'