13.6 Spider Middleware 的用法
阿新 • • 發佈:2020-07-17
<if>標籤
1.判斷非空或不等於
<if test="assessTypes!= null and assessTypes!='' "> AND FIND_IN_SET(t1.assess_type,#{assessTypes}) </if>
2.判斷等於某個固定字元
<if test='rankWay=="byAssessDate" and isDesc=="1" '> ORDER BY t1.assess_date DESC </if>
注意:這裡的主要區別在於
1.判斷不等於時雙引號在外,單引號在內
2.判斷等於時單引號在外,雙引號在內(此時雙引號標誌固定的字元)
<foreach>標籤
1.sql語句
<update id="makeConfig1ListApplying" > update c_u_custom_analysis_config_1 set is_use=1 where id IN <foreach collection="config1IdList" index="index" item="item" open="(" separator="," close=")"> #{item}</foreach> </update>
2.dao層
Integer makeConfig1ListApplying(@Param("config1IdList")List<Integer> config1IdList);
一對多<collection>標籤
1.sql語句
<resultMap id="customAnalysisConfig" type="com.pdzx.entity.CustomAnalysisConfig1"> <id column="analysis1Id" jdbcType="INTEGER"property="analysis1Id" /> <result column="company_id" property="companyId" /> <result column="assess_type" property="assessType" /> <result column="building_type" property="buildingType" /> <result column="special_type" property="specialType" /> <result column="analysis_name" property="analysisName" /> <result column="analysis_type" property="analysisType" /> <result column="x_axis_unit" property="xAxisUnit" /> <result column="y_axis_unit" property="yAxisUnit" /> <result column="desc_content" property="descContent" /> <result column="analysis_status" property="analysisStatus" /> <result column="is_use" property="isUse" /> <result column="orderby" property="orderby" /> <result column="create_time" property="createTime" /> <result column="create_user" property="createUser" /> <!--這裡的property就是CustomAnalysisConfig的 List<CustomAnalysisConfig2>屬性的名字 customAnalysisConfig2List--> <!--這裡的ofType就是CustomAnalysisConfig的 List<CustomAnalysisConfig2>屬性的單個CustomAnalysisConfig2--> <collection property="customAnalysisConfig2List" ofType="com.pdzx.entity.CustomAnalysisConfig2"> <result column="analysis2Id" property="analysis2Id" /> <result column="analysis1_id" property="analysis1Id" /> <result column="x_axis_data" property="xAxisData" /> <collection property="customAnalysisConfig3List" ofType="com.pdzx.entity.CustomAnalysisConfig3"> <result column="analysis3Id" property="analysis3Id" /> <result column="analysis2_id" property="analysis2Id" /> <result column="y_axis_dname" property="yAxisDname" /> <result column="y_axis_data" property="yAxisData" /> </collection> </collection> </resultMap> <select id="getCustomAnalysisConfigByTemplateId" parameterType="com.pdzx.entity.CustomAnalysisConfig1" resultMap="customAnalysisConfig"> SELECT t1.id AS analysis1Id, t1.company_id , t1.assess_type , t1.building_type , t1.special_type, t1.analysis_name , t1.analysis_type , t1.x_axis_unit , t1.y_axis_unit , t1.desc_content , t1.analysis_status , t1.is_use , t1.orderby , t1.create_time , t1.create_user , t2.id AS analysis2Id, t2.analysis1_id , t2.x_axis_data , t3.id AS analysis3Id, t3.analysis2_id , t3.y_axis_dname , t3.y_axis_data FROM c_u_custom_analysis_config_1 AS t1 JOIN c_u_custom_analysis_config_2 AS t2 ON t1.id=t2.analysis1_id JOIN c_u_custom_analysis_config_3 AS t3 ON t2.id=t3.analysis2_id WHERE t1.company_id=#{companyId} AND t1.assess_type=#{assessType} AND t1.building_type=#{buildingType} AND IFNULL(t1.special_type,'')=IFNULL(#{specialType},'') ORDER BY t1.orderby ASC </select>
2.實體類
CustomAnalysisConfig1
package com.pdzx.entity; import java.util.Date; import java.util.List; public class CustomAnalysisConfig1 { private Integer analysis1Id; private Integer id; private Integer companyId; private String assessType; private String buildingType; private String specialType; private String analysisName; private Byte analysisType; private String xAxisUnit; private String yAxisUnit; private String descContent; private Byte analysisStatus; private Byte isUse; private Short orderby; private Date createTime; private String createUser; private Date modifyTime; private String modifyUser; private List<CustomAnalysisConfig2> customAnalysisConfig2List; public Byte getIsUse() { return isUse; } public void setIsUse(Byte isUse) { this.isUse = isUse; } public List<CustomAnalysisConfig2> getCustomAnalysisConfig2List() { return customAnalysisConfig2List; } public void setCustomAnalysisConfig2List(List<CustomAnalysisConfig2> customAnalysisConfig2List) { this.customAnalysisConfig2List = customAnalysisConfig2List; } public Integer getAnalysis1Id() { return analysis1Id; } public void setAnalysis1Id(Integer analysis1Id) { this.analysis1Id = analysis1Id; } public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public Integer getCompanyId() { return companyId; } public void setCompanyId(Integer companyId) { this.companyId = companyId; } public String getAssessType() { return assessType; } public void setAssessType(String assessType) { this.assessType = assessType; } public String getBuildingType() { return buildingType; } public void setBuildingType(String buildingType) { this.buildingType = buildingType; } public String getSpecialType() { return specialType; } public void setSpecialType(String specialType) { this.specialType = specialType; } public String getAnalysisName() { return analysisName; } public void setAnalysisName(String analysisName) { this.analysisName = analysisName; } public Byte getAnalysisType() { return analysisType; } public void setAnalysisType(Byte analysisType) { this.analysisType = analysisType; } public String getxAxisUnit() { return xAxisUnit; } public void setxAxisUnit(String xAxisUnit) { this.xAxisUnit = xAxisUnit; } public String getyAxisUnit() { return yAxisUnit; } public void setyAxisUnit(String yAxisUnit) { this.yAxisUnit = yAxisUnit; } public String getDescContent() { return descContent; } public void setDescContent(String descContent) { this.descContent = descContent; } public Byte getAnalysisStatus() { return analysisStatus; } public void setAnalysisStatus(Byte analysisStatus) { this.analysisStatus = analysisStatus; } public Short getOrderby() { return orderby; } public void setOrderby(Short orderby) { this.orderby = orderby; } public Date getCreateTime() { return createTime; } public void setCreateTime(Date createTime) { this.createTime = createTime; } public String getCreateUser() { return createUser; } public void setCreateUser(String createUser) { this.createUser = createUser; } public Date getModifyTime() { return modifyTime; } public void setModifyTime(Date modifyTime) { this.modifyTime = modifyTime; } public String getModifyUser() { return modifyUser; } public void setModifyUser(String modifyUser) { this.modifyUser = modifyUser; } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append(getClass().getSimpleName()); sb.append(" ["); sb.append("Hash = ").append(hashCode()); sb.append(", id=").append(id); sb.append(", companyId=").append(companyId); sb.append(", assessType=").append(assessType); sb.append(", buildingType=").append(buildingType); sb.append(", specialType=").append(specialType); sb.append(", analysisName=").append(analysisName); sb.append(", analysisType=").append(analysisType); sb.append(", xAxisUnit=").append(xAxisUnit); sb.append(", yAxisUnit=").append(yAxisUnit); sb.append(", descContent=").append(descContent); sb.append(", analysisStatus=").append(analysisStatus); sb.append(", orderby=").append(orderby); sb.append(", createTime=").append(createTime); sb.append(", createUser=").append(createUser); sb.append(", modifyTime=").append(modifyTime); sb.append(", modifyUser=").append(modifyUser); sb.append("]"); return sb.toString(); } }
CustomAnalysisConfig2
package com.pdzx.entity; import java.util.List; public class CustomAnalysisConfig2 { private Integer analysis2Id; private Integer id; private Integer analysis1Id; private String xAxisData; private List<CustomAnalysisConfig3> customAnalysisConfig3List; public List<CustomAnalysisConfig3> getCustomAnalysisConfig3List() { return customAnalysisConfig3List; } public void setCustomAnalysisConfig3List(List<CustomAnalysisConfig3> customAnalysisConfig3List) { this.customAnalysisConfig3List = customAnalysisConfig3List; } public Integer getAnalysis2Id() { return analysis2Id; } public void setAnalysis2Id(Integer analysis2Id) { this.analysis2Id = analysis2Id; } public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public Integer getAnalysis1Id() { return analysis1Id; } public void setAnalysis1Id(Integer analysis1Id) { this.analysis1Id = analysis1Id; } public String getxAxisData() { return xAxisData; } public void setxAxisData(String xAxisData) { this.xAxisData = xAxisData; } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append(getClass().getSimpleName()); sb.append(" ["); sb.append("Hash = ").append(hashCode()); sb.append(", id=").append(id); sb.append(", analysis1Id=").append(analysis1Id); sb.append(", xAxisData=").append(xAxisData); sb.append("]"); return sb.toString(); } }
CustomAnalysisConfig3
package com.pdzx.entity; public class CustomAnalysisConfig3 { private Integer analysis3Id; private Integer id; private Integer analysis2Id; private String yAxisDname; private String yAxisData; public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public Integer getAnalysis2Id() { return analysis2Id; } public void setAnalysis2Id(Integer analysis2Id) { this.analysis2Id = analysis2Id; } public String getyAxisDname() { return yAxisDname; } public void setyAxisDname(String yAxisDname) { this.yAxisDname = yAxisDname; } public String getyAxisData() { return yAxisData; } public void setyAxisData(String yAxisData) { this.yAxisData = yAxisData; } public Integer getAnalysis3Id() { return analysis3Id; } public void setAnalysis3Id(Integer analysis3Id) { this.analysis3Id = analysis3Id; } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append(getClass().getSimpleName()); sb.append(" ["); sb.append("Hash = ").append(hashCode()); sb.append(", id=").append(id); sb.append(", analysis2Id=").append(analysis2Id); sb.append(", yAxisDname=").append(yAxisDname); sb.append(", yAxisData=").append(yAxisData); sb.append("]"); return sb.toString(); } }
3.dao層
List<CustomAnalysisConfig1> getCustomAnalysisConfigByTemplateId(CustomAnalysisConfig1 customAnalysisConfig1 );
一對一<association>標籤
1.sql語句
<!--手機端下載模板--> <resultMap id="templateInfos" type="com.pdzx.po.PparamCategory"> <id column="category_id" jdbcType="VARCHAR" property="id" /> <result column="categoryName" jdbcType="VARCHAR" property="name" /> <collection property="paramGroup" ofType="com.pdzx.po.PparamGroup"> <id column="group_id" jdbcType="VARCHAR" property="id" /> <result column="groupName" jdbcType="VARCHAR" property="name" /> <result column="category_id" jdbcType="VARCHAR" property="categoryId" /> <collection property="paramItem" ofType="com.pdzx.po.PparamItem"> <id column="item_id" jdbcType="VARCHAR" property="id" /> <result column="itemName" jdbcType="VARCHAR" property="name" /> <result column="group_id" jdbcType="VARCHAR" property="groupId" /> <result column="additemName" jdbcType="VARCHAR" property="additemName" /> <result column="remark" jdbcType="VARCHAR" property="remark" /> <!--這裡PparamItem和BTemplateRelation同級是一對一的關係,即一個物件內包含一個物件--> <association property="bTemplateRelation" javaType="com.pdzx.po.BTemplateRelation"> <id column="templ_rela_id" jdbcType="VARCHAR" property="id" /> </association> </collection> </collection> </resultMap> <select id="downTempl" parameterType="map" resultMap="templateInfos"> select t1.category_id, t2.name categoryName, t1.group_id, t3.name groupName, t1.item_id, t4.name itemName, t1.remark, fun_param_idtoname(t1.remark, 'p_param_additem') additemName, t1.id templ_rela_id from b_template_relation t1 left join p_param_category t2 on t2.category_id=t1.category_id left join p_param_group t3 on t3.group_id=t1.group_id left join p_param_item t4 on t4.item_id=t1.item_id where t1.template_id=#{templateId} and t1.assess_type =#{assessType} and t1.building_type = #{buildingType} and t1.flag = #{flag} and ifnull(t1.special_type, '') = ifnull(#{specialType}, '') order by t1.rowindex,t2.category_id,t3.group_id,t4.item_id </select>
2.實體類
PparamItem
package com.pdzx.po; /** * * @author lyz * p_param_item資料表 * 三級目錄三級分類 */ public class PparamItem { private String id; private String name; private Integer groupId; private String remark; private Integer orderby; private PparamGroup paramGroup; private BTemplateRelation bTemplateRelation; private String additemName; private String templateId; public String getTemplateId() { return templateId; } public void setTemplateId(String templateId) { this.templateId = templateId; } public String getAdditemName() { return additemName; } public void setAdditemName(String additemName) { this.additemName = additemName; } public BTemplateRelation getbTemplateRelation() { return bTemplateRelation; } public void setbTemplateRelation(BTemplateRelation bTemplateRelation) { this.bTemplateRelation = bTemplateRelation; } /** * @return the id */ public String getId() { return id; } /** * @param id the id to set */ public void setId(String id) { this.id = id; } /** * @return the name */ public String getName() { return name; } /** * @param name the name to set */ public void setName(String name) { this.name = name; } /** * @return the groupId */ public Integer getGroupId() { return groupId; } /** * @param groupId the groupId to set */ public void setGroupId(Integer groupId) { this.groupId = groupId; } /** * @return the remark */ public String getRemark() { return remark; } /** * @param remark the remark to set */ public void setRemark(String remark) { this.remark = remark; } /** * @return the orderby */ public Integer getOrderby() { return orderby; } /** * @param orderby the orderby to set */ public void setOrderby(Integer orderby) { this.orderby = orderby; } /** * @return the paramGroup */ public PparamGroup getParamGroup() { return paramGroup; } /** * @param paramGroup the paramGroup to set */ public void setParamGroup(PparamGroup paramGroup) { this.paramGroup = paramGroup; } @Override public String toString() { return "PparamItem [id=" + id + ", name=" + name + ", groupId=" + groupId + ", remark=" + remark + ", orderby=" + orderby + ", paramGroup=" + paramGroup + ", bTemplateRelation=" + bTemplateRelation + "]"; } }
BTemplateRelation
package com.pdzx.po; import java.util.List; /** * * @author lyz 模板關聯三級分類 * @param */ public class BTemplateRelation { private String id; private Integer templateId; private Integer groupId; private Integer categoryId; private Integer itemId; private String flag; private String remark; private String buildingType; private String assessType; private BaseTemple bBaseTemplate; private PparamCategory paramCategory; private PparamGroup paramGroup; private PparamItem paramItem; private String remarkName; private BMrqAssessRes bmrqAssessRes; private List<BTemplateRelationDetail> relaDetailList; private List<QRRelationDetail> qrRelationDetail; private List<IFTemplateRela> ifRelaDetailList; public List<IFTemplateRela> getIfRelaDetailList() { return ifRelaDetailList; } public void setIfRelaDetailList(List<IFTemplateRela> ifRelaDetailList) { this.ifRelaDetailList = ifRelaDetailList; } /* * 安全文明 */ private SCActualScore scActualScore; private List<SCTemplateRelationDetail> sctempRelaDetail; private BShouldScore shouldscore; /* * 簡報圖片 */ private Images imagesList; public String getRemarkName() { return remarkName; } public void setRemarkName(String remarkName) { this.remarkName = remarkName; } public Images getImagesList() { return imagesList; } public void setImagesList(Images imagesList) { this.imagesList = imagesList; } public BShouldScore getShouldscore() { return shouldscore; } public void setShouldscore(BShouldScore shouldscore) { this.shouldscore = shouldscore; } public SCActualScore getScActualScore() { return scActualScore; } public void setScActualScore(SCActualScore scActualScore) { this.scActualScore = scActualScore; } public List<SCTemplateRelationDetail> getSctempRelaDetail() { return sctempRelaDetail; } public void setSctempRelaDetail(List<SCTemplateRelationDetail> sctempRelaDetail) { this.sctempRelaDetail = sctempRelaDetail; } public List<QRRelationDetail> getQrRelationDetail() { return qrRelationDetail; } public void setQrRelationDetail(List<QRRelationDetail> qrRelationDetail) { this.qrRelationDetail = qrRelationDetail; } public String getAssessType() { return assessType; } public void setAssessType(String assessType) { this.assessType = assessType; } public List<BTemplateRelationDetail> getRelaDetailList() { return relaDetailList; } public void setRelaDetailList(List<BTemplateRelationDetail> relaDetailList) { this.relaDetailList = relaDetailList; } public BaseTemple getbBaseTemplate() { return bBaseTemplate; } public void setbBaseTemplate(BaseTemple bBaseTemplate) { this.bBaseTemplate = bBaseTemplate; } public String getBuildingType() { return buildingType; } public void setBuildingType(String buildingType) { this.buildingType = buildingType; } public BMrqAssessRes getBmrqAssessRes() { return bmrqAssessRes; } public void setBmrqAssessRes(BMrqAssessRes bmrqAssessRes) { this.bmrqAssessRes = bmrqAssessRes; } public PparamCategory getParamCategory() { return paramCategory; } public void setParamCategory(PparamCategory paramCategory) { this.paramCategory = paramCategory; } public PparamGroup getParamGroup() { return paramGroup; } public void setParamGroup(PparamGroup paramGroup) { this.paramGroup = paramGroup; } public PparamItem getParamItem() { return paramItem; } public void setParamItem(PparamItem paramItem) { this.paramItem = paramItem; } public Integer getTemplateId() { return templateId; } public void setTemplateId(Integer templateId) { this.templateId = templateId; } public String getId() { return id; } public void setId(String id) { this.id = id; } public String getFlag() { return flag; } public void setFlag(String flag) { this.flag = flag; } public String getRemark() { return remark; } public void setRemark(String remark) { this.remark = remark; } public Integer getGroupId() { return groupId; } public void setGroupId(Integer groupId) { this.groupId = groupId; } public Integer getCategoryId() { return categoryId; } public void setCategoryId(Integer categoryId) { this.categoryId = categoryId; } public Integer getItemId() { return itemId; } public void setItemId(Integer itemId) { this.itemId = itemId; } @Override public String toString() { return "BTemplateRelation [id=" + id + ", templateId=" + templateId + ", groupId=" + groupId + ", categoryId=" + categoryId + ", itemId=" + itemId + ", flag=" + flag + ", remark=" + remark + ", buildingType=" + buildingType + ", bBaseTemplate=" + bBaseTemplate + ", paramCategory=" + paramCategory + ", paramGroup=" + paramGroup + ", paramItem=" + paramItem + ", bmrqAssessRes=" + bmrqAssessRes + ", relaDetailList=" + relaDetailList + "]"; } }
dao層
List<PparamCategory> downTempl(Map<String, Object> map);
useGeneratedKeys用法
當useGeneratedKeys為true時,如果插入的表的id以自增列為主鍵時,將會把該自增id返回(注意是返回到該物件的屬性中)
1.sql
<insert id="addOneCustomAnalysisConfig1" parameterType="com.pdzx.entity.CustomAnalysisConfig1" useGeneratedKeys="true" keyProperty="id"> insert into c_u_custom_analysis_config_1 ( company_id, assess_type, building_type, <if test="specialType != null and specialType!='' "> special_type, </if> analysis_name, analysis_type, x_axis_unit, y_axis_unit, <if test="descContent != null and descContent!='' "> desc_content, </if> analysis_status, orderby, create_time, create_user ) values ( #{companyId}, #{assessType}, #{buildingType}, <if test="specialType != null and specialType!='' "> #{specialType}, </if> #{analysisName}, #{analysisType}, #{xAxisUnit}, #{yAxisUnit}, <if test="descContent != null and descContent!='' "> #{descContent}, </if> #{analysisStatus}, #{orderby}, NOW(), #{createUser} ) </insert>
實體類
package com.pdzx.entity; import java.util.Date; import java.util.List; public class CustomAnalysisConfig1 { private Integer analysis1Id; private Integer id; private Integer companyId; private String assessType; private String buildingType; private String specialType; private String analysisName; private Byte analysisType; private String xAxisUnit; private String yAxisUnit; private String descContent; private Byte analysisStatus; private Byte isUse; private Short orderby; private Date createTime; private String createUser; private Date modifyTime; private String modifyUser; private List<CustomAnalysisConfig2> customAnalysisConfig2List; public Byte getIsUse() { return isUse; } public void setIsUse(Byte isUse) { this.isUse = isUse; } public List<CustomAnalysisConfig2> getCustomAnalysisConfig2List() { return customAnalysisConfig2List; } public void setCustomAnalysisConfig2List(List<CustomAnalysisConfig2> customAnalysisConfig2List) { this.customAnalysisConfig2List = customAnalysisConfig2List; } public Integer getAnalysis1Id() { return analysis1Id; } public void setAnalysis1Id(Integer analysis1Id) { this.analysis1Id = analysis1Id; } public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public Integer getCompanyId() { return companyId; } public void setCompanyId(Integer companyId) { this.companyId = companyId; } public String getAssessType() { return assessType; } public void setAssessType(String assessType) { this.assessType = assessType; } public String getBuildingType() { return buildingType; } public void setBuildingType(String buildingType) { this.buildingType = buildingType; } public String getSpecialType() { return specialType; } public void setSpecialType(String specialType) { this.specialType = specialType; } public String getAnalysisName() { return analysisName; } public void setAnalysisName(String analysisName) { this.analysisName = analysisName; } public Byte getAnalysisType() { return analysisType; } public void setAnalysisType(Byte analysisType) { this.analysisType = analysisType; } public String getxAxisUnit() { return xAxisUnit; } public void setxAxisUnit(String xAxisUnit) { this.xAxisUnit = xAxisUnit; } public String getyAxisUnit() { return yAxisUnit; } public void setyAxisUnit(String yAxisUnit) { this.yAxisUnit = yAxisUnit; } public String getDescContent() { return descContent; } public void setDescContent(String descContent) { this.descContent = descContent; } public Byte getAnalysisStatus() { return analysisStatus; } public void setAnalysisStatus(Byte analysisStatus) { this.analysisStatus = analysisStatus; } public Short getOrderby() { return orderby; } public void setOrderby(Short orderby) { this.orderby = orderby; } public Date getCreateTime() { return createTime; } public void setCreateTime(Date createTime) { this.createTime = createTime; } public String getCreateUser() { return createUser; } public void setCreateUser(String createUser) { this.createUser = createUser; } public Date getModifyTime() { return modifyTime; } public void setModifyTime(Date modifyTime) { this.modifyTime = modifyTime; } public String getModifyUser() { return modifyUser; } public void setModifyUser(String modifyUser) { this.modifyUser = modifyUser; } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append(getClass().getSimpleName()); sb.append(" ["); sb.append("Hash = ").append(hashCode()); sb.append(", id=").append(id); sb.append(", companyId=").append(companyId); sb.append(", assessType=").append(assessType); sb.append(", buildingType=").append(buildingType); sb.append(", specialType=").append(specialType); sb.append(", analysisName=").append(analysisName); sb.append(", analysisType=").append(analysisType); sb.append(", xAxisUnit=").append(xAxisUnit); sb.append(", yAxisUnit=").append(yAxisUnit); sb.append(", descContent=").append(descContent); sb.append(", analysisStatus=").append(analysisStatus); sb.append(", orderby=").append(orderby); sb.append(", createTime=").append(createTime); sb.append(", createUser=").append(createUser); sb.append(", modifyTime=").append(modifyTime); sb.append(", modifyUser=").append(modifyUser); sb.append("]"); return sb.toString(); } }
dao層
Integer addOneCustomAnalysisConfig1(CustomAnalysisConfig1 customAnalysisConfig1);
用法
//新增一條定製分析 @Transactional public Integer addOneCustomAnalysisConfig(CustomAnalysisConfig1 customAnalysisConfig1) { //CustomAnalysisConfig1 customAnalysisConfig1 = customAnalysisConfig.getCustomAnalysisConfig1(); //配置1表插入資料後的返回該條資料主鍵 Integer count1 = customAnalysisConfig1Service.addOneCustomAnalysisConfig1(customAnalysisConfig1); //獲取自增主鍵 Integer analysis1Id = customAnalysisConfig1.getId(); List<CustomAnalysisConfig2> customAnalysisConfig2List = customAnalysisConfig1.getCustomAnalysisConfig2List(); for (CustomAnalysisConfig2 customAnalysisConfig2:customAnalysisConfig2List){ //配置1表插入資料後的返回主鍵作為關聯id存入配置2表的analysis1_id欄位 customAnalysisConfig2.setAnalysis1Id(analysis1Id); //配置2表插入資料後的返回該條資料主鍵 Integer count2 = customAnalysisConfig2Service.addOneCustomAnalysisConfig2(customAnalysisConfig2); Integer analysis2Id=customAnalysisConfig2.getId(); List<CustomAnalysisConfig3> customAnalysisConfig3List = customAnalysisConfig2.getCustomAnalysisConfig3List(); for (CustomAnalysisConfig3 customAnalysisConfig3:customAnalysisConfig3List){ //配置2表插入資料後的返回主鍵作為關聯id存入配置3表的analysis2_id欄位 customAnalysisConfig3.setAnalysis2Id(analysis2Id); Integer analysis3Id = customAnalysisConfig3Service.addOneCustomAnalysisConfig3(customAnalysisConfig3); } } return analysis1Id; }