Jpa带下拉框的多条件查询

如下示例:

//查询商品信息
@Query(value = "select * from tb_product " +
        "where del_flag=?1 and name like ?4 and " +
        "case ?2 when 'all' then state is not null else state=?2 end and " +
        "case ?3 when 'all' then type_id is not null else type_id=?3 end",nativeQuery = true)
Page<Product> findByDelFlagAndStateAndTypeIdAndNameLike(String delFlag,String state, String typeId, String nameLike,Pageable pageable);
当下拉框选的是"选择状态"和"选择类型"时传的值未all,
此时可把条件设为 is not null,不能为!=null,否则会出错

猜你喜欢

转载自blog.csdn.net/weixin_39936341/article/details/83343821
今日推荐