今天写公司项目中,遇到一个很奇怪的灵异事情
如图!
问题解决思路,先从controller ==> service ==> dao ==>mapper.xml 排查
问题发现在mapper.xml中有问题
我的原始*.xml是这样的写resultMap的
SELECT
a.areaid AS areaid, Right(a.areaNo, 4) AS aareaNo, a.registeredNo AS aregisteredNo,
a.name AS aname,concat_ws('_',n.name,a.addr) AS aaddr,
case a.DS when 'S' then '单月' else '双月' end AS ads,
COUNT(m.meterid) AS mmeterid,
SUM(m.TH_NUMBER) AS mTH_NUMBER,
SUM(m.S_NUMBER) AS mS_NUMBER,
t.n AS atnNumber,
a.reserved AS areserved,
to_char(GREATEST(m.TH_R_TIME),'YYYY-MM-DD hh:mm:ss') AS mTH_R_TIME,
to_char(a.lastsumday,'YYYY-MM-DD hh:mm:ss') AS alastsumday,
to_char(LEAST(m.starttime),'YYYY-MM-DD') AS mstarttime, a.description AS adescription
FROM ((ha_area a LEFT JOIN ha_meter m ON m.areaid=a.areaid)
LEFT JOIN ha_rgn n ON n.id=Left(a.areaNo, 1))
LEFT JOIN (SELECT Count(i.meterid) AS n,i.areaid AS areaid
FROM hav_meterinfo i WHERE i.状态!='正常' AND i.状态!='正确' AND i.状态!='建档'
AND i.状态!='集中器无返回' AND i.状态!='关阀' AND i.状态!='修改' AND i.状态!='已更正'
AND i.状态!='已更换' AND i.状态!='采集器无返回' AND i.状态 NOT LIKE '%用量异常%'
AND i.表号 >0
GROUP BY i.areaid) t ON t.areaid=a.areaid
group by a.areaid,a.areaNo,a.registeredNo,a.name,n.name,a.addr,a.DS,t.n,
a.reserved,m.TH_R_TIME,
a.lastsumday,m.starttime,a.description
估计在看的各位老鸟立马就能观察出来,没错就是你想的,
原因:
1.有中文 可能会出现乱码
2.查询语句和xml中的字段没有映射对
解决步骤,
1.去掉中文,把不需要的删掉;
2.把一些用聚合函数的取一个英文别名,和实体类的属性相等,没有的就给加上
最终解决完~
SELECT
a.areaid AS areaid, Right(a.areaNo, 4) AS aareaNo, a.registeredNo AS aregisteredNo,
a.name AS aname,concat_ws('_',n.name,a.addr) AS aaddr,
case a.DS when 'S' then '单月' else '双月' end AS ads,
COUNT(m.meterid) AS mmeterid,
SUM(m.TH_NUMBER) AS mTH_NUMBER,
SUM(m.S_NUMBER) AS mS_NUMBER,
t.n AS atnNumber,
a.reserved AS areserved,
to_char(GREATEST(m.TH_R_TIME),'YYYY-MM-DD hh:mm:ss') AS mTH_R_TIME,
to_char(a.lastsumday,'YYYY-MM-DD hh:mm:ss') AS alastsumday,
to_char(LEAST(m.starttime),'YYYY-MM-DD') AS mstarttime, a.description AS adescription
FROM ((ha_area a LEFT JOIN ha_meter m ON m.areaid=a.areaid)
LEFT JOIN ha_rgn n ON n.id=Left(a.areaNo, 1))
LEFT JOIN (SELECT Count(i.meterid) AS n,i.areaid AS areaid
FROM hav_meterinfo i WHERE i.状态!='正常' AND i.状态!='正确' AND i.状态!='建档'
AND i.状态!='集中器无返回' AND i.状态!='关阀' AND i.状态!='修改' AND i.状态!='已更正'
AND i.状态!='已更换' AND i.状态!='采集器无返回' AND i.状态 NOT LIKE '%用量异常%'
AND i.表号 >0
GROUP BY i.areaid) t ON t.areaid=a.areaid
group by a.areaid,a.areaNo,a.registeredNo,a.name,n.name,a.addr,a.DS,t.n,
a.reserved,m.TH_R_TIME,
a.lastsumday,m.starttime,a.description
另外补充一下,我在查询中,除了表还有视图一起用,可以把视图当场一个表用这里不多说,具体可以参看
Mybatis中视图的使用
如果博文中有什么不对的地方,请各位老鸟多多指教
如果上面用到的方法,没有帮到你的话,那就是你的类映射错了,仔细检查是在你当前的类映射还是,应该在别的类映射