蒦嗳伱 发表于 2018-10-25 12:07:18

Java操纵MongoDB_2(应用场景设置)

  应用场景设置
  以学生的信息管理系统为例,演示学生信息的增删改查。这里定义学生的Bean类为:
  Student.java

  public>  private String studentId;
  private String name;
  private int weight;

  private int>  private Date birthday;
  public String getStudentId() {
  return studentId;
  }
  public void setStudentId(String studentId) {
  this.studentId = studentId;
  }
  public String getName() {
  return name;
  }
  public void setName(String name) {
  this.name = name;
  }
  public int getWeight() {
  return weight;
  }
  public void setWeight(int weight) {
  this.weight = weight;
  }
  public int getHeight() {

  return>  }

  public void setHeight(int>
  this.height =>  }
  public Date getBirthday() {
  return birthday;
  }
  public void setBirthday(Date birthday) {
  this.birthday = birthday;
  }
  @Override
  public String toString() {
  return "Student [studentId=" + studentId + ", name=" + name

  + ", weight=" + weight + ",>  + birthday + "]";
  }

  public Student(String studentId, String name, int weight, int>  Date birthday) {
  super();
  this.studentId = studentId;
  this.name = name;
  this.weight = weight;

  this.height =>  this.birthday = birthday;
  }
  public Student() {
  }
  }
  并且定义了学生的增删改查接口如下:
  IStudentDao.java
  public interface IStudentDao {
  void insert(Student s);
  void update(Student s);
  void delete(String studentId);
  }
  操纵MongoDB的接口实现文件如下,
  IStudentDaoImpl.java

  public>  @Override
  public void insert(Student s) {
  //暂未实现
  }
  @Override
  public void update(Student s) {
  //暂未实现
  }
  @Override
  public void delete(String studentId) {
  //暂未实现
  }
  }


页: [1]
查看完整版本: Java操纵MongoDB_2(应用场景设置)