Recording time data MyBatis inserted Bug (org.apache.ibatis.binding.BindingException: Parameter 'username' not found)

interface

public interface UserMapper {

    int addUser(@Param("user") User user); #
}

XML file

<insert id="addUser" parameterType="com.rong.blog.entity.User">
    insert into user
    <trim prefix="(" suffix=")" suffixOverrides=",">
        <if test="id != null">
            id,
        </if>
        <if test="username != null">
            username,
        </if>
        <if test="password != null">
            password,
        </if>
        <if test="address != null">
            address,
        </if>
    </trim>
    values
    <trim prefix="(" suffix=")" suffixOverrides=",">
        <if test="id != null">
            #{id},
        </if>
        <if test="username != null">
            #{username},
        </if>
        <if test="password != null">
            #{password},
        </if>
        <if test="address != null">
            #{address}
        </if>
    </trim>

</insert>

Error Reporting as described above:
org.apache.ibatis.binding.BindingException: Parameter ‘username’ not found.

the reason

In front of the connector into the entity class parameter method adds @Param(“user”), to remove this annotation.

Published 141 original articles · won praise 131 · views 210 000 +

Guess you like

Origin blog.csdn.net/qq_41621362/article/details/105231502
Recommended