该文章是Java入门系列的第十一章:使用 MyBatis-Plus 修改数据
修改数据
打开 Controller.java 文件,我们编写修改数据的接口,代码如下:
我们在上一章节添加了数据 {"id":13,"number":"113","name":"小黄","age":14,"chi":78,"math":99,"eng":93} ,但是我们发现小黄的语文成绩录入错误了,应该为88,所以我们将数据修改一下,使用 studentMapper.updateById() 方法进行修改,修改完成后返回提示“修改成功”
@GetMapping("/update")
public String updateStudent(){
String student = "{"id":13,"number":"113","name":"小黄","age":14,"chi":88,"math":99,"eng":93}";
Student student1 = gson.fromJson(student, Student.class);
String name = student1.getName();
studentMapper.updateById(student1);
return name + "修改成功!";
}
项目重新运行后,我们访问http://localhost:8080/update ,看到修改成功的提示
我们再访问http://localhost:8080/select ,可以看到小黄的语文成绩已经修改为88了
写在最后
以上就是使用 MyBatis-Plus 修改数据的全部说明