Mybatis 动态标签 if

<insert id=”insert2 ” useGeneratedKeys=” true keyProperty
		insert into sys user(
		user_name, user_password,
		<if test=”userEmail != null and userEmail != ””>
		useremail ,
		</if>
		userinfo, headimg, createtime)
		values(
		#{userName}, #{userPassword},
		<if test=”userEmail != null and userEmail != ””>
		#{userEmail} ,
		</if>
		#{userinfo}, #{headimg,]dbcType=BLOB} ,
		#{createTime, jdbcType= TIMESTAMP})
</ insert>

或者 条件拼接

<where>
            <!--管理单位 -->
            <if test="provinceLevelOrgCode !=null and provinceLevelOrgCode !=''">
              and pb.province_level_org_code=#{provinceLevelOrgCode}
            </if>

             <!--站等级 -->
            <if test="stationLevelType !=null and stationLevelType !=''">
                and pa.station_level_type=#{stationLevelType}
            </if>

            <!--厂商 -->
            <if test="manufactureName !=null and manufactureName !=''">
                and pa.manufacture_name=#{manufactureName}
            </if>

            <!--产权单位 找不见-->
            <if test="">
                and
            </if>

            <!-- 运维单位 -->
            <if test="provinceOmOrgName !=null and provinceOmOrgName !=''">
                and pb.province_om_org_name=#{provinceOmOrgName}
            </if>

            <!-- 时间段  开始时间 -->
            <if test="stakeDateStart !=null">
                and pb.stake_date &gt;=#{stakeDateStart}
            </if>

            <!-- 时间段  结束时间 -->
            <if test="stakeDateEnd !=null">
                and pb.stake_date &lt;=#{stakeDateEnd}
            </if>
               and pa.station_uuid=pb.station_uuid
        </where>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章