Error querying database. Cause: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'user' in 'class learn.User'
### Cause: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'user' in 'class learn.User'
主要原因是,复制代码的时候,入参那里将@Param注解去掉后,结果仍然使用 #{user.userCode}的方式获取值。
下面是正确的示例代码:
package learn;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.session.RowBounds;
import java.util.List;
public interface UserMapper {
public User selectUser(String id);
public User selectUserByIdAndName(String id,String name);
public User selectUserByArgs(String id,String name);
public User selectUserByIdFromTable(@Param("id")String id,@Param("tableName")String tableName);
public User selectUser2(User user);
public void updateName(@Param("name") String name , @Param("id")Str

在MyBatis中遇到一个错误:ReflectionException,提示在User类中没有getter方法名为'user'。问题源于在传入自定义对象作为参数时未正确使用@Param注解。正确做法是,对于带有注解的参数,应使用#{user.userCode}方式获取值,而对于单个对象参数,直接使用#{属性名}即可,形参可以随意命名。在DefaultParameterHandler的setParameters()方法中,简单类型参数直接返回值,对象类型则通过元数据获取属性字段值。
最低0.47元/天 解锁文章
594

被折叠的 条评论
为什么被折叠?



