在执行一个查询语句的时候,mybatis报错:root cause org.apache.ibatis.ognl.OgnlException: source is null for getProperty(null, "XXX")

 

代码如下:

  root cause org.apache.ibatis.ognl.OgnlException: source is null for getProperty(null, "XXX")

mapper.xml中:

  root cause org.apache.ibatis.ognl.OgnlException: source is null for getProperty(null, "XXX")

 

原因分析:

  传进来的参数为accountDO本身为null,导致获取name属性值的时候就会抛出空指针,mybatis会将该异常封装为自己的异常,再抛出。

 

解决:

  方式一:

    在mapper.xml中,进行两层的<if>标签判断,先判断accountDO是否为null;再判断accountDO.name是否为null

  方式二:

    在service中new AccountDO()对象,保证accountDO不为null;再根据需求判断是否给name属性设置值


参考:http://blog.csdn.net/qq_32331073/article/details/76272110

 

相关文章:

  • 2022-03-09
  • 2022-12-23
  • 2021-11-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-14
猜你喜欢
  • 2022-12-23
  • 2021-06-04
  • 2021-04-25
  • 2020-10-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案