今天学习Mybatis的时候,用if标签来判断int类型是否为null,老是报There is no getter for property named 'UserId' in 'class java.lang.Integer',查看后,发现if标签是用OGNL表达式,取值的时候是用类名.属性的方式使用该属性的getter方法来取值的,所以报了no getter错误。
改正措施:
1.在mapper中添加@Param标签声明需要使用的参数的名字,如 public List<Orders> testIf(@Param(value = "UserId") int UserId);
2.String和基本数据类型在if标签中判断的时候,使用_parameter来代替即可 如 <if test="_parameter!=null and _parameter!='' or _parameter==0">
AND t1.user_id = #{_parameter}
</if>