Mybatis分页There is no getter for property named __frch_criterion_1 in class

用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)、问题完美解决!!

查了半天,特此记录。

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

凌晨两点钟同学

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值