关于mybatis条件查询 报错:元素内容必须由格式正确的字符数据或标记组成

原查询
select sum(case when age<=16 then 1 else 0 end ) age1,
sum(case when age>16 and age<=25 then 1 else 0 end ) age2,
sum(case when age>25 and age<=35 then 1 else 0 end ) age3,
sum(case when age>35 and age<=45 then 1 else 0 end ) age4,
sum(case when age>45 and age<=55 then 1 else 0 end ) age5,
sum(case when age>55 and age<=65 then 1 else 0 end ) age6,
sum(case when age>65 and age<=75 then 1 else 0 end ) age7,
sum(case when age>75 then 1 else 0 end ) age8,
count(id) other
from snap_face

经检查发现xml格式 <=号无法正确识别
改过之后的查询
select sum(case when age <=16 then 1 else 0 end ) age1,
sum(case when age>16 and age <=25 then 1 else 0 end ) age2,
sum(case when age>25 and age <=35 then 1 else 0 end ) age3,
sum(case when age>35 and age <=45 then 1 else 0 end ) age4,
sum(case when age>45 and age <=55 then 1 else 0 end ) age5,
sum(case when age>55 and age <=65 then 1 else 0 end ) age6,
sum(case when age>65 and age <=75 then 1 else 0 end ) age7,
sum(case when age>75 then 1 else 0 end ) age8,
count(id) other
from snap_face

  • 附:XML转义字符

<< 小于号;

>> 大于号;

& & 和 ;

' ‘’单引号;

" “” 双引号;

原文地址:https://www.cnblogs.com/lancelee98/p/9879116.html