Mybatis parameter annotation problem:
found the following errors in the process of using mybatis:
“nested exception is org.apache.ibatis.binding.BindingException: Parameter ‘cid’ not found. Available parameters are [cid, ps, offset, param3, param1, param2]”,
Code investigation found nothing wrong
@Select({"select * from table where c_id = #{cid} and delete_flag = 0 order by created_at desc limit #{offset}, #{ps} "})
List listByCompanyId(long cid, int offset, int ps);
Cause: The
parameter is not used @Param notes, resulting in a corresponding mybatis not find parameters
修改如下:
@Select({"select * from table where c_id = #{cid} and delete_flag = 0 order by created_at desc limit #{offset}, #{ps} "})
List listByCompanyId(@Param(“cid”)long cid,@Param (“offset”) int offset, @Param(“ps”) int ps);
Another:
If only one parameter, you can omit the parameter annotation;
this is no problem
@Select ({ "select count (1 ) from table where c_id = # {cid} and delete_flag = 0 and status = 0!" })
Long COUNT (Long CID);
Summary:
In use mybatis, if a multi-parameter, then add parameters must be annotated, if there is only one parameter may be omitted if the parameter annotation, it is recommended that all together, so that will not be wrong.