org.apache.ibatis.mapping.SqlMapperException: The expression 'list' evaluated to a null value.

使用的mapper接口以及对应的mapper.xml

public interface BooksSlaveMapper {
    List<Book> getBookList(Book object);
    List<Book> getBookListByIdList(List<Integer> list, Integer status);
}
  <select id="getBookListByIdList" resultMap="BaseResultMap">
    select
    <include refid="Column_List" />
    from books
    where id in
    <foreach collection="list" item="id"  open="(" separator="," close=")">
      #{id}
    </foreach>
    and `status` = #{status,jdbcType=INTEGER}
  </select>

运行执行后报错:

Caused by: org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: org.apache.ibatis.mapping.SqlMapperException: The expression 'list' evaluated to a null value.
### The error may exist in com/lwby/mapper/slave/BooksSlaveMapper.xml
### The error may involve com.lwby.dao.slave.BooksSlaveMapper.getBookListByIdList
### The error occurred while executing a query
### Cause: org.apache.ibatis.mapping.SqlMapperException: The expression 'list' evaluated to a null value.
	at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:8)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:61)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:53)
	at org.apache.ibatis.binding.MapperMethod.executeForList(MapperMethod.java:82)
	at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:63)
	at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:35)
	at com.sun.proxy.$Proxy157.getAdPosListByIdListAndPlatformId(Unknown Source)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at org.mybatis.spring.SqlSessionTemplate$7$1.doInSqlSession(SqlSessionTemplate.java:342)
	... 49 more
Caused by: org.apache.ibatis.mapping.SqlMapperException: The expression 'list' evaluated to a null value.
	at org.apache.ibatis.builder.xml.dynamic.ExpressionEvaluator.evaluateIterable(ExpressionEvaluator.java:27)
	at org.apache.ibatis.builder.xml.dynamic.ForEachSqlNode.apply(ForEachSqlNode.java:36)
	at org.apache.ibatis.builder.xml.dynamic.MixedSqlNode.apply(MixedSqlNode.java:14)
	at org.apache.ibatis.builder.xml.dynamic.DynamicSqlSource.getBoundSql(DynamicSqlSource.java:22)
	at org.apache.ibatis.mapping.MappedStatement.getBoundSql(MappedStatement.java:198)
	at org.apache.ibatis.executor.BaseExecutor.createCacheKey(BaseExecutor.java:119)
	at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:88)
	at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:72)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:59)
	... 59 more

这个问题的原因是在于传递的参数,在mapper接口中传递的参数是有两个,在这种情况下list是找不到对应传的值的,所以才会报上面的问题

处理方法:
1.将这些参数处理成一个对象进行传参;
2.在mapper对应接口中添加@Param注解,如下:

public interface BooksSlaveMapper {
    List<Book> getBookList(Book object);
    List<Book> getBookListByIdList(@Param(value = "list") List<Integer> list, @Param(value = "status") Integer status);
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
引用\[1\]:异常信息: nested exception is org.apache.ibatis.builder.BuilderException: Error evaluating expression 'ides'. Return value (806) was not iterable. 引用\[2\]:nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML lo 引用\[3\]:在基于微服务架构风格的项目开发过程中,为了提高快速开发的目的,提高开发效率,集成了 MyBatisPlus,对于 MyBatisPlus 封装的 CRUD API 接口已经非常强大了,但是有时还是需要使用其动态 SQL 的拼接,在编写动态 SQL 时遇到一个梗,异常信息:“异常信息:nested exception is org.apache.ibatis.builder.BuilderException: Error evaluating expression 'employee.startDate != null and employee.endDate ! = null'. Cause: org.apache.ibatis.ognl.ExpressionSyntaxException: Malformed OGNL expression: employee.startDate != null and employee.endDate ! = null \[org.apache.ibatis.ognl.ParseException: Encountered " "!" "! "" at line 1, column 53. ”, 。 问题: nested exception is org.apache.ibatis.builder.BuilderException: The expression 'array' evaluated to a null value. 回答: 这个异常信息表明在MyBatis中,表达式'array'的值为null,导致了BuilderException异常。\[1\]这可能是由于代码中的某个地方没有正确地初始化或赋值给'array'变量。要解决这个问题,你需要检查代码中涉及到'array'的部分,并确保它被正确地初始化或赋值。另外,你还可以使用调试工具来跟踪代码并找出导致'array'为null的具体原因。 #### 引用[.reference_title] - *1* [nested exception is org.apache.ibatis.builder.BuilderException: Error evaluating expression 异常](https://blog.csdn.net/ren9436/article/details/120454494)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v8^insert_chatgpt"}} ] [.reference_item] - *2* [nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML lo](https://blog.csdn.net/qq_40834643/article/details/128788665)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v8^insert_chatgpt"}} ] [.reference_item] - *3* [nested exception is org.apache.ibatis.builder.BuilderException: Error evaluating expression 的解决...](https://blog.csdn.net/Hello_World_QWP/article/details/86514214)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v8^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值