我是靠谱客的博主 平常唇彩,最近开发中收集的这篇文章主要介绍mybatis 多对多对多 字段名一致问题解决,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

Mybatis关联查询(一对多,多对一) - liqiangbk - 博客园 

通过起别名的方式解决

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.angen.springboot_test2.mapper.CateDao">
    <resultMap id="gameList" type="com.angen.springboot_test2.pojo.GameBigcate">
        <id column="bid" property="id" />
        <result column="btitle" property="title"/>
        <result property="sort" column="bsort"/>
        <collection  property="games" resultMap="gameTwo" ofType="com.angen.springboot_test2.pojo.Game">
        </collection>
    </resultMap>
    <resultMap id="gameTwo" type="com.angen.springboot_test2.pojo.Game">
        <id property="id" column="gid"/>
        <result property="title" column="gtitle"/>

        <collection property="gamess" ofType="com.angen.springboot_test2.pojo.Game">
            <id property="id" column="zid"/>
            <result property="title" column="ztitle"/>
        </collection>
    </resultMap>
    <sql id="field">
        bigcate.id as bid,
        bigcate.title as btitle,
        bigcate.sort as bsort,
        game.id as gid,
        game.title as gtitle,
        game_z.id as zid,
        game_z.title as ztitle
    </sql>
    <select id="findAll" resultMap="gameList">
        select
            <include refid="field"></include>
        from dlq_game_bigcate bigcate
            left join dlq_game game on bigcate.id=game.bigcate_id
            left join dlq_game game_z on game.id=game_z.parent_id
    </select>
</mapper>
package com.angen.springboot_test2.pojo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class GameBigcate implements Serializable {
    private Integer id;
    private String title;
    private Integer sort;

    private List<Game> games;
}
package com.angen.springboot_test2.pojo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Game implements Serializable {
    private Integer id;
    private Integer bigcate_id;
    private String smallcate_id;
    private Integer parent_id;
    private String title;
    private String route;
    private String alias;
    private String logo;
    private Integer temperature;
    private String seo_title;
    private String seo_keywords;
    private String seo_description;
    private String content;
    private String url;
    private Integer ads_type;
    private Integer status;
    private String search;
    private String official_url;
    private String download_url;
    private String operators;
    private String developers;
    private String theme;
    private String platform;
    private String letter;
    private Integer is_new;
    private Integer info_cate_id;
    private Integer sort;

    private List<Game> gamess;
}

最后

以上就是平常唇彩为你收集整理的mybatis 多对多对多 字段名一致问题解决的全部内容,希望文章能够帮你解决mybatis 多对多对多 字段名一致问题解决所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(33)

评论列表共有 0 条评论

立即
投稿
返回
顶部