当涉及到增删改查的操作时,通常会使用Java的CRUD(Create, Read, Update, Delete)操作。以下是Java中实现CRUD操作的示例代码。
假设我们要创建一个简单的学生类,其中包括学生的姓名、年龄和成绩。我们将在以下示例代码中使用这个类。
public class Student {
private String name;
private int age;
private double score;
public Student(String name, int age, double score) {
this.name = name;
this.age = age;
this.score = score;
}
// getter and setter methods
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public double getScore() {
return score;
}
public void setScore(double score) {
this.score = score;
}
}