复杂关联表分页查询,传入article的name="a",默认分页大小20,第一页即0:

SELECT u0.ID,u0.NAME,u0.CODE,u0.CONTENT,u0.STATUS,u0.ORDER_NUM,u0.URS_NAV_ID,u0.URS_CATALOG_ID,
 		       u2.NAME AS CATALOG_NAME,u2.CODE AS CATALOG_CODE,
                       u1.NAME AS NAV_NAME,u1.CODE AS NAV_CODE 
FROM T_URS_ARTICLE u0,T_URS_NAV u1,T_URS_CATALOG u2 
WHERE  u0.URS_CATALOG_ID = u2.ID 
AND  u0.URS_NAV_ID = u1.ID 
AND ( u0.NAME LIKE ? OR  u0.CODE LIKE ? OR  u1.CODE LIKE ? OR  u2.CODE LIKE ?)  
AND  u0.URS_NAV_ID = ? 
ORDER BY u0.CODE DESC 
LIMIT ? OFFSET ?  

            参数:%a%, %a%, %a%, %a%, 6082f3b3-cc61-4a60-9088-a9c7b4f6e329, 20, 0

SELECT  COUNT(*)  
FROM T_URS_ARTICLE u0,T_URS_NAV u1,T_URS_CATALOG u2 
WHERE  u0.URS_CATALOG_ID = u2.ID 
AND  u0.URS_NAV_ID = u1.ID 
AND ( u0.NAME LIKE ? OR  u0.CODE LIKE ? OR  u1.CODE LIKE ? OR  u2.CODE LIKE ?)  
AND  u0.URS_NAV_ID = ? 

            参数:%a%, %a%, %a%, %a%, 6082f3b3-cc61-4a60-9088-a9c7b4f6e329

public Pageable<Map<String, Object>> page(UrsArticle article,Pageable pageable){

        IMultiQuery query = new MultiQueryImpl();
        AliasTable art = query.table(UrsArticle.class);
        AliasTable nav = query.table(UrsNav.class);
        AliasTable catalog = query.table(UrsCatalog.class);

        query.whereEqual(art.c(UrsArticle.T_URS_CATALOG_ID), catalog.c(UrsCatalog.T_ID));
        query.whereEqual(art.c(UrsArticle.T_URS_NAV_ID), nav.c(UrsNav.T_ID));
        query.where(new Condition().andOr(
                new Expression(art.c(UrsArticle.T_NAME), article.getName(), ExpressionType.CDT_Like),
                new Expression(art.c(UrsArticle.T_CODE), article.getName(), ExpressionType.CDT_Like),
                new Expression(nav.c(UrsNav.T_CODE), article.getName(), ExpressionType.CDT_Like),
                new Expression(catalog.c(UrsCatalog.T_CODE), article.getName(), ExpressionType.CDT_Like)
        ));
        query.whereEqual(art.c(UrsArticle.T_URS_NAV_ID), article.getUrsNavId());
        query.orderDesc(art.c(UrsArticle.T_CODE));
  
        query.createQuery(Map.class, 
            art.cs(
                    UrsArticle.T_ID,
                    UrsArticle.T_NAME,
                    UrsArticle.T_CODE,
                    UrsArticle.T_CONTENT,
                    UrsArticle.T_STATUS,
                    UrsCatalog.T_ORDER_NUM,
                    UrsCatalog.T_URS_NAV_ID,
                    UrsCatalog.T_URS_CATALOG_ID),
            nav.cs().names(UrsNav.T_NAME,UrsNav.T_CODE).asNames("NAV_NAME","NAV_CODE")
            catalog.cs().names(UrsCatalog.T_NAME,UrsCatalog.T_CODE).asNames("CATALOG_NAME","CATALOG_CODE"));
         
        return ursArticleService.queryPage(query, pageable);
}
目录
Copyright © objectsql.com 2021 闽ICP备17009107号-3

闽公网安备 35020302035600号