JavaWeb踩坑记录

  1. org.apache.ibatis.binding.BindingException: Parameter 'XXXX' not found.There is no getter for property named ‘XXX‘ in ‘class XXX

    • 原因分析(首先这个问题在 Dao 层)
      1. 检查 SQL 语句,#{}中的内容是否存在拼写错误,或者与参数中@param注解中不一致的情况
      2. @param的使用错误,使用方法参考:MyBatis参数传递
  2. Mapper method 'priv.dandelion.dao.BrandMapper.selectTotalCountByCondition attempted to return null from a method with a primitive return type (int).

    • 原因分析:

      1. 是未配置 导致数据库与需要使用的名称不一致,需要配置@ResultMap使其名称一致就可以了

      2. 第二种情况就是误配置,如selectTotalCount 无返回值类型 就不要使用 @ResultMap,使用resultType,二者都不用会报错

        <select id="selectTotalCountByCondition" resultType="java.lang.Integer">
        select count(*) from tb_brand
        <where>
        <if test="brand.brandName != null and brand.brandName != ''">
        brandName like #{brand.brandName}
        </if>
        <if test="brand.companyName != null and brand.companyName != ''">
        and companyName like #{brand.companyName}
        </if>
        <if test="brand.status != null">
        and status = #{brand.status}
        </if>
        </where>
        </select>
  3. Unknown column 'companyName' in 'where clause'

    • 原因分析:并没有按照resultMap进行解析,where 标签中的内容必须要和数据库中一致

      • 错误代码

        <!-- 条件查询 -->
        <select id="selectByPageAndCondition" resultMap="brandResultMap">
        select * from tb_brand
        <where>
        <if test="brand.brandName != null and brand.brandName != ''">
        brandName like #{brand.brandName}
        </if>
        <if test="brand.companyName != null and brand.companyName != ''">
        and companyName like #{brand.companyName}
        </if>
        <if test="brand.status != null">
        and status = #{brand.status}
        </if>
        </where>
        limit #{begin}, #{pageSize}
        </select>
      • 更整后代码

        <!-- 条件查询 -->
        <select id="selectByPageAndCondition" resultMap="brandResultMap">
        select * from tb_brand
        <where>
        <if test="brand.brandName != null and brand.brandName != ''">
        brand_name like #{brand.brandName}
        </if>
        <if test="brand.companyName != null and brand.companyName != ''">
        and company_name like #{brand.companyName}
        </if>
        <if test="brand.status != null">
        and status = #{brand.status}
        </if>
        </where>
        limit #{begin}, #{pageSize}
        </select>
posted @   Dandelion_000  阅读(47)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现

阅读目录(Content)

此页目录为空

点击右上角即可分享
微信分享提示