mybatis 配置association、collection 使用样例
<association property="next" column="nextId"javaType="cn.web.model.Machine" select="getById" /><collection property="nextIPs" javaType="ArrayList" column="nextIPIds"ofType="cn.web.model.MachineConfig"
·
opjo
public class MachineConfig {
private Long id;
private String ip;
private String Name;
private String nextId;
private Machine next;
private String nextIPId;
private List<MachineConfig> nextIps;
private Integer state ;
}
public class Machine {
private Long id;
private String Name;
private Integer state ;
}
Mapper.xml层
<!-- 机器配置 -->
<resultMap id="MachineConfigResult" type="cn.web.model.MachineConfig">
<id column="Id" property="id" />
<result column="IP" property="ip" />
<result column="Name" property="Name" />
<result column="nextId" property="nextId" />
<result column="nextIPId" property="nextIPId" />
<result column="state" property="state" />
<association property="next" column="nextId" javaType="cn.web.model.Machine" select="getById" />
<collection property="nextIPs" javaType="ArrayList" column="nextIPIds" ofType="cn.web.model.MachineConfig" select="selectMachineConfigByids"/>
</resultMap>
<!-- 机器分组 -->
<resultMap id="MachineResult" type="cn.web.model.Machine">
<id column="Id" property="id" />
<result column="Name" property="Name" />
<result column="state" property="state" />
</resultMap>
<select id="getMachineConfigInfo" resultMap="MachineConfigResult">
SELECT * FROM TMachineConfig t order by t.id
</select>
<select id="getById" parameterType="java.lang.Long" resultMap="MachineResult">
SELECT * FROM TMachineHierarchyConfig where id=#{nextId}
</select>
<!-- 查询机器列表根据ids -->
<select id="selectMachineConfigByids" parameterType = "java.lang.String" resultMap="MachineConfigResult">
SELECT * FROM TMachineConfigInfo t WHERE FIND_IN_SET(#{nextIPIds}, t.id) order by t.id
</select>
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)