美文网首页
MyBatis 注解查询一对一(@Results @One)

MyBatis 注解查询一对一(@Results @One)

作者: 何佳阳 | 来源:发表于2020-07-29 00:29 被阅读0次
    //在orderMapper里:
    @Results({
        @Result(property = "id", column = "id"),
        @Result(property = "orderTime", column = "orderTime"),
        @Result(property = "total", column = "total"),
        @Result(property = "user", column = "uid", javaType = User.class,
            one = @One(select = "UserMapper.findUserById"))
    })
    @Select("select * from Order")
    public List<Order> findOrderAndUser();
    
    //在userMapper里:
    @Select("select * from user where id = #{id}")
    public User findUserById(Integer id);

    相关文章

      网友评论

          本文标题:MyBatis 注解查询一对一(@Results @One)

          本文链接:https://www.haomeiwen.com/subject/xoecrktx.html