用mybatis插件自动生成的example查询分页,不带条件时可以成功,带条件会报错There is no getter for property named '__frch_criterion_1' in 'class xxx。
这应该是mybatis的一个Bug。
问题原因:加红色的分页参数后,方法有两个两个参数,原先生成的xxxMapper.xml里找不到对应参数
List<Product> selectByExample(ProductExample example, PageBounds asPageBounds);
解决方法:主要为改造之前的selectByExample方法
List<Product> selectByExampleWithPage(@Param("example") ProductExample example, PageBounds asPageBounds);
a)、dao层加入以上新方法,用@Param注解定义参数名(非常重要!!!)
b)、定义一个扩展的mapper文件,名字如xxxExMapper.xml,内容如下
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.hnac.hzinfo.energy.dao.ProductMapper" >
<!--分页接口-->
<sql id="Example_Where_Clause_Alias" >
<where >
<foreach collection="example.oredCriteria" item="criteria" separator="or" >
<if test="criteria.valid" >
<trim prefix="(" suffix=")" prefixOverrides="and" >
<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 collection="criterion.value" item="listItem" open="(" close=")" separator="," >
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<select id="selectByExampleWithPage" resultMap="BaseResultMap" parameterType="xxx.ProductExample" >
select
<if test="example.distinct" >
distinct
</if>
'true' as QUERYID,
<include refid="Base_Column_List" />
from en_product
<if test="_parameter != null" >
<include refid="Example_Where_Clause_Alias" />
</if>
<if test="example.orderByClause != null" >
order by ${example.orderByClause}
</if>
</select>
</mapper>
c)、问题完美解决!!
查了半天,特此记录。