MyBatis 问题

nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named  in 'class java.lang.String'

Mapper.xml是这样的

<select id="findPlanByPersonId" resultMap="BaseResultMap" parameterType="java.lang.String">
      select * from t_plan
      <where>
          <if test="personId != null">personId = #{personId}</if>
      </where> 
  </select>

Mapper类中的方法是

Plan findPlanByPersonId(String personId);

就会报上述Exception

解决办法

1.改方法

Plan findPlanByPersonId(@Param(value="personId")String personId);

或者2改xml

<select id="findPlanByPersonId1" resultMap="BaseResultMap" parameterType="java.lang.String">
      select * from t_plan
      <where>
          <if test="_parameter != null">personId = #{_parameter}</if>
      </where> 
  </select>

还有一种方式

只改xml(去掉条件)和Mybatis Generator生成的一样

<select id="findPlanByPersonId" resultMap="BaseResultMap" parameterType="java.lang.String">
      select * from t_plan
      where person_id = #{personId,jdbcType=varchar}
  </select>

#{personId,jdbcType=varchar}是重点

评论

暂无评论