话不多说,直接结合实际应用场景来说明List<Map<String, List>>用法:
1.PO层
//存储项目的不同类型、不同阶段 所对应到的 不同sheet页的category列表
public class ProjectCategoryRelationModel {
//项目ID
private Integer projectId;
//类型
private String type;
//阶段名
private String phase;
//包含的sheet及其category列表
private Map<String, List<String>> sheetCategory = new HashMap<>();
public ModuleItemRelationModel(){}
2.DAO层
//注意用@Param区分每一个入参
void insertProjectCategoryRelationModel(@Param("userId") Integer userId, @Param("itemRelation") List<ProjectCategoryRelationModel> projectCategoryRelationModels);
3.Mybatis的xml写法
tips:遍历map的核心是遍历key获得value
<insert id="insertProjectCategoryRelationModel">
insert into SGO_CHECK_LIST_CONF (
ID,
FK_SGO_PROJECT_ID,
TYPE,
PHASE,
SHEET_NAME,
CATEGORY,
CREATE_TIME,
CREATE_USER,
STATE
)
SELECT SEQ_SGO_CHECK_LIST_CONF_ID.NEXTVAL,A.* FROM (
<foreach collection="itemRelation" item="item" index="index" separator="union all">
<foreach collection="item.sheetCategory.keys" item="itemKey" index="sheetIndex" separator="union all">
<foreach collection="item.sheetCategory[itemKey]" item="categoryList" index="categoryIndex" separator="union all">
SELECT
#{item.projectId,jdbcType=INTEGER},
#{item.type,jdbcType=VARCHAR},
#{item.phase,jdbcType=VARCHAR},
#{itemKey,jdbcType=VARCHAR},
#{categoryList,jdbcType=VARCHAR},
SYSDATE,
#{userId,jdbcType=INTEGER},
1
FROM dual
</foreach>
</foreach>
</foreach>
) A
</insert>