JPA原生sql多条件查询

// my_table 是表,MyTable是实体 查询字段为name,comment
public interface TabelDao extends PagingAndSortingRepository,
JpaSpecificationExecutor {

@Query(value = "select * from my_table t where 1=1 " +
        "AND if(''!=:#{#myTabel.name}, name like %:#{#myTabel.name}%,1=1) " +
        "AND if(''!=:#{#myTabel.comment}, comment=:#{#myTabel.comment},1=1) "
        ,nativeQuery = true)
List findByStrategyTypeAndStatess(MyTabel myTabel );

}

你可能感兴趣的:(数据库,java,sql,数据库,mysql)