Mybatis报错:Cause: org.apache.ibatis.binding.BindingException: Parameter xxx not found

使用mybatis报错在插入语句中报错

org.apache.ibatis.exceptions.PersistenceException: 
### Error updating database.  Cause: org.apache.ibatis.binding.BindingException: Parameter 'username' not found. Available parameters are [arg1, arg0, param1, param2]
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: insert into user (username, password) values (?, ?)
### Cause: org.apache.ibatis.binding.BindingException: Parameter 'username' not found. Available parameters are [arg1, arg0, param1, param2]

在数据库中插入一行数据
代码:

    /**
     * 添加用户
     * @param username 用户名
     * @param password 用户密码
     */
    void addUser(String username, String password);
    
    <insert id="addUser">
        insert into user (username, password) values (#{username}, #{password})
    insert>

查阅后得知,在有传递的参数有多个的情况下,使用注解@Param

/**
     * 添加用户
     * @param username 用户名
     * @param password 用户密码
     */
    void addUser(@Param("username") String username, @Param("password") String password);

你可能感兴趣的:(Mybatis)