java 报错Error evaluating expression ‘params.createBy’. Return value (126) was not iterable.
出现原因:xml文件中遍历List 时,该参数的实际值为非List数据。
这里需要一个list集合去遍历查询,
注释仔细看,尤其没有子id的时候
// 判断是否为超级管理员
if (getUserId() != Constant.SUPER_ADMIN) {
// 如果不是,就把当前用户id传给,用户表查询他的子id
List <Long> userId = sysUserService.selectParentId(getUserId());
// 判断子id是否为空
if (!CommonUtils.isEmpty(userId)) {
// 不为空, 就把多个或者单个子id传过去,查询这些子id相关的信息
params.put("createBy",userId);
} else {
// 为空 ,就把当前用户传过去,查询当前用户信息
// 这里,,,当前用户id就只有唯一一个,所以不是list集合,到xml查询信息会报错
// params.put("createBy",getUserId()); 会报错
// 把单个元素转化为一个集合
List <Long> getuserId = Collections.singletonList(getUserId());
params.put("createBy",getuserId);
}
}
PageUtils page = comEnterpriseWasteService.queryPage(params);
return R.ok().put("page", page);
这时候我们看看xml文件
select t4.name bigClassName, t1.name doorClassName,a.*
from com_enterprise_waste a
LEFT JOIN ods_industry_classification t1 on a.door_class = t1.code
LEFT JOIN ods_industry_classification t4 on a.big_class = t4.code
where 1=1
<if test="params.name != null and params.name !=''">
and name like concat('%',#{params.name},'%')
</if>
<trim prefix="and">
<foreach item="createBy" collection="params.createBy" separator="or">
created_by = #{createBy}
</foreach>
</trim>
limit #{params.start},#{params.end}