DataWay 分页查询
参数
{
"article_title":"",
"page":1,
"pageSize":10
}
请求
// - 设置数据源 xxx 为你设置的数据源
hint FRAGMENT_SQL_DATA_SOURCE = "xxx"
// 自动转驼峰
hint FRAGMENT_SQL_COLUMN_CASE = "hump"
// 开启分页
hint FRAGMENT_SQL_QUERY_BY_PAGE = true
hint FRAGMENT_SQL_OPEN_PACKAGE = "off"
var dataSetFun = @@mybatis(article_title)
<%
<select>
SELECT
CAST(@row_number := @row_number + 1 AS UNSIGNED) AS '序号',
article_title AS '标题',
DATE_FORMAT(created_at, '%Y-%m-%d') AS '发布时间',
CASE
WHEN article_status = 2 THEN '待发布'
WHEN article_status = 3 THEN '已发布'
END AS '状态'
FROM
`lc_knowledge_test`.`t_article`, (SELECT @row_number := 0) AS rn
WHERE
`article_title` like concat('%',#{article_title},'%')
AND `is_deleted` = 0
AND (`article_status` = 2 OR `article_status` = 3)
<if test="article_title != null and article_title != ''">
and article_title like CONCAT('%',#{article_title},'%')
</if>
</select>
%>
// 创建分页查询对象
var pageQuery = dataSetFun(${article_title});
// 设置分页信息
run pageQuery.setPageInfo({
"pageSize" : ${pageSize}, // 页大小
"currentPage" : ${page} - 1 // 第3页
});
// 执行分页查询
var result = pageQuery.data();
return {
"currentPage" : pageQuery.pageInfo().currentPage + 1,
"pageSize" : pageQuery.pageInfo().pageSize,
"totalPage" : pageQuery.pageInfo().totalPage,
"totalRow" : pageQuery.pageInfo().totalCount,
"list" : pageQuery.data()
}
返回格式
{
"desc" : "@resultMessage",
"code" : "@resultCode",
"data" : "@resultData"
}
返回数据
{
"desc":"OK",
"code":0,
"data":{
"currentPage":1,
"pageSize":10,
"totalPage":2,
"totalRow":4,
"list":[
{
"序号":"1",
"标题":"新文章标题1",
"发布时间":"2023-06-27",
"状态":"已发布"
},
{
"序号":"2",
"标题":"文章标题",
"发布时间":"2023-06-28",
"状态":"已发布"
},
{
"序号":"3",
"标题":"test",
"发布时间":"2023-06-29",
"状态":"待发布"
},
{
"序号":"4",
"标题":"文章标题",
"发布时间":"2023-06-30",
"状态":"已发布"
}
]
}
}