我们如何使用mybatis-spring映射Mapper.xml中的多个表?
How can we map multiple tables in Mapper.xml using mybatis-spring?
我正在创建一个项目,我必须在其中从多个表中获取记录。为此,我正在使用 spring 和 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
我正在创建一个项目,我必须在其中从多个表中获取记录。为此,我正在使用 spring 和 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