资讯详情

Error querying database.Parameter ‘brandName‘ not found. Available parameters are [size, param3.....

项目场景:

提示:黑马新版web项目,查询增删改查的条件


问题描述:

连接数据库失败,一开始以为是mybatis后来发现的原因是xml配置sql语法问题

报错信息

Caused by: org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: org.apache.ibatis.binding.BindingException: Parameter 'brandName' not found. Available parameters are [size, param3, begin, brand, param1, param2] ### Cause: org.apache.ibatis.binding.BindingException: Parameter 'brandName' not found. Available parameters are [size, param3, begin, brand, param1, param2


原因分析:

问题代码:

 <select id="selectByPageAndCondition" resultMap="brandResultMap" >         select *         from tb_brand         <where>             <if test="brand.brandName != null and brandName != '' ">                 and brand_name like #{brand.brandName}             </if>              <if test="brand.companyName != null and companyName!='' ">                 and company_name like #{brand.companyName}             </if>              <if test="brand.status != null">                 and status = #{brand.status}             </if>          </where>         limit #{begin} , #{size}      </select>

问题分析:这类问题有几种情况

1,没有在mapper在接口中加注解@Param(xxx) 却使用 xxx.属性 或传输多个变量

2.添加注释是没有用的 xxx.属性 直接使用属性名 (我犯的错误)


解决方案:

将对象添加到属性前,改为 对象.属性

 <select id="selectByPageAndCondition" resultMap="brandResultMap" >         select *         from tb_brand         <where>             <if test="brand.brandName != null and brand.brandName != '' ">                 and 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} , #{size}      </select>

标签: 1sma22at3g抑制二极管

锐单商城拥有海量元器件数据手册IC替代型号,打造 电子元器件IC百科大全!

锐单商城 - 一站式电子元器件采购平台