问题
使用mybatis时报错: “nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named ‘user’ in ‘class org.springblade.store.common.entity.User’”
可能的原因
1.字段名写错了
2.@Param注解问题
方法只有一个参数时, 如果xml文件中使用#{user.userId}, 则必须添加@Param注解 方法只有一个参数时, 如果xml文件中使用#{userId}, 则不必添加@Param注解
方法有多个参数时, xml文件必须使用#{user.userId}, 不必添加@Param注解
正确写法
写法一
import org
.apache
.ibatis
.annotations
.Param
;
List
<SupplierListVo> getSupplierList(@Param("user") User user
);
<select id
="getSupplierList" resultType
="SupplierListVo">
SELECT
*
FROM
table
WHERE
userId
= #
{user
.userId
}
</select
>
写法二
List
<SupplierListVo> getSupplierList(User user
);
<select id
="getSupplierList" resultType
="SupplierListVo">
SELECT
*
FROM
table
WHERE
userId
= #
{userId
}
</select
>
写法三
List
<SupplierListVo> getSupplierList(User user
, Form form
);
<select id
="getSupplierList" resultType
="SupplierListVo">
SELECT
*
FROM
table
WHERE
userId
= #
{user
.userId
}
AND orderNo
= #
{form
.orderNo
}
</select
>