zoukankan      html  css  js  c++  java
  • @NamedNativeQuery 自定义分页

    interface FoobarEntityRepository extends JpaRepository<FoobarEntity, Integer> {
        Page findFoobarsSpecialQuery(String someParameter, final Pageable pageable);
    }

    @Entity
    @SqlResultSetMappings({
        @SqlResultSetMapping(name = "SqlResultSetMapping.count", columns = @ColumnResult(name = "cnt"))
    })
    @NamedNativeQueries({
        @NamedNativeQuery(
                name = "FoobarEntity.findFoobarsSpecialQuery",
                resultClass = DailyPictureEntity.class,
                query = "Select * from foobars f where someValue = :someParameter "
        ),
        @NamedNativeQuery(
                name = "FoobarEntity.findFoobarsSpecialQuery.count",
                resultSetMapping = "SqlResultSetMapping.count",
                query = "Select count(*) as cnt from foobars f where someValue = :someParameter "
        )
    })
    FoobarEntity {
    }

    The trick is to specify the count query with the suffix .count. This works also with the Spring Data @Query annotation.

    Notice that you need a SQL result set mapping for the count query, though.

  • 相关阅读:
    第4次作业得分-东师软工
    第3次作业得分-东师软工
    C语言-第3次作业得分
    NPM
    Node模块化
    spring源码解析前瞻
    单例DCL模式
    dubbo-admin安装
    linux 安装Zookeeper
    Tomcat在Linux上的安装与配置
  • 原文地址:https://www.cnblogs.com/zany-hui/p/14460308.html
Copyright © 2011-2022 走看看