前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >source is null for getProperty(null, “name“)

source is null for getProperty(null, “name“)

作者头像
张小驰出没
发布2021-12-06 16:16:47
1.7K0
发布2021-12-06 16:16:47
举报
文章被收录于专栏:用户8506532的专栏

source is null for getProperty(null, “name”)

这个问题的发生一般是在 Mapper.xml 的 sql语句中出错。

我在项目中使用到了,用到了XML中的判断条件查询方式,代码如下:

代码语言:javascript
复制
<if test="employee.name != null and employee.name != ''">
    AND e.`name` LIKE CONCAT( '%', #{employee.name}, '%' )
</if>

上述语句的简单来说,当传过来的employee.name不等于 null 并且不等于 '' ,就按这个条件查询,这时候运行项目,报错:

source is null for getProperty(null, “name”)

这时候可能有两个原因:

一、你并没有对应的对象参数

你可以查看方法参数中是否有对应的对象参数

例如:我这个方法中要查看是否有 employee

代码语言:javascript
复制
//  错误
List<Employee> getEmployee();

//  正确
List<Employee> getEmployee(Employee employee);
二、有对应对象,但是对象传值为NULL

这种情况可以在外层加入判断:

代码语言:javascript
复制
<if test="employee != null and employee != '' ">
	<if test="employee.name != null and employee.name != ''">
       AND e.`name` LIKE CONCAT( '%', #{employee.name}, '%' )
    </if>
</if>

这样,没有传入任何参数时,也不会报错了

个人博客为: MoYu’s HomePage

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2021/05/07 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • source is null for getProperty(null, “name”)
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档