【MyBatis-Plus】 在使用updateById()修改值时报错:Invalid bound statement (not found)

一、问题:

问题发生在:使用MybatisPlus做测试

1. 实体类

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Book {
    int bookId;
    String bookName;
    int bookCounts;
    String detail;

2. 测试类

    /**
     * 通过id修改用户信息
     */
    @Test
    public void testUpdateById(){
        Book b=new Book();
        b.setBookId(15);
        b.setBookName("《Linux私房菜》");
        b.setDetail("好好学习指令 这是2.0版本");
        b.setBookCounts(100);
        int res=bookMapper.updateById(b);
        System.out.println(res);

    }

然后测试时出现错误

二、分析问题 

Invalid bound statement (not found)           无效的绑定语句(未找到)

 我们发现原来是没有找到我们绑定的id,因为我使用的是updateById的方法 需要通过id寻找

所以说,要加上一个mybatisplus的注解@TableId

查看官方文档:

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Book {
    @TableId
    int bookId;
    String bookName;
    int bookCounts;
    String detail;

三、测试 

这样子我们的问题就解决啦

猜你喜欢

转载自blog.csdn.net/m0_56233309/article/details/126858295