使用MyBatis-Plus写一个更新数据的方法报错
userMapper.java
@Mapper
public interface UserMapper extends BaseMapper<User> {
int updateUserByUserId(@Param("user") User user);
}
userMapper.xml
<update id="updateUserByUserId" parameterType="com.demo.entity.User">
update user
<set>
<if test="nickname != null and nickname != '' ">
nickname = #{nickname},
</if>
<if test="email != null and email != '' ">
email = #{email},
</if>
</set>
where id = #{id}
</update>
报错
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'nickname' not found. Available parameters are [user, param1]
删除@Param(“user”)即可:
int updateUserByUserId(User user);