You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<selectid="selectCatPage"resultMap="CatResult">
select p.CAT_ID, p.CAT_NAME, t.TOY_ID, t.TOY_NAME
from (<![CDATA[ <p> ]]>
select distinct c.CAT_ID, c.CAT_NAME
from CAT c
left join TOY t on t.CAT_ID = c.CAT_ID
<where>
<iftest="catName != null and catName != ''">and CAT_NAME like concat('%', #{catName},'%')</if>
<iftest="toyName != null and toyName != ''">and instr(t.TOY_NAME, #{toyName})</if>
</where>
<![CDATA[ </p> ]]>) p
left join TOY t on t.CAT_ID = p.CAT_ID
<where>
<iftest="toyName != null and toyName != ''">and instr(t.TOY_NAME, #{toyName})</if>
</where>
</select>
countSql:
select distinctc.CAT_ID, c.CAT_NAMEfrom CAT c
left join TOY t ont.CAT_ID=c.CAT_IDwhere CAT_NAME like concat('%', ?,'%') and instr(t.TOY_NAME, ?)
pageSql:
selectp.CAT_ID, p.CAT_NAME, t.TOY_ID, t.TOY_NAMEfrom (
select distinctc.CAT_ID, c.CAT_NAMEfrom CAT c
left join TOY t ont.CAT_ID=c.CAT_IDwhere CAT_NAME like concat('%', ?,'%') and instr(t.TOY_NAME, ?)
) p
left join TOY t ont.CAT_ID=p.CAT_IDwhere instr(t.TOY_NAME, ?)
想法:
面对一对多分页的情况,可以将countSql和pageSql写在一起, 用标签区分sql.自定义自定义方言实现类,以达到在拦截器做count查询和分页查询时传入不同sql的目的.
先看一份sql:
countSql:
pageSql:
自定义方言:
侵入修改部分(ExecutorUtil):
光从代码看executeAutoCount()方法相比于pageQuery()方法在方言中少一个可以自定义实现processParameterObject()方法.
但processParameterObject()方法中实质上会修改原始boundSql对象.
因此,我的想法是,可以将executeAutoCount()和pageQuery()方法中的new BoundSql()方法交由方言实现.
如果有其他的一对多分页方案,也可以告诉我,谢谢.
The text was updated successfully, but these errors were encountered: