mybatis example 用法中怎么传查重的参数example.setdistinct
1个回答
展开全部
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" />
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
limit #{beginLine},#{endLine}
</select>
执行过程中,显示在使用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.
首先多个参数的值已经取到了,可以读取出来。
其中问题主要出现在:
<if test="example!= null">
<include refid="Example_Where_Clause" />
</if>
一旦example不为null的时候,就会去调用Example_Where_Clause sql子句。
该子句语法如下:
<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>
select
<if test="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>
执行过程中,显示在使用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.
首先多个参数的值已经取到了,可以读取出来。
其中问题主要出现在:
<if test="example!= null">
<include refid="Example_Where_Clause" />
</if>
一旦example不为null的时候,就会去调用Example_Where_Clause sql子句。
该子句语法如下:
<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>
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |