项目场景:
项目场景:自建站站点,访问量,访问人数统计
问题描述
后端接收到对象有参数,mybatis识别后一直是null
c.h.w.d.V.sumsyslist_COUNT : ==> Parameters: 2022-05-29(String), null,
原因分析:
<if test="ldatend = null and ldatestart = null">
sql太长中间重复部分,参数表达式有误
解决方案:
mybatis中sql 标签判断不规范 '='改为'=='
<if test="ldatend != null and ldatend != ''">
and left(t1.ldate, 10) <= left(#{ldatend}, 10)
</if>
出错场景复现:
SELECT ta1.sys,total,IFNULL(totalM,0) totalM,IFNULL(totalD,0) totalD,IFNULL(totalP,0) totalP,IFNULL(totalMP,0) totalMP,IFNULL(totalDP,0) totalDP FROM (SELECT t1.sys,count(0) total FROM `ct_visitlogs` t1
<where>
1=1
<if test="ldatestart != null and ldatestart != ''">
and left(t1.ldate, 10) >= left(#{ldatestart}, 10)
</if>
<if test="ldatend != null and ldatend != ''">
and left(t1.ldate, 10) <= left(#{ldatend}, 10)
</if>
<if test="whe != null and whe != ''">
and 2=2 and #{whe}
</if>
<if test="lacc != null and lacc != ''">
and 3=3 and #{lacc}
</if>
</where>
group by t1.sys ) ta1
left join (SELECT t2.sys,count(0) totalM FROM `ct_visitlogs` t2
<where>
1=1
<if test="ldatestart != null and ldatestart != ''">
and left(t2.ldate, 10) >= left(#{ldatestart}, 10)
</if>
<if test="ldatend != null and ldatend != ''">
and left(t2.ldate, 10) <= left(#{ldatend}, 10)
</if>
<if test="ldatend == null and ldatestart == null">
and left(t2.ldate, 7) = left(NOW(), 7)
</if>
</where>
group by t2.sys) ta2 on ta2.sys =ta1.sys
left join (SELECT t2.sys,count(0) totalD FROM `ct_visitlogs` t2
<where>
1=1
<if test="ldatestart != null and ldatestart != ''">
and left(t2.ldate, 10) >= left(#{ldatestart}, 10)
</if>
<if test="ldatend != null and ldatend != ''">
and left(t2.ldate, 10) <= left(#{ldatend}, 10)
</if>
<if test="ldatend == null and ldatestart == null">
and left(t2.ldate, 10) = left(NOW(), 10)
</if>
</where>
group by t2.sys) ta3 on ta3.sys =ta1.sys
left join (select count(0) totalP,sys from (SELECT sys,t1.ip,count(0) FROM `ct_visitlogs` t1 where sys=any(SELECT t1.sys FROM `ct_visitlogs` t1
<where>
1=1
<if test="ldatestart != null and ldatestart != ''">
and left(t1.ldate, 10) >= left(#{ldatestart}, 10)
</if>
<if test="ldatend != null and ldatend != ''">
and left(t1.ldate, 10) <= left(#{ldatend}, 10)
</if>
</where>
) group by t1.ip) t group by sys) ta4 on ta4.sys =ta1.sys
left join (select count(0) totalMP,sys from (SELECT sys,t1.ip,count(0) FROM `ct_visitlogs` t1 where sys=any(SELECT t1.sys FROM `ct_visitlogs` t1
<where>
1=1
<if test="ldatestart != null and ldatestart != ''">
and left(t1.ldate, 10) >= left(#{ldatestart}, 10)
</if>
<if test="ldatend != null and ldatend != ''">
and left(t1.ldate, 10) <= left(#{ldatend}, 10)
</if>
<if test="ldatend == null and ldatestart == null">
and left(t1.ldate, 7) = left(NOW(), 7)
</if>
</where>
) group by t1.ip) t group by sys) ta5 on ta5.sys =ta1.sys
left join (select count(0) totalDP,sys from (SELECT sys,t1.ip,count(0) FROM `ct_visitlogs` t1 where sys=any(SELECT t1.sys FROM `ct_visitlogs` t1
<where>
1=1
<if test="ldatestart != null and ldatestart != ''">
and left(t1.ldate, 10) >= left(#{ldatestart}, 10)
</if>
<if test="ldatend != null and ldatend != ''">
and left(t1.ldate, 10) <= left(#{ldatend}, 10)
</if>
<if test="ldatend == null and ldatestart == null">
and left(t1.ldate, 10) = left(NOW(), 10)
</if>
</where>
) group by t1.ip) t group by sys) ta6 on ta6.sys =ta1.sys