温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

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

发布时间:2020-07-18 11:42:05 来源:网络 阅读:401 作者:huting010527 栏目:MongoDB数据库


应用场景设置

以学生的信息管理系统为例,演示学生信息的增删改查。这里定义学生的Bean类为:


Student.java


public class Student {

private String studentId;

private String name;

private int weight;

private int height;

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 height;

}

public void setHeight(int height) {

this.height = 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 + ", height=" + height + ", birthday="

+ birthday + "]";

}

public Student(String studentId, String name, int weight, int height,

Date birthday) {

super();

this.studentId = studentId;

this.name = name;

this.weight = weight;

this.height = 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 class IStudentDaoImpl implements IStudentDao{


@Override

public void insert(Student s) {

//暂未实现

}


@Override

public void update(Student s) {

//暂未实现

}


@Override

public void delete(String studentId) {

//暂未实现

}

}



向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI