<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>标签

foreach元素的属性主要有item,index,collection,open,separator,close。

  • item:集合中元素迭代时的别名,该参数为必选。
  • index:在list和数组中,index是元素的序号,在map中,index是元素的key,该参数可选
  • open:foreach代码的开始符号,一般是(和close=")"合用。常用在in(),values()时。该参数可选
  • separator:元素之间的分隔符,例如在in()的时候,separator=","会自动在元素中间用“,“隔开,避免手动输入逗号导致sql错误,如in(1,2,)这样。该参数可选。
  • close: foreach代码的关闭符号,一般是)和open="("合用。常用在in(),values()时。该参数可选。
  • collection: 要做foreach的对象,作为入参时,List对象默认用"list"代替作为键,数组对象有"array"代替作为键,Map对象没有默认的键。当然在作为入参时可以使用@Param("keyName")来设置键,设置keyName后,list,array将会失效。 除了入参这种情况外,还有一种作为参数对象的某个字段的时候。举个例子:如果User有属性List ids。入参是User对象,那么这个collection = "ids".如果User有属性Ids ids;其中Ids是个对象,Ids有个属性List id;入参是User对象,那么collection = "ids.id"

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; 
    }

 

发布评论

分享到:

IT源码网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!

mybatis自动生成代码插件mybatis-generator使用流程(亲测可用)讲解
你是第一个吃螃蟹的人
发表评论

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。