xml問價(jià)中查詢數(shù)據(jù)中包含list,需要使用collection
resultMap id="XX" type="com.XXX.XXXX">
id column="o_id" jdbcType="BIGINT" property="id" />
result column="o_user_id" jdbcType="BIGINT" property="userId" />
....
collection property="orderProductList" ofType="com.XXXXXX.XXXXX">
id column="p_id" jdbcType="BIGINT" property="id" />
result column="p_order_id" jdbcType="BIGINT" property="orderId" />
....
/collection>
/resultMap>
這樣的查詢系統(tǒng)封裝的通用分頁查詢是不對(duì)的,所以需要自己sql中加入分頁解決
select id="XXX" resultMap="OrderListMap">
SELECT
you.nick_name,
yo.id o_id,
yo.user_id o_user_id
FROM
(
SELECT * FROM
youpin_order
WHERE
1 = 1
if test="status != null">
and `status` = #{status}
/if>
if test="page != null and limit != null">
LIMIT #{page},
#{limit}
/if>
) yo
LEFT JOIN XXX yop ON yo.id = yop.order_id
LEFT JOIN XXXX you ON yo.user_id = you.id
/select>
傳入?yún)?shù)的時(shí)候需要計(jì)算
(offset - 1) * limit, limit
總結(jié)
以上所述是小編給大家介紹的mysql一對(duì)多關(guān)聯(lián)查詢分頁錯(cuò)誤問題的解決方法,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
您可能感興趣的文章:- MySQL百萬級(jí)數(shù)據(jù)分頁查詢優(yōu)化方案
- mysql千萬級(jí)數(shù)據(jù)分頁查詢性能優(yōu)化
- mysql oracle和sqlserver分頁查詢實(shí)例解析
- 詳解MySQL的limit用法和分頁查詢語句的性能分析
- Mysql Limit 分頁查詢優(yōu)化詳解
- Oracle、MySQL和SqlServe三種數(shù)據(jù)庫分頁查詢語句的區(qū)別介紹
- mysql、mssql及oracle分頁查詢方法詳解
- Mysql中分頁查詢的兩個(gè)解決方法比較
- oracle,mysql,SqlServer三種數(shù)據(jù)庫的分頁查詢的實(shí)例
- MySQL中SQL分頁查詢的幾種實(shí)現(xiàn)方法及優(yōu)缺點(diǎn)