JavaWeb踩坑记录
-
org.apache.ibatis.binding.BindingException: Parameter 'XXXX' not found.
或There is no getter for property named ‘XXX‘ in ‘class XXX
- 原因分析(首先这个问题在 Dao 层)
- 检查 SQL 语句,
#{}
中的内容是否存在拼写错误,或者与参数中@param
注解中不一致的情况 @param
的使用错误,使用方法参考:MyBatis参数传递
- 检查 SQL 语句,
- 原因分析(首先这个问题在 Dao 层)
-
Mapper method 'priv.dandelion.dao.BrandMapper.selectTotalCountByCondition attempted to return null from a method with a primitive return type (int).
-
原因分析:
-
是未配置 导致数据库与需要使用的名称不一致,需要配置
@ResultMap
使其名称一致就可以了 -
第二种情况就是误配置,如
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>
-
-
-
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>
-
-