接口
public interface UserMapper {
int addUser(@Param("user") User user); #
}
XML文件
<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>
上述方式彙報如下錯誤:
org.apache.ibatis.binding.BindingException: Parameter ‘username’ not found
。
原因
在接口插入的方法實體類參數前面添加了@Param(“user”)
,去掉這個註解即可。