MyBatis 是一个持久层框架,它提供了许多功能来简化数据库操作。其中一个功能是 collection 查询策略,它用于在查询结果中包含集合类型的属性。
MyBatis 的 collection 查询策略有三种:select,fetchType 和 fetchSize。
<collection property="users" select="selectUsersByDepartmentId" column="department_id"/>
<collection property="users" select="selectUsersByDepartmentId" column="department_id" fetchType="lazy"/>
<collection property="users" select="selectUsersByDepartmentId" column="department_id" fetchSize="100"/>
这些 collection 查询策略可以根据实际需求来配置,以提高查询效率和减少资源消耗。在使用 MyBatis 进行数据库操作时,可以根据具体情况选择合适的查询策略来优化查询性能。