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

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

作者: 何佳阳 | 来源:发表于2020-07-29 00:43 被阅读0次
    //在userMapper里:
    @Results({
        @Result(property = "id", column = "id"),
        @Result(property = "username", column = "username"),
        @Result(property = "orders", column = "uid", javaType = List.class,
            many = @Many(select = "OrderMapper.findOrderByUserId"))
    })
    @Select("select * from User")
    public List<Order> findUserAndOrders();
    
    
    //在orderMapper里:
    @Select("select * from orders where user_id = #{userId}")
    public User findOrderByUserId(Integer userId);

    相关文章

      网友评论

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

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