如何使用mybatis-spring在mapper.xml中映射多个表



我正在创建一个项目,其中我必须从多个表中获取记录。为此,我正在使用春季和mybatis。我的问题是,对于多个表,应该只有一个mapper.xml。但是,如何在一个mapper.xml中映射多个表。我们的mapper.xml的样子。

我不确定我是否正确理解您的问题。如果您谈论如何处理不同的桌子,那么使用一个单个映射器并不是一个好习惯。最好将其分开并以许多方式注册您的映射器。其中一个是

<mappers>
  <mapper resource="org/mybatis/builder/AuthorMapper.xml"/>
  <mapper resource="org/mybatis/builder/BlogMapper.xml"/>
  <mapper resource="org/mybatis/builder/PostMapper.xml"/>
</mappers>

请参阅http://www.mybatis.org/mybatis-3/configuration.html#mappers了解更多详细信息。

但是,如果您谈论如何通过加入多个表来查询,则可以使用结果映射来实现它。请参阅http://www.mybatis.org/mybatis-3/sqlmap-xml.html#advanced_result_maps

最新更新