发布网友 发布时间:2022-05-11 03:00
共2个回答
热心网友 时间:2024-02-08 08:38
select id="selectByExample" resultMap="BaseResultMap">
select
<if test="distinct">
distinct
</if>
<include refid="Base_Column_List" />
from client
<if test="example!= null">
<include refid="Example_Where_Clause" />
org.mybatis.spring.MyBatisSystemException: SqlSession operation; nested exception is org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: org.apache.ibatis.mapping.SqlMapperException: The expression 'oredCriteria' evaluated to a null value.
### The error may exist in com/alex/server/mapper/ClientMapper.xml
### The error may involve com.alex.server.mapper.ClientMapper.selectPageByExample
### The error occurred while executing a query
### Cause: org.apache.ibatis.mapping.SqlMapperException: The expression 'oredCriteria' evaluated to a null value.
热心网友 时间:2024-02-08 08:39
1、select id="selectByExample"resultMap="BaseResultMap">select<iftest="distinct">distinct</if><include refid="Base_Column_List" />from client<if test="example!= null"><include refid="Example_Where_Clause" /></if>
<if test="orderByClause != null">order by ${orderByClause}</if>limit #{beginLine},#{endLine}</select>
2、执行过程中,显示在使用example的时候,里面的criteria为null。具体为:
org.mybatis.spring.MyBatisSystemException: SqlSession operation; nested exception is org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: org.apache.ibatis.mapping.SqlMapperException: The expression 'oredCriteria' evaluated to a null value.
### The error may exist in com/alex/server/mapper/ClientMapper.xml
### The error may involve com.alex.server.mapper.ClientMapper.selectPageByExample
### The error occurred while executing a query
### Cause: org.apache.ibatis.mapping.SqlMapperException: The expression 'oredCriteria' evaluated to a null value.
1、首先多个参数的值已经取到了,可以读取出来。其中问题主要出现在:
<if test="example!= null"><include refid="Example_Where_Clause" />
</if>一旦example不为null的时候,就会去调用Example_Where_Clause sql子句。
2、该子句语法如下:
<sql id="Example_Where_Clause"><where><foreach collection="oredCriteria" item="criteria" separator="or"><if test="criteria.valid"><trim prefix="(" prefixOverrides="and" suffix=")"><foreach collection="criteria.criteria" item="criterion"><choose><when test="criterion.noValue">and ${criterion.condition}
</when><when test="criterion.singleValue">and ${criterion.condition} {criterion.value}
</when><when test="criterion.betweenValue">and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}</when><when test="criterion.listValue">and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="("separator=",">
#{listItem}</foreach></when></choose></foreach></trim></if></foreach></where>