错误记录(11): source is null for getProperty(null, "name")
2018-01-13 16:35
1446 查看
使用SSM框架做项目时,使用到了XML中的判断条件查询方式,代码如下:
<if test="machineInfo.name != null and machineInfo.name != ''">
AND b.name like CONCAT('%',#{machineInfo.name},'%')
</if>也就是如果有值,按条件查询,如果没有传入条件,则展示所有,运行项目时报错:org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.builder.BuilderException: Error evaluating expression 'machineInfo.name != null and machineInfo.name != '''. Cause: org.apache.ibatis.ognl.OgnlException: source is null for getProperty(null, "name")
source is null for getProperty(null, "name")
这个相当于Mybatis封装的空指针异常,单没有传入条件时,machineInfo这个对象即为空,而进行条件判断machineInfo.name,自然会报空指针。
解决方法是加一层判断,先判断machineInfo是不是空:
<if test="machineInfo != null and machineInfo != ''">
<if test="machineInfo.name != null and machineInfo.name != ''">
AND b.name like CONCAT('%',#{machineInfo.name},'%')
</if>
</if>这样,没有传入任何参数时,也不会报错了,这里记录一下这个错误
<if test="machineInfo.name != null and machineInfo.name != ''">
AND b.name like CONCAT('%',#{machineInfo.name},'%')
</if>也就是如果有值,按条件查询,如果没有传入条件,则展示所有,运行项目时报错:org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.builder.BuilderException: Error evaluating expression 'machineInfo.name != null and machineInfo.name != '''. Cause: org.apache.ibatis.ognl.OgnlException: source is null for getProperty(null, "name")
source is null for getProperty(null, "name")
这个相当于Mybatis封装的空指针异常,单没有传入条件时,machineInfo这个对象即为空,而进行条件判断machineInfo.name,自然会报空指针。
解决方法是加一层判断,先判断machineInfo是不是空:
<if test="machineInfo != null and machineInfo != ''">
<if test="machineInfo.name != null and machineInfo.name != ''">
AND b.name like CONCAT('%',#{machineInfo.name},'%')
</if>
</if>这样,没有传入任何参数时,也不会报错了,这里记录一下这个错误
相关文章推荐
- source is null for getProperty(null, "parentId")
- source is null for getProperty(null, "xxx")
- ognl.OgnlException: source is null for getProperty(null, "0")
- Struts2 设置List值时出错:ognl.OgnlException: source is null for getProperty(null, "0")
- org.apache.ibatis.ognl.OgnlException: source is null for getProperty(null, "mil_id")
- Caused by: org.apache.ibatis.ognl.OgnlException: source is null for getProperty(null, "list")
- WEB开发错误收集(二) ognl.OgnlException: target is null for setProperty(null, "name", [Ljava.lang.String;@f6
- root cause org.apache.ibatis.ognl.OgnlException: source is null for getProperty(null, "XXX")
- Caused by: org.apache.ibatis.ognl.OgnlException: source is null for getProperty(null, "id")
- 解决异常ognl.OgnlException: source is null for getProperty(null, "token")
- 对于Name属性没有get/set方法引起的:target is null for setProperty(null, "x", [Ljava.lang.String;@1a48515)异常
- target is null for setProperty(null, "x", [Ljava.lang.String;@b0c40e)错误异常
- target is null for setProperty(null, "x", [Ljava.lang.String;@b0c40e)错误异常
- ognl.OgnlException: target is null for setProperty(null, "x",)错误
- target is null for setProperty(null, "name", [Ljava.lang.String;@ffc6ae)
- ognl.OgnlException: target is null for setProperty(null, "username")
- target is null for setProperty(null, "username", [Ljava.lang.String;@c06258)问题
- Warning Error user.userId value userid 出现错误ognl.OgnlException: target is null for setProperty(null, "userid", [Ljava.lang.String;@19af9e98)
- source is null for getproperty
- Warning Error user.userId value userid 出现错误ognl.OgnlException: target is null for setProperty(null, "userid", [Ljava.lang.String;@19af9e98)