mybatis基于注解的关联查询

一、使用场景

mybatis多表关联查询,1对1,1对多

public class User implements UserDetails, Serializable {
    //parent是一个对象,有自己的表,这是1对1的多表关联查询
    private Parent scale;
    //Authority是一个对象,有自己的表,这是1对多的查询
    private List<Authority> authoritys;

 

二、参考文献

https://blog.csdn.net/gluawwa/article/details/53289162(三、方案中的代码复制的这篇博客里的,用作备份,已实践通过)

三、方案


 
public interface UserInfoDAO {  
    //一个user对应一个userinfo  
    @Select("select * from test_userinfo where id =#{id}")  
    public UserInfo getUserInfoById(@Param("id") String id);  
  
   //select ="com.zwk.dao.UserInfoDAO.getUserInfoById",getUserinfoById方法必须存在  
    @Select("select * from test_user u where u.id = #{id}")  
    @Results({  
            @Result(id = true,property = "id" ,column = "id"),  
            @Result(property ="password",column = "password"),  
            @Result(property ="userInfo",column="info_id",one =@One(select ="com.zwk.dao.UserInfoDAO.getUserInfoById"))}  
    )  
    public User getById(@Param("id") String id);  
} 

 

转载于:https://my.oschina.net/Cubicluo/blog/1817659

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值