二级级联:
一:新建两个Bean
父级:
/*** @Description 数据字典* @Author WangKun* @Date 2023/7/25 10:15* @Version*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName("HW_DICT_KEY")
public class DictKey implements Serializable {private static final long serialVersionUID = 1L;@TableId(value = "id", type = IdType.AUTO)private String id;private Timestamp created;private Timestamp modified;private String dictKey;private String dictName;private List<DictItemValue> dictItemValues;
}
子级:
/*** @Description 数据字段* @Author WangKun* @Date 2023/7/25 10:15* @Version*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName("HW_DICT_ITEM_VALUE")
public class DictItemValue implements Serializable {private static final long serialVersionUID = 1L;@TableId(value = "id", type = IdType.AUTO)private String id;private Timestamp created;private Timestamp modified;private String dictKey;private String itemCode;private String itemName;}
mybatis 或者 mybatisplus
<mapper namespace="com.module.dict.mapper.DictMapper"><resultMap id="BaseResultMap" type="com.module.dict.bean.DictKey"><result column="dictKey" property="dictKey" jdbcType="VARCHAR"/><result column="dictName" property="dictName" jdbcType="VARCHAR"/><collection property="dictItemValues" ofType="com.module.dict.bean.DictItemValue"><result column="dictKey" property="dictKey" jdbcType="VARCHAR"/><result column="itemName" property="itemName" jdbcType="VARCHAR"/><result column="itemCode" property="itemCode" jdbcType="VARCHAR"/></collection></resultMap><select id="queryAllDict" resultMap="BaseResultMap">SELECTt1.id,t1.dict_name AS 'dictName',t1.dict_key AS 'dictKey',t2.item_name AS 'itemName',t2.item_code AS 'itemCode'FROMhw_dict_key t1JOIN hw_dict_item_value t2 ON t2.dict_key = t1.dict_key</select></mapper>
三级级联:
新建三个Bean
父级:
/*** @Description 数据字典* @Author WangKun* @Date 2023/7/25 10:15* @Version*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName("HW_DICT")
public class Dict implements Serializable {private static final long serialVersionUID = 1L;@TableId(value = "id", type = IdType.AUTO)private String id;private String key;private String name;private String parentId;private List<DictValue> children;
}
子级:
/*** @Description 数据字典* @Author WangKun* @Date 2023/7/25 10:15* @Version*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName("HW_DICT_VALUE")
public class DictValue implements Serializable {private static final long serialVersionUID = 1L;@TableId(value = "id", type = IdType.AUTO)private String id;private String key;private String name;private String parentId;private List<DictValueItem> children;
}
孙级:
/*** @Description 数据字典* @Author WangKun* @Date 2023/7/25 10:15* @Version*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName("HW_DICT_VALUE_ITEM")
public class DictValueItem implements Serializable {private static final long serialVersionUID = 1L;@TableId(value = "id", type = IdType.AUTO)private String id;private String key;private String name;private String parentId;
}
mybatis 或者 mybatisplus
<mapper namespace="com.module.dict.mapper.DictMapper"><resultMap id="BaseResultMap" type="com.module.dict.bean.Dict"><id column="id" property="id"></id><result column="name" property="name"></result><result column="key" property="key"></result><collection property="children" ofType="com.module.dict.bean.DictValue"><id column="value_id" property="id"></id><result column="value_name" property="name"></result><result column="value_key" property="key"></result><collection property="children" ofType="com.module.dict.bean.DictValueItem"><id column="item_id" property="id"></id><result column="item_name" property="name"></result><result column="item_key" property="key"></result></collection></collection></resultMap><select id="queryAllDict" resultMap="BaseResultMap">selectt1.id,t1.name,t1.key,t2.id value_id,t2.name value_name,t2.key value_key,t3.id item_id,t3.name item_name,t3.key item_keyfrom hw_dict t1join hw_dict_value t2 on t2.parent_id = t1.idjoin hw_dict_value_item t3 on t3.parent_id = t2.id
-- where p.parent_id = '0'</select></mapper>