在SpringBoot中使用规范分页

时间:2018-06-19 18:15:08

标签: spring-boot spring-data-jpa specifications

我创建了一个使用规范在SQL中创建过滤器的项目。

但是我需要分页查询,因此我在方法中放置了一个Pageable,如下所示:

MyRepository

Page<Protocolo> findAll(Specification<Protocolo> specification, Pageable pageable);

MyService

retorno =protocoloRepository.findAll(
                    Specifications.where(ProtocoloSpecification.withNumero(filtro.getNumero()))
                    .and(ProtocoloSpecification.withTipo(filtro.getTipoProtocolo()))
                    .and(ProtocoloSpecification.withAndamento(filtro.getAndamento()))
                    .and(ProtocoloSpecification.withNatureza(filtro.getNatureza()))
                    .and(ProtocoloSpecification.withCliente(filtro.getCliente()))
                    .and(ProtocoloSpecification.withDataBetween(filtro.getCampoData(), filtro.getDtInicial(), filtro.getDtFinal()))
                    , new PageRequest(offset,limit,Sort.Direction.DESC,"dataProtocolo")).getContent();

但是当我配置为在终端中显示sql时,子句限制和偏移量不显示

这是我的日志:

select
        protocolo0_.id as id1_33_0_,
        cliente1_.id as id1_7_1_,
        statusprot2_.id as id1_42_2_,
        status3_.id as id1_41_3_,
        natureza4_.id as id1_24_4_,
        protocolo0_.apresentante as apresent2_33_0_,
        protocolo0_.apresentante_rg as apresent3_33_0_,
        protocolo0_.cartorio_parceiro_id as cartori38_33_0_,
        protocolo0_.cliente_id as cliente39_33_0_,
        protocolo0_.dt_certidao_informado_portal as dt_certi4_33_0_,
        protocolo0_.data_protocolo as data_pro5_33_0_,
        protocolo0_.dt_protocolo_informado_portal as dt_proto6_33_0_,
        protocolo0_.dt_registro_informado_portal as dt_regis7_33_0_,
        protocolo0_.data_doc as data_doc8_33_0_,
        protocolo0_.data_entrega as data_ent9_33_0_,
        protocolo0_.data_prevista as data_pr10_33_0_,
        protocolo0_.data_vencimento as data_ve11_33_0_,
        protocolo0_.dt_devolvido as dt_devo12_33_0_,
        protocolo0_.dt_registro as dt_regi13_33_0_,
        protocolo0_.email as email14_33_0_,
        protocolo0_.forma_entrega_id as forma_e40_33_0_,
        protocolo0_.ic_guarda_conservacao as ic_guar15_33_0_,
        protocolo0_.ic_possui_sigilo_legal as ic_poss16_33_0_,
        protocolo0_.natureza_id as naturez41_33_0_,
        protocolo0_.nr_exame_calculo_referencia as nr_exam17_33_0_,
        protocolo0_.numero as numero18_33_0_,
        protocolo0_.numero_registro as numero_19_33_0_,
        protocolo0_.numero_registro_referencia as numero_20_33_0_,
        protocolo0_.objetos as objetos21_33_0_,
        protocolo0_.observacao_registro as observa22_33_0_,
        protocolo0_.observacoes as observa23_33_0_,
        protocolo0_.parte as parte24_33_0_,
        protocolo0_.parte_documento as parte_d25_33_0_,
        protocolo0_.pasta_pj as pasta_p26_33_0_,
        protocolo0_.pedido_id as pedido_27_33_0_,
        protocolo0_.registro_referencia as registr28_33_0_,
        protocolo0_.responsavel as respons29_33_0_,
        protocolo0_.servicos as servico30_33_0_,
        protocolo0_.situacao_atual_registro as situaca31_33_0_,
        protocolo0_.sub_natureza_id as sub_nat42_33_0_,
        protocolo0_.telefone as telefon32_33_0_,
        protocolo0_.texto_carimbo as texto_c33_33_0_,
        protocolo0_.texto_certidao as texto_c34_33_0_,
        protocolo0_.tipo_protocolo_id as tipo_pr35_33_0_,
        protocolo0_.valor as valor36_33_0_,
        protocolo0_.vias as vias37_33_0_,
        cliente1_.apresentante as apresent2_7_1_,
        cliente1_.documento as document3_7_1_,
        cliente1_.email as email4_7_1_,
        cliente1_.identificacao as identifi5_7_1_,
        cliente1_.nome as nome6_7_1_,
        cliente1_.nome_fantasia as nome_fan7_7_1_,
        cliente1_.responsavel as responsa8_7_1_,
        statusprot2_.conteudo as conteudo2_42_2_,
        statusprot2_.data as data3_42_2_,
        statusprot2_.status_id as status_i4_42_2_,
        statusprot2_.usuario_id as usuario_5_42_2_,
        statusprot2_.protocolo_id as protocol6_42_0__,
        statusprot2_.id as id1_42_0__,
        status3_.automatico as automati2_41_3_,
        status3_.bloquear_protocolo as bloquear3_41_3_,
        status3_.nome as nome4_41_3_,
        natureza4_.dias_previsao as dias_pre2_24_4_,
        natureza4_.dias_reentrada as dias_ree3_24_4_,
        natureza4_.dias_vencimento as dias_ven4_24_4_,
        natureza4_.natureza_tipo_id as natureza5_24_4_,
        natureza4_.nome as nome6_24_4_,
        natureza4_.tipo_emissao_certidao_id as tipo_emi7_24_4_ 
    from
        protocolo protocolo0_ 
    left outer join
        cliente cliente1_ 
            on protocolo0_.cliente_id=cliente1_.id 
    left outer join
        status_protocolo statusprot2_ 
            on protocolo0_.id=statusprot2_.protocolo_id 
    left outer join
        status status3_ 
            on statusprot2_.status_id=status3_.id 
    left outer join
        natureza natureza4_ 
            on protocolo0_.natureza_id=natureza4_.id 
    where
        (
            protocolo0_.tipo_protocolo_id in (
                ? , ? , ? , ? , ? , ?
            )
        ) 
        and (
            protocolo0_.data_protocolo between ? and ?
        ) 
    order by
        protocolo0_.data_protocolo desc

这是正确的行为,还是应该在日志中显示“ limit”和“ offset”子句?

0 个答案:

没有答案