<selectid="queryOddList"resultType="java.util.Map" > select d.`name` as deviceName , d.`id` as deviceId ,d.`code` as deviceCode ,d.`outdoors_address` as outdoorsAddress ,d.type as deviceType,d.sub_type as deviceSubType LEFT JOIN `device_position` as dp on d.`id` = dp.`id` where 1=1 <iftest="oltId != null "> and o.`olt_id` = #{oltId}</if> <iftest="ponPort != null "> and o.`pon_port` = #{ponPort}</if> </select>
总体来说与JSON差别不大,不需要在xml中写参数类型,只需要写返回类型(resultType)。
where 1=1
如果下面的参数全都是需要判断的,我们需要1=1来应对没有一个参数存在的情况
对数字判空写if
1
<iftest="deviceId != null "> and d.`id` = #{deviceId}</if>
对字符串判空写if
1
<iftest="username != null and username != ''">AND username = #{username}</if>
对单字符写if
方法1:
1
<iftest="resType != null and resType == '1'.toString() ">
<iftest="deviceIds != null and deviceIds != ''"> and e.pwr_device_id in (${deviceIds})</if> <iftest='haveResponsibleStaff == "是"'> and du.sys_user_id is not null</if>
<updateid="updateCtoCutoverMark"> UPDATE cto_cutover_serv_prod_itf SET `STS` = 3, `STS_DATE` = NOW() WHERE `CUTOVER_ID` = #{cutoverId} AND `USER_ACC_NBR` IN <foreachcollection="userAccNbrList"item="userAccNbr"open="("separator=","close=")"> #{userAccNbr} </foreach> AND sts IN (1, 8) </update>
select dev.*, dev.name dpName, dev.id dpId, (select name from spc_station st where st.id = dev.station_id) as stationName, (select name from spc_room sr where sr.id =dev.room_id ) as roomName, (select e.name from spc_exch e where e.id = exch_id) exch_name ....
一对一、一对多、多对多(注解与XML)
一对一,一对多,多对多总结
关于默认生成的selectVoList其中的标签
实体类添加额外字段
1 2 3 4 5 6 7
/** 局站id */ @Excel(name = "局站id") private Long stationId;