mybtis-plus多表查询后实体类的数据不匹配


package com.example.demo.pojo;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class book  {
    private int id;
    private String type;
    @TableField(value="name")
    private String bname;
    private String description;
    private Integer leaves;
    private Integer lend;
    @TableField(exist = false)
    private String jieshu;
    @TableField(exist = false)
    private String huanshu;
}
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Student {
    private Integer id;
    private String sno;
    private String name;
    private String password;
    @TableField(exist = false)
    List<book> books;
}

img

img

img

StudentMapper.xml

   <resultMap id="stduentbooks" type="com.example.demo.pojo.Student">
        <result property="id" column="id"/>
        <result property="name" column="name"/>
        <collection property="books" ofType="com.example.demo.pojo.book">
            <result property="id" column="id"/>
            <result property="bname" column="name"/>
            <result property="jieshu" column="jieshu"/>
            <result property="huanshu" column="huanshu"/>
        </collection>
    </resultMap>

    <select id="seletStudetBook" resultMap="stduentbooks">
            select
                s.id,s.name,b.id,b.name,bs.jieshu,bs.huanshu
            from
                student as s, book as b, bss as bs
            where
                s.id = bs.sid
            and
                b.id=bs.bid
            and
                s.id=#{id}

    </select>

结果

img

{
            "id": 1,
            "sno": null,
            "name": "张三",
            "password": null,
            "books": [
                {
                    "id": 1,
                    "type": null,
                    "bname": "张三",
                    "description": null,
                    "leaves": null,
                    "lend": null,
                    "jieshu": "2023-05-12",
                    "huanshu": "2023-05-17"
                },
                {
                    "id": 1,
                    "type": null,
                    "bname": "张三",
                    "description": null,
                    "leaves": null,
                    "lend": null,
                    "jieshu": "2023-05-13",
                    "huanshu": "2023-05-18"
                }
            ]
        }

sql语句能查询出结果,为啥封装成实体类后图书名和id都查询不对?

s.id,s.name,b.id,b.name,bs.jieshu,bs.huanshu 这些列要设置不同的别名。
最好是一个表对应一个实体。

相同的ID太多了。取个别名吧。