简单学生信息管理系统java
时间: 2024-01-17 13:18:31 浏览: 30
以下是一个简单的学生信息管理系统的Java代码示例:
```java
import org.litepal.LitePal;
import org.litepal.crud.LitePalSupport;
public class Student extends LitePalSupport {
private int id;
private String name;
private int age;
private String gender;
// 构造方法
public Student(String name, int age, String gender) {
this.name = name;
this.age = age;
this.gender = gender;
}
// getter和setter方法
// ...
// 保存学生信息到数据库
public void save() {
LitePal.save();
}
// 更新学生信息到数据库
public void update() {
LitePal.update();
}
// 删除学生信息从数据库
public void delete() {
LitePal.delete();
}
// 查询所有学生信息
public static List<Student> findAll() {
return LitePal.findAll(Student.class);
}
}
// 使用示例
public class Main {
public static void main(String[] args) {
// 创建学生对象
Student student1 = new Student("张三", 18, "男");
Student student2 = new Student("李四", 20, "女");
// 保存学生信息到数据库
student1.save();
student2.save();
// 查询所有学生信息
List<Student> students = Student.findAll();
for (Student student : students) {
System.out.println("姓名:" + student.getName() + ",年龄:" + student.getAge() + ",性别:" + student.getGender());
}
}
}
```
相关推荐
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)