mybatis

mybatis一对多、延迟查询

2020-08-16  本文已影响0人  rainbowz

参考
https://blog.csdn.net/ncepu_Chen/article/details/97424811

https://blog.csdn.net/qq_40981851/article/details/104191911?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param

实体类

@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class User implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 主键ID
     */
    private Long id;

    /**
     * 姓名
     */
    private String name;

    /**
     * 年龄
     */
    private Integer age;

    /**
     * 邮箱
     */
    private String email;

    private LocalDateTime updateTime;

    private List<Accounts> accounts;    // 一对多关系映射:主表实体应该包含从表实体的集合引用

@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class Accounts implements Serializable {

    private static final long serialVersionUID = 1L;

    private Integer id;

    /**
     * 金额
     */
    private Double money;

    /**
     * 用户编号
     */
    private Integer uid;


    private User user;

}


Userdao接口


image.png

User xml文件


image.png

AccountDao


image.png

Account xml

image.png

结果


image.png
上一篇下一篇

猜你喜欢

热点阅读