错误具体信息:

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

接口:

public interface NarCodeService {
    
    public NarCode getNarCode(String id);

}

xml

<select id="getNarCode" parameterType="java.lang.String"
         resultType="narCode">
         select
         <include refid="Base_Column_List"></include>
         from nar_code
         <where>
             <if test="id != null">
                 id=#{id,jdbcType=VARCHAR}
             </if>
         </where>
 </select>

查询报错:

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

解决方法:
1.去掉sql语句的if标签限制

id=#{id,jdbcType=VARCHAR} 改为: id=#{id,jdbcType=VARCHAR}

原因:我自己猜测加上if标签时,id属性没有包含在数据类型为String id对象中。
如果去掉if标签时直接使用这个数据类型为String id对象

2.将parameterType="java.lang.String"参数改为传一个自定义实体对象或者HashMap来封装这个id参数
原因:可以在自定义实体对象或者HashMap中找到这个id属性

转载于:https://www.cnblogs.com/sishang/p/6555176.html

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐