java mybatis多层collection嵌套查询
https://blog.csdn.net/ywanan/article/details/115674487?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_title~default-1.control
Factory.java
public class Factory implements Serializable { /** The Constant serialVersionUID. */ private static final long serialVersionUID = 1L; @ApiModelProperty(value = "地址") private java.lang.String address; private java.lang.String databaseName; @ApiModelProperty(value = "是否删除") private Boolean deleted; @ApiModelProperty(value = "描述")private java.lang.Object displayd; @ApiModelProperty(value = "编码") private java.lang.String factoryCode; @ApiModelProperty(value = "工厂坐标") private java.lang.String factoryCoordinate; @ApiModelProperty(value = "工厂名称") private java.lang.String factoryName; @TableId(value = "id",type = IdType.ASSIGN_ID) @ApiModelProperty(value = "主键ID") private java.lang.String id; private java.lang.String pid; @TableField(exist = false) private List<Factory> children;
FactoryMapper.java
/** * 获取工厂及其分厂 * @param factoryId * @return */ Factory getFactorys(String factoryId);
FactoryMapper.xml
<resultMap id="factoryResultMap" type="com.dcsyun.wqc.modules.factory.entity.Factory"> <id column="id" property="id"/> <collection property="children" column="id" select="getChildren"/> </resultMap> <select id="getFactorys" resultMap="factoryResultMap" parameterType="string"> select * from fty_factory where id = #{factoryId} and displayd = true and deleted = false </select> <select id="getChildren" resultMap="factoryResultMap"> select * from fty_factory where pid = #{factoryId} and displayd = true and deleted = false </select>