JavaFx+MySql学生管理系统

前言:

        上个月学习了javafx和mysql数据库,于是写了一个学生管理系统,因为上个月在复习并且有一些事情,比较忙,所以没有更新博客了,这个项目页面虽然看着有点简陋了,但是大致内容还是比较简单的,于是现在跟大家分享一下我的学生管理系统,希望对这方面有兴趣的同学提供一些帮助

🥰个人主页:心.c

🤓文章专题:javafx+mysql管理系统

👐欢迎大家点赞👍 收藏😽

 

9a7940c627094e34946debbd787da24e.jpg

487ac90190f44b238ebafae9d457463b.png

 

目录

页面展示:

包的创建:

登录界面:

学生登录界面:

 学生信息查询:

​编辑

学生成绩查询:

管理员登录界面:

管理员学生信息管理界面:

管理员课程信息管理界面:

管理员成绩信息管理界面:

修改学生界面:

 代码展示:

主窗口(endView):

 登录界面和提示窗口(otherView):

学生:

学生界面(studentView):

学生Dao语句:

utilDao:

studentDao*:

管理员:

管理员界面(magView):

管理员工具类:

学生(studentUtil):

课程(courseUtil):

分数(scoreUtil):

判断工具类(judgeUtil):

管理员Dao类:

utilDao:

studentDao*:

courseDao:

scoreDao:

judgeDao:

domain(对象类):

student:

course:

score:

结尾


 

 

页面展示:

包的创建:

(在这里我用了一些mvc的框架结构,虽然我的代码不是很多,但是我觉得这样写可以让我们的代码变的更加简洁易懂,很有结构层次)

4033c3dc2d754754a7b3f2454d5e9845.png

登录界面:

关于登录界面(关于登录界面,写了一些关于文本输入框的判断--数据库判断是否正确和一些非空判断--)

55d6138971d64cfbb14cf719a47454e5.png

学生登录界面:

87787ba5c3924a76a98926dd8515df68.png

 学生信息查询:

8e9905fc895a44c982abbc457be7a80a.png

学生成绩查询:

97cefd35d8ad47399c72b79e965a7d4d.png

管理员登录界面:

a5114f0d903747b197c0ad925c424043.png

管理员学生信息管理界面:

49cd3ef4185041aa8d83bb07e3cc417e.png

管理员课程信息管理界面:

d7d32fcf511e4703a0701d4b44141a7f.png

管理员成绩信息管理界面:

584f66d36cdf4bb8a2c0bb845fb20d84.png

修改学生界面:

(以为这几个页面都差不多,所以在这里我就只展示一个添加学生界面了)

9f338156d1d740fca1f060ce0ede42c8.png

 

 代码展示:

 

主窗口(endView):

关于主窗口,我定义了一个静态舞台来当我的主舞台,将我的start方法中的舞台赋值给静态舞台,我设置这个舞台的目的是为了将我写的其他方法,比如登录界面等的方法里面的scene场景放到我的静态stage当中,这样我的代码在执行的时候我的页面就可以一直用主舞台了也不会显得界面很乱了,而且非常方便,简单易懂

public class endView extends Application {public static Stage stage;public static student student0;public static course course0;public static score score0;@Overridepublic void start(Stage stage) {endView.stage=stage;//这里将主舞台赋值给静态舞台stage.setTitle("学生管理系统");stage.setResizable(false);otherView.login();endView.stage.show();}public static void main(String[] args) {launch(args);}}

 登录界面和提示窗口(otherView):

//设置登录界面public static void login() {//创建网格面板GridPane gp=new GridPane();gp.setVgap(10);gp.setHgap(10);//创建标签Label idL=new Label("id");Label passwordL=new Label("密码");//创建输入框TextField tf=new TextField();PasswordField pf=new PasswordField();tf.setPromptText("请输入您的id号");pf.setPromptText("请输入6位数密码");//创建单选按钮RadioButton stuB=new RadioButton("学生");RadioButton teaB=new RadioButton("管理员");//创建单选按钮组ToggleGroup tg=new ToggleGroup();stuB.setToggleGroup(tg);teaB.setToggleGroup(tg);//创建单行面板HBox hBox1=new HBox();hBox1.setAlignment(Pos.CENTER);hBox1.setSpacing(10);hBox1.getChildren().addAll(stuB,teaB);//创建登录注册按钮Button loginB=new Button("登录");//给单选按钮组添加监听事件tg.selectedToggleProperty().addListener(((observableValue, toggle, t1) -> {if(t1.equals(stuB)){idL.setText("id");}else if(t1.equals(teaB)){idL.setText("姓名");}}));loginB.setOnAction(actionEvent -> {// 如果内容不为空try {String idS=tf.getText().trim();String passwordS=pf.getText().trim();Toggle selectedToggle = tg.getSelectedToggle(); // 获取选中的单选按钮if (selectedToggle != null && selectedToggle.equals(stuB)) { // 检查选中的按钮是否为学生按钮if (studentDao.login(idS,passwordS)) {studentView.stu_login(Integer.parseInt(idS));}else if((idS.isEmpty()||passwordS.isEmpty())){tipJframe("id或密码不能为空");}else{tipJframe("id或密码输入错误");}}else if(selectedToggle !=null && selectedToggle.equals(teaB)){if(judgeDao.magLogin(idS,passwordS)){magView.mag_login();}else  if((idS.isEmpty()||passwordS.isEmpty())){tipJframe("姓名或密码不可为空");}else {tipJframe("姓名或密码输入错误");}}else {tipJframe("你是什么人");}} catch (Exception e) {e.printStackTrace();}});HBox hBox2=new HBox();hBox2.setAlignment(Pos.CENTER);hBox2.setSpacing(10);hBox2.getChildren().add(loginB);//将节点添加到面板当中gp.add(idL,0,0);gp.add(passwordL,0,1);gp.add(tf,1,0);gp.add(pf,1,1);gp.add(hBox1,1,2);gp.add(hBox2,1,3);gp.setAlignment(Pos.BASELINE_LEFT);//设置面板内边距gp.setPadding(new Insets(40,20,10,70));//设置面板垂直间距gp.setVgap(16);Scene scene=new Scene(gp,360,240);endView.stage.setScene(scene);}//增加弹出界面public static void tipJframe(String str){Label label=new Label(str);Button rebackB=new Button("返回");VBox vBox=new VBox(label,rebackB);vBox.setSpacing(10);vBox.setAlignment(Pos.CENTER);Scene scene=new Scene(vBox,150,100);Stage stage1=new Stage();stage1.setScene(scene);stage1.setTitle("提示");stage1.show();rebackB.setOnAction(actionEvent -> {stage1.close();});}

学生:

学生界面(studentView):

下面是我写的三个界面,和上面学生登录的图片对照,一共对应三个方法,当然后面两个方法(成绩查询和信息查询)会放到第一个stu_login的方法当中,根据按钮的动作监听而起作用

//学生登录后界面public static void stu_login(int stu_Id){Label label=new Label("学生查询系统");Button informationB=new Button("个人信息");Button gradeB=new Button("成绩查询");Button returnLogin=new Button("返回登录");//设置按钮字体颜色informationB.setTextFill(Color.BLUE);gradeB.setTextFill(Color.BLUE);returnLogin.setTextFill(Color.BLUE);//设置字体样式Font font = Font.font("Comic Sans MS", FontWeight.BOLD, FontPosture.REGULAR, 20);label.setFont(font);informationB.setFont(font);gradeB.setFont(font);returnLogin.setFont(font);//为按钮添加监听事件//信息查询informationB.setOnAction(actionEvent -> {try {informationInquire(stu_Id);} catch (Exception e) {e.printStackTrace();}});//成绩查询gradeB.setOnAction(actionEvent -> {try {gradeInquire(stu_Id);} catch (Exception e) {throw new RuntimeException(e);}});//返回登录returnLogin.setOnAction(actionEvent -> otherView.login());//添加竖直方向面板VBox vBox=new VBox(20,label,informationB,gradeB,returnLogin);vBox.setAlignment(Pos.CENTER);Scene scene=new Scene(vBox,400,300);endView.stage.setScene(scene);}//学生信息查询public static void informationInquire(int stu_Id) throws Exception {//调用inquiry的返回值studentstudent student= studentDao.returnStudent(stu_Id);Label idL=new Label("学号:"+student.getStu_id());Label classL=new Label("班级:"+student.getStu_class());Label nameL=new Label("姓名:"+student.getStu_name());Label genderL=new Label("性别:"+student.getStu_gender());Label birthL=new Label("出生日期:"+student.getStu_birth());Label majorL=new Label("专业:"+student.getStu_major());//设置字体样式Font font = Font.font("Comic Sans MS", FontWeight.BOLD, FontPosture.REGULAR, 20);idL.setFont(font);classL.setFont(font);nameL.setFont(font);genderL.setFont(font);birthL.setFont(font);majorL.setFont(font);Button backB=new Button("返回");backB.setOnAction(actionEvent -> {stu_login(stu_Id);});VBox vBox=new VBox(10);vBox.getChildren().addAll(idL,classL,nameL,genderL,birthL,majorL,backB);vBox.setAlignment(Pos.CENTER);vBox.setSpacing(10);Scene scene=new Scene(vBox,360,340);endView.stage.setScene(scene);}//学生成绩查询public static void gradeInquire(int stu_Id) throws Exception {int grade=studentDao.gradeOneself(stu_Id);Label gradeL=new Label("您的总学分为:"+grade);Font font = Font.font("Comic Sans MS", FontWeight.BOLD, FontPosture.REGULAR, 20);gradeL.setFont(font);VBox vBox=new VBox();vBox.setAlignment(Pos.CENTER);vBox.setPadding(new Insets(0,0,20,0));Button back=new Button("返回");back.setMinWidth(50);back.setMinHeight(30);back.setOnAction(actionEvent -> {stu_login(stu_Id);});vBox.getChildren().addAll(gradeL,back);Scene scene=new Scene(vBox,340,150);endView.stage.setScene(scene);}

学生Dao语句:

utilDao:

private static final String URL = "jdbc:mysql:///studentMs";private static final String USER = "root";private static final String PASSWORD = "123321";//获取连接对象public static Connection getCon() {try {return DriverManager.getConnection(URL, USER, PASSWORD);} catch (SQLException e) {e.printStackTrace();return null;}}//关闭资源public static void close(ResultSet rs, PreparedStatement ps, Connection con) {try {if (rs != null) {rs.close();}if (ps != null) {ps.close();}if (con != null) {con.close();}} catch (SQLException e) {e.printStackTrace();}}//执行mysqlpublic static boolean exeUpdate(String sql, Object... params) {//获取连接对象Connection con = getCon();PreparedStatement ps = null;try {//获取编译对象ps = con.prepareStatement(sql);//判断参数是否为空if (Objects.nonNull(params)) {for (int i = 0; i < params.length; i++) {//实现占位赋值ps.setObject(i + 1, params[i]);}}//执行更新return ps.executeUpdate() > 0;} catch (Exception e) {e.printStackTrace();} finally {close(null, ps, con);}return false;}

studentDao*:

上面只展示了关于学生登录的jdbc语句,而不是我的studentDao中的所有语句,这样写是为让思路更加清晰,如果觉得很简单可以看我下面的总代码

//学生登录判断public static boolean login(String idStr, String passwordStr) throws Exception {String sql = "select * from student where stuID =? and stuPassword=?";PreparedStatement ps = utilDao.getCon().prepareStatement(sql);ps.setString(1,idStr);ps.setString(2, passwordStr);ResultSet rs = ps.executeQuery();if (rs.next()) {utilDao.close(rs,ps, utilDao.getCon());return true;} else {utilDao.close(rs,ps,utilDao.getCon());return false;}}//学生查询自己成绩public static Integer gradeOneself(int stu_id) throws Exception {String sql = "SELECT SUM(credit) AS gradesum FROM score WHERE stuID=?";try (Connection connection =utilDao.getCon();PreparedStatement ps = connection.prepareStatement(sql)) {ps.setInt(1, stu_id);try (ResultSet rs = ps.executeQuery()) {if (rs.next()) {int gradesum = rs.getInt("gradesum");return gradesum;} else {// 如果没有查询到结果,可以返回 null 或者其他合适的值return null;}}}}//返回学生信息public static student returnStudent(int stu_id)throws Exception{student student=new student();String sql="select stuID,stuClass,stuName,stuSex,stuBirth,stuMajor,stuPassword from student where stuID=?";PreparedStatement ps=utilDao.getCon().prepareStatement(sql);//过滤其他的只留下ID为1的学生ps.setString(1,String.valueOf(stu_id));ResultSet rs=ps.executeQuery();if(rs.next()){student.setStu_id(rs.getInt("stuID"));student.setStu_class(rs.getString("stuClass"));student.setStu_name(rs.getString("stuName"));student.setStu_gender(rs.getString("stuSex"));student.setStu_birth(rs.getString("stuBirth"));student.setStu_major(rs.getString("stuMajor"));student.setStu_password(rs.getString("stuPassword"));}rs.close();ps.close();return student;}

--- 关于学生登录的代码就这些 ---

管理员:

管理员界面(magView):

下面是我关于管理员设置的界面方法,一共四个管理员的主界面,和页面展示中管理员登录的前四个相对应,下面一共7个方法,关于createTableView方法就是我写的用我的student等的对象添加到tableview中的一部分代码,只是拿出来重新定义了一个方法,大家不用在意,所以其他的四个创建界面的方法刚好与页面展示中管理员登录的前四个相对应,第一个是登录后的界面方法,后三个是登录后的面板中前三个的按钮的动作监听所调用的方法

 //管理员登录界面public static void mag_login(){Label magL=new Label("管理员查询系统");VBox vBox=new VBox();vBox.setAlignment(Pos.CENTER);vBox.setSpacing(30);Button informationB= new Button("查询学生信息");Button courseB=new Button("查看课程");Button gradeB=new Button("查看学生成绩");Button rebackB=new Button("返回登录界面");rebackB.setOnAction(actionEvent -> {otherView.login();});informationB.setOnAction(actionEvent -> {try {magStudent();} catch (Exception e) {e.printStackTrace();}});courseB.setOnAction(actionEvent -> {try {magCourse();} catch (Exception e) {e.printStackTrace();}});gradeB.setOnAction(actionEvent -> {try {magScore();} catch (Exception e) {e.printStackTrace();}});rebackB.setOnAction(actionEvent -> {try {otherView.login();} catch (Exception e) {e.printStackTrace();}});Font font = Font.font("Comic Sans MS", FontWeight.BOLD, FontPosture.REGULAR, 20);magL.setFont(font);informationB.setFont(font);courseB.setFont(font);gradeB.setFont(font);rebackB.setFont(font);magL.setTextFill(Color.BLACK);informationB.setTextFill(Color.BLUE);courseB.setTextFill(Color.BLUE);gradeB.setTextFill(Color.BLUE);rebackB.setTextFill(Color.BLUE);vBox.getChildren().addAll(magL,informationB,courseB,gradeB,rebackB);Scene scene=new Scene(vBox,360,400);endView.stage.setScene(scene);}//管理员查看学生信息界面public static void magStudent() throws Exception {BorderPane bp=new BorderPane();TableView<student> tableView = createTableView1();Label studentL=new Label("学生信息管理");Button addB=new Button("添加学生");Button updateB=new Button("修改学生");Button deleteB=new Button("删除学生");Button backB=new Button("返回");addB.setOnAction(actionEvent -> {try {studentUtil.studentAdd();} catch (Exception e) {throw new RuntimeException(e);}});updateB.setOnAction(actionEvent -> {try {studentUtil.studentUpdate();} catch (Exception e) {throw new RuntimeException(e);}});deleteB.setOnAction(actionEvent -> {try {studentUtil.studentDelete();} catch (Exception e) {throw new RuntimeException(e);}});backB.setOnAction(actionEvent -> {mag_login();});addB.setMinWidth(70);updateB.setMinWidth(70);deleteB.setMinWidth(70);addB.setMinHeight(35);updateB.setMinHeight(35);deleteB.setMinHeight(35);addB.setTextFill(Color.INDIANRED);updateB.setTextFill(Color.INDIANRED);deleteB.setTextFill(Color.INDIANRED);backB.setTextFill(Color.INDIANRED);addB.setBorder(Border.stroke(Color.LIGHTPINK));updateB.setBorder(Border.stroke(Color.LIGHTPINK));deleteB.setBorder(Border.stroke(Color.LIGHTPINK));backB.setBorder(Border.stroke(Color.LIGHTPINK));backB.setOnAction(actionEvent -> {mag_login();});Font font = Font.font("Comic Sans MS", FontWeight.BOLD, FontPosture.REGULAR, 20);studentL.setFont(font);studentL.setTextFill(Color.RED);VBox vBox=new VBox();vBox.getChildren().addAll(studentL,addB,updateB,deleteB,backB);vBox.setAlignment(Pos.CENTER);vBox.setSpacing(20);vBox.setPadding(new Insets(50));BorderPane bp1=new BorderPane();bp1.setTop(vBox);BorderPane bp2=new BorderPane();bp2.setRight(tableView);// 获取学生列表,将集合转换成ObservableListArrayList<student> students = studentDao.initStudent();// 将学生列表转换为ObservableListObservableList<student> stuObs = FXCollections.observableArrayList(students);// 将 ObservableList 设置为 TableView 的数据源tableView.setItems(stuObs);bp.setLeft(bp1);bp.setCenter(bp2);Scene scene = new Scene(bp, 650, 350);endView.stage.setScene(scene);}//绑定学生面板public static TableView<student> createTableView1() {TableView<student> tableView = new TableView<>();TableColumn<student, Integer> idCol = new TableColumn<>("ID");idCol.setCellValueFactory(cellData -> new SimpleIntegerProperty(cellData.getValue().getStu_id()).asObject());TableColumn<student, String> classCol = new TableColumn<>("班级");classCol.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().getStu_class()));TableColumn<student, String> nameCol = new TableColumn<>("姓名");nameCol.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().getStu_name()));TableColumn<student, String> sexCol = new TableColumn<>("性别");sexCol.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().getStu_gender()));TableColumn<student, String> birthCol = new TableColumn<>("出生日期");birthCol.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().getStu_birth()));TableColumn<student, String> majorCol = new TableColumn<>("所在班级");majorCol.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().getStu_major()));// 添加其他表格列...tableView.getColumns().addAll(idCol, classCol, nameCol,sexCol,birthCol,majorCol);return tableView;}//管理员查看课程界面public static void magCourse() throws Exception {//创建面板BorderPane bp=new BorderPane();//创建第二面板TableView<course> tableView = createTableView2();Label studentL=new Label("学生课程管理");Button addB=new Button("添加课程");Button updateB=new Button("修改课程");Button deleteB=new Button("删除课程");Button backB=new Button("返回");addB.setOnAction(actionEvent -> {try {courseUtil.courseAdd();} catch (Exception e) {throw new RuntimeException(e);}});updateB.setOnAction(actionEvent -> {courseUtil.courseUpdate();});deleteB.setOnAction(actionEvent -> {courseUtil.courseDelete();});backB.setOnAction(actionEvent -> {mag_login();});addB.setMinWidth(70);updateB.setMinWidth(70);deleteB.setMinWidth(70);addB.setMinHeight(35);updateB.setMinHeight(35);deleteB.setMinHeight(35);addB.setTextFill(Color.INDIANRED);updateB.setTextFill(Color.INDIANRED);deleteB.setTextFill(Color.INDIANRED);backB.setTextFill(Color.INDIANRED);addB.setBorder(Border.stroke(Color.LIGHTPINK));updateB.setBorder(Border.stroke(Color.LIGHTPINK));deleteB.setBorder(Border.stroke(Color.LIGHTPINK));backB.setBorder(Border.stroke(Color.LIGHTPINK));Font font = Font.font("Comic Sans MS", FontWeight.BOLD, FontPosture.REGULAR, 20);studentL.setFont(font);studentL.setTextFill(Color.RED);VBox vBox=new VBox();vBox.getChildren().addAll(studentL,addB,updateB,deleteB,backB);vBox.setAlignment(Pos.CENTER);vBox.setSpacing(20);vBox.setPadding(new Insets(50));BorderPane bp1=new BorderPane();bp1.setTop(vBox);BorderPane bp2=new BorderPane();bp2.setRight(tableView);// 获取学生列表ArrayList<course> courses = courseDao.initCourse();// 将学生列表转换为ObservableListObservableList<course> stuObs = FXCollections.observableArrayList(courses);// 将 ObservableList 设置为 TableView 的数据源tableView.setItems(stuObs);bp.setLeft(bp1);bp.setCenter(bp2);Scene scene = new Scene(bp, 700, 350);endView.stage.setScene(scene);}//绑定课程面板public static TableView<course> createTableView2() {TableView<course> tableView = new TableView<>();TableColumn<course, Integer> idCol = new TableColumn<>("课程号");idCol.setCellValueFactory(cellData -> new SimpleIntegerProperty(cellData.getValue().getCou_id()).asObject());TableColumn<course, String> majorCol = new TableColumn<>("所属专业");majorCol.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().getCou_major()));TableColumn<course, String> nameCol = new TableColumn<>("课程名称");nameCol.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().getCou_name()));TableColumn<course, String> typeCol = new TableColumn<>("课程类型");typeCol.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().getCou_type()));TableColumn<course, String> beginCol = new TableColumn<>("开课学期");beginCol.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().getCou_beginTime()));TableColumn<course, Integer> studyCol = new TableColumn<>("学时数");studyCol.setCellValueFactory(cellData -> new SimpleIntegerProperty(cellData.getValue().getCou_studyTime()).asObject());TableColumn<course, Integer> scoreCol = new TableColumn<>("学分");scoreCol.setCellValueFactory(cellData -> new SimpleIntegerProperty(cellData.getValue().getCou_score()).asObject());tableView.getColumns().addAll(idCol, majorCol, nameCol,typeCol,beginCol,studyCol,scoreCol);return tableView;}//管理员查看学生成绩界面public static void magScore() throws Exception {BorderPane bp=new BorderPane();TableView<score> tableView = createTableView3();Label studentL=new Label("学生成绩管理");Button addB=new Button("添加成绩");Button updateB=new Button("修改成绩");Button deleteB=new Button("删除成绩");Button rebackB=new Button("返回");addB.setOnAction(actionEvent -> {scoreUtil.scoreAdd();});updateB.setOnAction(actionEvent -> {scoreUtil.scoreUpdate();});deleteB.setOnAction(actionEvent -> {scoreUtil.scoreDelete();});rebackB.setOnAction(actionEvent -> {mag_login();});addB.setMinWidth(70);updateB.setMinWidth(70);deleteB.setMinWidth(70);addB.setMinHeight(35);updateB.setMinHeight(35);deleteB.setMinHeight(35);addB.setTextFill(Color.INDIANRED);updateB.setTextFill(Color.INDIANRED);deleteB.setTextFill(Color.INDIANRED);rebackB.setTextFill(Color.INDIANRED);addB.setBorder(Border.stroke(Color.LIGHTPINK));updateB.setBorder(Border.stroke(Color.LIGHTPINK));deleteB.setBorder(Border.stroke(Color.LIGHTPINK));rebackB.setBorder(Border.stroke(Color.LIGHTPINK));Font font = Font.font("Comic Sans MS", FontWeight.BOLD, FontPosture.REGULAR, 20);studentL.setFont(font);studentL.setTextFill(Color.RED);VBox vBox=new VBox();vBox.getChildren().addAll(studentL,addB,updateB,deleteB,rebackB);vBox.setAlignment(Pos.CENTER);vBox.setSpacing(10);vBox.setPadding(new Insets(40));BorderPane bp1=new BorderPane();bp1.setTop(vBox);BorderPane bp2=new BorderPane();bp2.setRight(tableView);// 获取学生列表ArrayList<score> scores = scoreDao.initScore();// 将学生列表转换为ObservableListObservableList<score> stuObs = FXCollections.observableArrayList(scores);// 将 ObservableList 设置为 TableView 的数据源tableView.setItems(stuObs);bp.setLeft(bp1);bp.setCenter(bp2);Scene scene = new Scene(bp, 450, 300);endView.stage.setScene(scene);}//绑定成绩面板public static TableView<score> createTableView3() {TableView<score> tableView = new TableView<>();TableColumn<score, Integer> stuCol = new TableColumn<>("学号");stuCol.setCellValueFactory(cellData -> new SimpleIntegerProperty(cellData.getValue().getScore_id()).asObject());TableColumn<score, Integer> idCol = new TableColumn<>("课程号");idCol.setCellValueFactory(cellData -> new SimpleIntegerProperty(cellData.getValue().getScore_cid()).asObject());TableColumn<score, String> studyCol = new TableColumn<>("学数");studyCol.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().getSocre_score()));TableColumn<score, String> scoreCol = new TableColumn<>("学分");scoreCol.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().getScore_credit()));tableView.getColumns().addAll(stuCol,idCol,studyCol,scoreCol);return tableView;}
}

管理员工具类:

管理员工具类是对进入操作页面中的添加学生,修改学生,删除学生,添加课程...的操作


学生(studentUtil):

    //添加学生信息public static void studentAdd() throws Exception {//添加面板GridPane gp=new GridPane();Label idL=new Label("学号");Label classL=new Label("班级");Label nameL=new Label("姓名");Label sexL=new Label("性别");Label birthL=new Label("出生日期");Label majorL=new Label("所在专业");Label passwordL=new Label("密码");//添加按钮Button admitB=new Button("提交");Button backB=new Button("返回");//设置字体样式Font font = Font.font("Comic Sans MS", FontWeight.BOLD, FontPosture.REGULAR, 15);idL.setFont(font);classL.setFont(font);nameL.setFont(font);sexL.setFont(font);birthL.setFont(font);majorL.setFont(font);//添加输入框TextField idT=new TextField(String.valueOf(judgeDao.maxID()+1));TextField classT=new TextField();TextField nameT=new TextField();TextField sexT=new TextField();TextField birthT=new TextField();TextField majorT=new TextField();TextField passwordT=new TextField();//将组件添加到面板当中gp.add(idL,0,0);gp.add(idT,1,0);gp.add(classL,0,1);gp.add(classT,1,1);gp.add(nameL,0,2);gp.add(nameT,1,2);gp.add(sexL,0,3);gp.add(sexT,1,3);gp.add(birthL,0,4);gp.add(birthT,1,4);gp.add(majorL,0,5);gp.add(majorT,1,5);gp.add(passwordL,0,6);gp.add(passwordT,1,6);gp.add(admitB,0,7);gp.add(backB,1,7);//设置面板样式gp.setPadding(new Insets(30));gp.setVgap(20);gp.setHgap(10);Scene scene=new Scene(gp,300,400);Stage stage=new Stage();stage.setScene(scene);stage.setTitle("添加学生信息");stage.show();backB.setOnAction(actionEvent -> {try {stage.close();} catch (Exception e) {throw new RuntimeException(e);}});//给提交按钮添加监听事件admitB.setOnAction(actionEvent -> {try {// 获取文本框中的内容并去除首尾空白String id = idT.getText().trim();String clazz = classT.getText().trim();String name = nameT.getText().trim();String sex = sexT.getText().trim();String birth = birthT.getText().trim();String major = majorT.getText().trim();String password = passwordT.getText().trim();// 首先进行基本的非空验证,如果有任何一个字段为空,则不进行添加操作if (id.isEmpty() || clazz.isEmpty() || name.isEmpty() || sex.isEmpty() || birth.isEmpty() || major.isEmpty() || password.isEmpty()) {otherView.tipJframe("字段不能为空");return;}else if(!((sex.equals("男")||sex.equals("女")))){otherView.tipJframe("请输入正常性别");return;}else if(!judgeUtil.isValidDate(birth)){otherView.tipJframe("日期格式不正确,请重新输入");return;}else if(!clazz.equals(judgeUtil.isClass(id))){otherView.tipJframe("班级格式不正确,请重新输入");return;}else if(!password.equals(judgeUtil.isPassword(id))){otherView.tipJframe("密码格式错误,请重新输入");return;}int studentId = Integer.parseInt(id);// 调用Dao层方法尝试添加学生信息if (studentDao.addStudent(studentId, clazz, name, sex, birth, major, password)) {// 添加成功后的操作studentDao.initStudent();magView.magStudent();otherView.tipJframe("添加成功");}else {otherView.tipJframe("添加失败");}} catch (Exception e) {// 捕获其他异常并打印堆栈信息e.printStackTrace();otherView.tipJframe("操作失败:" + e.getMessage()); // 提示操作失败,并显示具体的异常信息}});}//修改学生信息public static void studentUpdate(){//创建第一个面板GridPane gp = new GridPane();Label idl = new Label("ID");TextField idt = new TextField();//创建第一个界面的按钮Button admitb = new Button("提交");Button backb = new Button("返回");gp.add(idl,0,0);gp.add(idt,1,0);gp.add(admitb,0,1);gp.add(backb,0,2);gp.setHgap(20);gp.setVgap(10);gp.setAlignment(Pos.CENTER);Scene scene=new Scene(gp,240,140);//创建第一个舞台Stage stage=new Stage();stage.setScene(scene);stage.setResizable(false);stage.setTitle("修改学生信息");stage.show();backb.setOnAction(actionEvent -> {try {stage.close();} catch (Exception e) {throw new RuntimeException(e);}});// 创建第二个舞台Stage stage1 = new Stage();//创建只能存储一个字符的字符串final int[] id = new int[1];final String[] clas = new String[1];final String[] names = new String[1];final String[] sexs = new String[1];final String[] births = new String[1];final String[] majors = new String[1];final String[] passwords=new String[1];GridPane gp1=new GridPane();Label idL=new Label("学号");Label classL=new Label("班级");Label nameL=new Label("姓名");Label sexL=new Label("性别");Label birthL=new Label("出生日期");Label majorL=new Label("所在专业");Label passwordL=new Label("密码");Button admitB=new Button("提交");Button rebackB=new Button("返回");rebackB.setOnAction(actionEvent -> {stage1.close();});//创建显示信息文本框TextField idT=new TextField(String.valueOf(id[0]));TextField classT=new TextField(clas[0]);TextField nameT=new TextField(names[0]);TextField sexT=new TextField(sexs[0]);TextField birthT=new TextField(births[0]);TextField majorT=new TextField(majors[0]);TextField passwordT=new TextField(passwords[0]);Font font = Font.font("Comic Sans MS", FontWeight.BOLD, FontPosture.REGULAR, 15);idL.setFont(font);classL.setFont(font);nameL.setFont(font);sexL.setFont(font);birthL.setFont(font);majorL.setFont(font);gp1.add(idL,0,0);gp1.add(idT,1,0);gp1.add(classL,0,1);gp1.add(classT,1,1);gp1.add(nameL,0,2);gp1.add(nameT,1,2);gp1.add(sexL,0,3);gp1.add(sexT,1,3);gp1.add(birthL,0,4);gp1.add(birthT,1,4);gp1.add(majorL,0,5);gp1.add(majorT,1,5);gp1.add(passwordL,0,6);gp1.add(passwordT,1,6);gp1.add(admitB,0,7);gp1.add(rebackB,1,7);gp1.setPadding(new Insets(30));gp1.setVgap(20);gp1.setHgap(10);Scene scene1=new Scene(gp1,300,400);stage1.setScene(scene1);stage1.setResizable(false);stage1.setTitle("修改学生信息");stage1.close();//第一个界面的提交按钮admitb.setOnAction(actionEvent -> {String idText = idt.getText().trim();if (!idText.isEmpty()) {try {if (studentDao.isStudent(Integer.parseInt(idText))) {endView.student0=studentDao.returnStudent(Integer.parseInt(idText));id[0] = endView.student0.getStu_id();clas[0] = endView.student0.getStu_class();names[0] = endView.student0.getStu_name();sexs[0] = endView.student0.getStu_gender();births[0] = endView.student0.getStu_birth();majors[0] = endView.student0.getStu_major();passwords[0]=endView.student0.getStu_password();// 将值设置到文本框中idT.setText(String.valueOf(id[0]));classT.setText(clas[0]);nameT.setText(names[0]);sexT.setText(sexs[0]);birthT.setText(births[0]);majorT.setText(majors[0]);passwordT.setText(passwords[0]);// 显示舞台stage1.show();} else {otherView.tipJframe("不存在该学生");}} catch (Exception e) {throw new RuntimeException(e);}} else {otherView.tipJframe("ID不能为空");}});//第二个界面的提交按钮admitB.setOnAction(actionEvent -> {try {String idd = idT.getText().trim();String clazz = classT.getText().trim();String name = nameT.getText().trim();String sex = sexT.getText().trim();String birth = birthT.getText().trim();String major = majorT.getText().trim();String password=passwordT.getText().trim();// 首先进行基本的非空验证,如果有任何一个字段为空,则不进行添加操作if (idd.isEmpty() || clazz.isEmpty() || name.isEmpty() || sex.isEmpty() || birth.isEmpty() || major.isEmpty()) {otherView.tipJframe("所有字段不能为空");return;}else if(!((sex.equals("男")||sex.equals("女")))){otherView.tipJframe("请输入正常性别");return;}else if(!judgeUtil.isValidDate(birth)){otherView.tipJframe("日期格式不正确,请重新输入");return;}else if(!clazz.equals(judgeUtil.isClass(idd))){otherView.tipJframe("班级格式不正确,请重新输入");return;}else if(!password.equals(judgeUtil.isPassword(idd))){otherView.tipJframe("密码格式错误,请重新输入");return;}int studentId = Integer.parseInt(idd);//判断如果学号发生改变,则进行添加学生操作,否者进行修改操作//如果发生修改if(id[0]!=Integer.valueOf(idT.getText().trim())){if (studentDao.addStudent(studentId, clazz, name, sex, birth, major,password)) {// 添加成功后的操作if(studentDao.deleteStudent(id[0])){studentDao.initStudent();magView.magStudent();otherView.tipJframe("修改成功");}} else {otherView.tipJframe("修改失败");}}//如果没有发生修改,那么进行修改操作else {if (studentDao.updateStudent(studentId, clazz, name, sex, birth, major,password)) {// 添加成功后的操作studentDao.initStudent();magView.magStudent();otherView.tipJframe("修改成功");} else {otherView.tipJframe("修改失败");}}} catch (Exception e) {e.printStackTrace();otherView.tipJframe("操作失败:" + e.getMessage());}});}//删除学生信息public static void studentDelete(){GridPane gp = new GridPane();Label idL = new Label("ID");TextField idT = new TextField();Button admitB = new Button("提交");Button backB = new Button("返回");// 将按钮事件处理移到这里,确保在点击按钮时获取最新的文本框内容gp.add(idL, 0, 0);gp.add(idT, 1, 0);gp.add(admitB, 0, 1);gp.add(backB, 1, 1);gp.setAlignment(Pos.CENTER);gp.setHgap(10);gp.setVgap(30);//创建一个删除学生的界面舞台Stage stage = new Stage();Scene scene = new Scene(gp, 240, 100);stage.setScene(scene);stage.setTitle("删除学生信息");stage.setResizable(false);stage.show();//如果舞台退出,则界面关闭backB.setOnAction(actionEvent -> {try {stage.close();} catch (Exception e) {throw new RuntimeException(e);}});//对按钮添加点击事件admitB.setOnAction(actionEvent -> {String ids = idT.getText().trim();if (!ids.isEmpty()) {try {int id = Integer.parseInt(ids);if (studentDao.isStudent(id)) {if (studentDao.deleteStudent(id)) {otherView.tipJframe("学生删除成功");//更新数据库信息studentDao.initStudent();//更新面板信息magView.magStudent();} else {otherView.tipJframe("学生删除失败");}} else {otherView.tipJframe("未找到该学生");}} catch (NumberFormatException e) {otherView.tipJframe("请输入有效的数字ID");} catch (Exception e) {e.printStackTrace();otherView.tipJframe("数据库操作失败");}} else {otherView.tipJframe("请输入学生ID");}});}

课程(courseUtil):

//添加课程public static void courseAdd() throws Exception {//创建面板GridPane gp=new GridPane();Label cIDL=new Label("课程号");Label cMajorL=new Label("所属专业");Label cNameL=new Label("课程名称");Label cTypeL=new Label("课程类型");Label cBeginL=new Label("开课学期");Label cStudyL=new Label("学时数");Label cCreditL=new Label("学分");//创建按钮Button admitB=new Button("提交");Button backB=new Button("返回");//创建字体样式Font font = Font.font("Comic Sans MS", FontWeight.BOLD, FontPosture.REGULAR, 15);cIDL.setFont(font);cMajorL.setFont(font);cNameL.setFont(font);cTypeL.setFont(font);cBeginL.setFont(font);cStudyL.setFont(font);cCreditL.setFont(font);//创建文本输入框TextField cIDT=new TextField(String.valueOf(judgeDao.maxcID()+1));TextField cMajorT=new TextField();TextField cNameT=new TextField();TextField cTypeT=new TextField();TextField cBeginT=new TextField();TextField cStudyT=new TextField();TextField cCreditT=new TextField();//将节点添加到面板当中gp.add(cIDL,0,0);gp.add(cIDT,1,0);gp.add(cMajorL,0,1);gp.add(cMajorT,1,1);gp.add(cNameL,0,2);gp.add(cNameT,1,2);gp.add(cTypeL,0,3);gp.add(cTypeT,1,3);gp.add(cBeginL,0,4);gp.add(cBeginT,1,4);gp.add(cStudyL,0,5);gp.add(cStudyT,1,5);gp.add(cCreditL,0,6);gp.add(cCreditT,1,6);gp.add(admitB,0,7);gp.add(backB,1,7);//设置面板gp.setPadding(new Insets(30));gp.setVgap(20);gp.setHgap(10);Scene scene=new Scene(gp,350,400);Stage stage=new Stage();stage.setResizable(false);stage.setTitle("添加课程");stage.setScene(scene);stage.show();backB.setOnAction(actionEvent -> {try {stage.close();} catch (Exception e) {throw new RuntimeException(e);}});admitB.setOnAction(actionEvent -> {try {// 获取文本框中的内容并去除首尾空白String id = cIDT.getText().trim();String major = cMajorT.getText().trim();String name = cNameT.getText().trim();String type = cTypeT.getText().trim();String begin = cBeginT.getText().trim();String study = cStudyT.getText().trim();String credit = cCreditT.getText().trim();// 首先进行基本的非空验证,如果有任何一个字段为空,则不进行添加操作if ((id.isEmpty() || major.isEmpty() || name.isEmpty() || type.isEmpty() || begin.isEmpty() || study.isEmpty() || credit.isEmpty())) {otherView.tipJframe("字段不能为空");return;}// 尝试将id和password转换为整数,如果格式不正确会抛出NumberFormatExceptionint cId = Integer.parseInt(id);int studytime=Integer.parseInt(study);int creditt=Integer.parseInt(credit);if (courseDao.addCourse(cId, major, name, type, begin, studytime, creditt)) {// 添加成功后的操作courseDao.initCourse();magView.magCourse();otherView.tipJframe("课程添加成功");} else {otherView.tipJframe("课程添加失败");}} catch (Exception e) {// 捕获其他异常并打印堆栈信息e.printStackTrace();otherView.tipJframe("操作失败:" + e.getMessage());}});}//修改课程public static void courseUpdate(){//创建第一个面板GridPane gp = new GridPane();Label idl = new Label("cID");TextField idt = new TextField();//创建第一个界面的按钮Button admitb = new Button("提交");Button backB = new Button("返回");gp.add(idl,0,0);gp.add(idt,1,0);gp.add(admitb,0,1);gp.add(backB,0,2);gp.setHgap(20);gp.setVgap(10);gp.setAlignment(Pos.CENTER);Scene scene=new Scene(gp,250,140);Stage stage=new Stage();stage.setTitle("修改课程");stage.setScene(scene);stage.show();backB.setOnAction(actionEvent -> {try {stage.close();} catch (Exception e) {throw new RuntimeException(e);}});//第二个舞台Stage stage1 = new Stage();//创建只能存储一个字符串的数组final int[] id = new int[1];final String[] major = new String[1];final String[] name = new String[1];final String[] type = new String[1];final String[] begin = new String[1];final int[] studytime = new int[1];final int[] credit = new int[1];// 创建显示信息文本框TextField idT = new TextField(String.valueOf(id[0]));TextField majorT = new TextField(major[0]);TextField nameT = new TextField(name[0]);TextField typeT = new TextField(type[0]);TextField beginT = new TextField(begin[0]);TextField studyTime = new TextField(String.valueOf(studytime[0]));TextField creditT = new TextField(String.valueOf(credit[0]));//创建第二个面板GridPane gp1=new GridPane();Label cID=new Label("课程号");Label cMajor=new Label("所属专业");Label cName=new Label("课程名称");Label cType=new Label("课程类型");Label cBegin=new Label("开课学期");Label cStudy=new Label("学时数");Label cCredit=new Label("学分");Button admitB=new Button("提交");Button rebackB=new Button("返回");rebackB.setOnAction(actionEvent -> {try {stage1.close();} catch (Exception e) {throw new RuntimeException(e);}});//创建字体样式Font font = Font.font("Comic Sans MS", FontWeight.BOLD, FontPosture.REGULAR, 15);cID.setFont(font);cMajor.setFont(font);cName.setFont(font);cType.setFont(font);cBegin.setFont(font);cStudy.setFont(font);cCredit.setFont(font);gp1.add(cID,0,0);gp1.add(idT,1,0);gp1.add(cMajor,0,1);gp1.add(majorT,1,1);gp1.add(cName,0,2);gp1.add(nameT,1,2);gp1.add(cType,0,3);gp1.add(typeT,1,3);gp1.add(cBegin,0,4);gp1.add(beginT,1,4);gp1.add(cStudy,0,5);gp1.add(studyTime,1,5);gp1.add(cCredit,0,6);gp1.add(creditT,1,6);gp1.add(admitB,0,7);gp1.add(rebackB,1,7);gp1.setPadding(new Insets(30));gp1.setVgap(20);gp1.setHgap(10);Scene scene1=new Scene(gp1,300,400);stage1.setScene(scene1);stage1.setTitle("修改课程");stage1.setResizable(false);stage1.close();String idText = idt.getText().trim();//创建第一个按钮的点击事件admitb.setOnAction(actionEvent -> {if (idText.isEmpty()) {otherView.tipJframe("id不能为空");}else {try {if (courseDao.isCourse(Integer.parseInt(idText))) {endView.course0 = courseDao.returnCourse(Integer.parseInt(idText));//给数组字符串赋值id[0] = endView.course0.getCou_id();major[0] = endView.course0.getCou_major();name[0] = endView.course0.getCou_name();type[0] = endView.course0.getCou_type();begin[0] = endView.course0.getCou_beginTime();studytime[0] = endView.course0.getCou_studyTime();credit[0] = endView.course0.getCou_score();// 更新界面元素,确保在JavaFX应用线程上更新Platform.runLater(() -> {idT.setText(String.valueOf(id[0]));majorT.setText(major[0]);nameT.setText(name[0]);typeT.setText(type[0]);beginT.setText(begin[0]);studyTime.setText(String.valueOf(studytime[0]));creditT.setText(String.valueOf(credit[0]));});// 显示舞台stage1.show();} else {otherView.tipJframe("不存在该课程");}} catch (Exception e) {otherView.tipJframe("发生异常: " + e.getMessage());}}});//创建第二个面板的按钮的点击事件admitB.setOnAction(actionEvent -> {try {// 获取文本框中的内容并去除首尾空白String ids = idT.getText().trim();String majors = majorT.getText().trim();String names = nameT.getText().trim();String types = typeT.getText().trim();String begins = beginT.getText().trim();String studys = studyTime.getText().trim();String credits = creditT.getText().trim();// 首先进行基本的非空验证,如果有任何一个字段为空,则不进行添加操作if (ids.isEmpty() || majors.isEmpty() || names.isEmpty() || types.isEmpty() || begins.isEmpty() || studys.isEmpty() || credits.isEmpty()) {otherView.tipJframe("字段不能为空");return;}int cId = Integer.parseInt(ids);int study=Integer.parseInt(studys);int creditt=Integer.parseInt(credits);if(!(id[0]==Integer.valueOf(idText))){if(courseDao.addCourse(cId, majors, names, types, begins, study, creditt)){courseDao.deleteCourse(id[0]);courseDao.initCourse();magView.magCourse();otherView.tipJframe("课程修改成功");}else {// 添加失败的提示otherView.tipJframe("课程修改失败");}}else if(id[0]==Integer.valueOf(idText)){// 调用Dao层方法尝试添加学生信息if (courseDao.updateCourse(cId, majors, names, types, begins, study, creditt)) {// 添加成功后的操作courseDao.initCourse();magView.magCourse();otherView.tipJframe("课程修改成功");} else {// 添加失败的提示otherView.tipJframe("课程修改失败");}}} catch (Exception e) {e.printStackTrace();otherView.tipJframe("操作失败:" + e.getMessage()); // 提示操作失败,并显示具体的异常信息}});}//删除课程public static void courseDelete(){GridPane gp = new GridPane();Label idL = new Label("ID");TextField idT = new TextField();Button admitB = new Button("提交");Button backB = new Button("返回");gp.add(idL, 0, 0);gp.add(idT, 1, 0);gp.add(admitB, 0, 1);gp.add(backB, 1, 1);gp.setAlignment(Pos.CENTER);gp.setHgap(10);gp.setVgap(30);Stage stage = new Stage();Scene scene = new Scene(gp, 240, 100);stage.setTitle("删除课程");stage.setScene(scene);stage.show();backB.setOnAction(actionEvent -> {try {stage.close();} catch (Exception e) {throw new RuntimeException(e);}});// 将按钮事件处理移到这里,确保在点击按钮时获取最新的文本框内容admitB.setOnAction(actionEvent -> {String ids = idT.getText().trim(); // 获取文本框内容if (!ids.isEmpty()) {try {int id = Integer.parseInt(ids);if (courseDao.isCourse(id)) {if (courseDao.deleteCourse(id)) {otherView.tipJframe("课程删除成功");courseDao.initCourse(); // 更新数据magView.magCourse(); // 刷新界面信息} else {otherView.tipJframe("课程删除失败");}} else {otherView.tipJframe("未找到该课程");}} catch (Exception e) {e.printStackTrace();otherView.tipJframe("数据库操作失败");}} else {otherView.tipJframe("请输入课程ID");}});}

分数(scoreUtil):

    //添加成绩public static void scoreAdd(){GridPane gp=new GridPane();Label sID=new Label("学号");Label sCID=new Label("课程号");Label sStudy=new Label("成绩");Label sCredit=new Label("学分");Button admitB=new Button("提交");Button rebackB=new Button("返回");Font font = Font.font("Comic Sans MS", FontWeight.BOLD, FontPosture.REGULAR, 15);sID.setFont(font);sCID.setFont(font);sStudy.setFont(font);sCredit.setFont(font);TextField sIDT=new TextField();TextField scIDT=new TextField();TextField sStudyT=new TextField();TextField sCreditT=new TextField();gp.add(sID,0,0);gp.add(sIDT,1,0);gp.add(sCID,0,1);gp.add(scIDT,1,1);gp.add(sStudy,0,2);gp.add(sStudyT,1,2);gp.add(sCredit,0,3);gp.add(sCreditT,1,3);gp.add(admitB,0,7);gp.add(rebackB,1,7);gp.setPadding(new Insets(30));gp.setVgap(20);gp.setHgap(10);Scene scene=new Scene(gp,280,300);Stage stage1=new Stage();stage1.setScene(scene);stage1.setTitle("添加分数");stage1.show();rebackB.setOnAction(actionEvent -> {try {stage1.close();} catch (Exception e) {throw new RuntimeException(e);}});admitB.setOnAction(actionEvent -> {try {// 获取文本框中的内容并去除首尾空白String id = sIDT.getText().trim();String cid = scIDT.getText().trim();String study = sStudyT.getText().trim();String credit = sCreditT.getText().trim();// 首先进行基本的非空验证,如果有任何一个字段为空,则不进行添加操作if ((id.isEmpty() || cid.isEmpty() || study.isEmpty() || credit.isEmpty())) {otherView.tipJframe("字段不能为空");return;}else if(!studentDao.isStudent(Integer.parseInt(id))){otherView.tipJframe("不存在该学生");return;}else if(!courseDao.isCourse(Integer.parseInt(cid))){otherView.tipJframe("不存在该课程");return;}int Id=Integer.parseInt(id);int cId = Integer.parseInt(cid);if (scoreDao.addScore(Id, cId, study, credit)&&scoreDao.isScore(Id,cId)) {scoreDao.initScore();magView.magScore();otherView.tipJframe("成绩添加成功");} else {// 添加失败的提示otherView.tipJframe("成绩添加失败");}} catch (NumberFormatException e) {otherView.tipJframe("ID格式错误,请输入有效的整数");} catch (Exception e) {// 捕获其他异常并打印堆栈信息e.printStackTrace();otherView.tipJframe("操作失败:" + e.getMessage());}});}//修改成绩public static void scoreUpdate(){GridPane gp=new GridPane();Label idl = new Label("ID");Label cidl=new Label("cID");TextField idt = new TextField();TextField cidt=new TextField();Button admitb = new Button("提交");Button backB=new Button("返回");gp.add(idl,0,0);gp.add(idt,1,0);gp.add(cidl,0,1);gp.add(cidt,1,1);gp.add(admitb,0,2);gp.add(backB,1,2);gp.setHgap(10);gp.setVgap(20);gp.setAlignment(Pos.CENTER);Scene scene=new Scene(gp,300,240);//创建第一个舞台Stage stage=new Stage();stage.setScene(scene);stage.setResizable(false);stage.setTitle("修改分数");stage.show();backB.setOnAction(actionEvent -> {stage.close();});//创建第二个面板GridPane gp1 = new GridPane();final int[] id = new int[1];final int[] cid = new int[1];TextField sIDT=new TextField(String.valueOf(id[0]));TextField scIDT=new TextField(String.valueOf(cid[0]));TextField sStudyT=new TextField();TextField sCreditT=new TextField();Label sID=new Label("学号");Label sCID=new Label("课程号");Label sStudy=new Label("成绩");Label sCredit=new Label("学分");Button admitB=new Button("提交");Button rebackB=new Button("返回");Font font = Font.font("Comic Sans MS", FontWeight.BOLD, FontPosture.REGULAR, 15);sID.setFont(font);sCID.setFont(font);sStudy.setFont(font);sCredit.setFont(font);gp1.add(sID,0,0);gp1.add(sIDT,1,0);gp1.add(sCID,0,1);gp1.add(scIDT,1,1);gp1.add(sStudy,0,2);gp1.add(sStudyT,1,2);gp1.add(sCredit,0,3);gp1.add(sCreditT,1,3);gp1.add(admitB,0,7);gp1.add(rebackB,1,7);gp1.setPadding(new Insets(30));gp1.setVgap(20);gp1.setHgap(10);Scene scene1=new Scene(gp1,280,300);//创建第二个舞台Stage stage1 = new Stage();stage1.setScene(scene1);stage1.setTitle("修改分数");stage1.setResizable(false);stage1.close();rebackB.setOnAction(actionEvent -> {try {stage1.close();} catch (Exception e) {throw new RuntimeException(e);}});// 登录按钮的事件处理器admitb.setOnAction(actionEvent -> {String idText = idt.getText().trim();String cidText = cidt.getText().trim();if (!(idText.isEmpty() || cidText.isEmpty())) {try {if (judgeUtil.isDigits(idText) && judgeUtil.isDigits(cidText)) {if (scoreDao.isScore(Integer.parseInt(idText), Integer.parseInt(cidText))) {endView.score0 = scoreDao.returnScore(Integer.parseInt(idText),Integer.parseInt(cidText));id[0] = endView.score0.getScore_id();cid[0] = endView.score0.getScore_cid();// 更新TextField显示sIDT.setText(String.valueOf(id[0]));scIDT.setText(String.valueOf(cid[0]));// 显示舞台stage1.show();stage.close();} else if (!studentDao.isStudent(Integer.parseInt(idText))) {otherView.tipJframe("不存在该学生");} else if (!courseDao.isCourse(Integer.parseInt(cidText))) {otherView.tipJframe("不存在该课程");} else {otherView.tipJframe("信息输入错误");}} else {otherView.tipJframe("格式错误");}} catch (Exception e) {throw new RuntimeException(e);}} else {otherView.tipJframe("id不能为空");}});//第二个按钮点击事件admitB.setOnAction(actionEvent -> {try {// 获取文本框中的内容并去除首尾空白String ids = sIDT.getText().trim();String cids = scIDT.getText().trim();String studys = sStudyT.getText().trim();String credits = sCredit.getText().trim();// 首先进行基本的非空验证,如果有任何一个字段为空,则不进行添加操作if (ids.isEmpty() || cids.isEmpty() || studys.isEmpty() || credits.isEmpty()) {otherView.tipJframe("字段不能为空");return;}// 尝试将id和password转换为整数,如果格式不正确会抛出NumberFormatExceptionint Id=Integer.parseInt(ids);int cId = Integer.parseInt(cids);// 调用Dao层方法尝试添加学生信息if (scoreDao.updateScore(Id, cId, studys, credits)) {// 添加成功后的操作scoreDao.initScore();magView.magScore();otherView.tipJframe("成绩添加成功");} else {otherView.tipJframe("成绩添加失败");}} catch (NumberFormatException e) {otherView.tipJframe("ID格式错误,请输入有效的整数");} catch (Exception e) {e.printStackTrace();otherView.tipJframe("操作失败:" + e.getMessage());}});}//删除成绩public static void scoreDelete(){GridPane gp = new GridPane();Label idL = new Label("ID");Label cidL=new Label("cID");TextField idT = new TextField();TextField cidT=new TextField();Button admitB = new Button("提交");Button backB = new Button("返回");gp.add(idL, 0, 0);gp.add(idT, 1, 0);gp.add(cidL,0,1);gp.add(cidT,1,1);gp.add(admitB, 0, 2);gp.add(backB, 1, 2);gp.setAlignment(Pos.CENTER);gp.setHgap(10);gp.setVgap(30);Stage stage = new Stage();Scene scene = new Scene(gp, 240, 200);stage.setScene(scene);stage.setTitle("删除分数");stage.show();backB.setOnAction(actionEvent -> {try {stage.close();} catch (Exception e) {throw new RuntimeException(e);}});// 将按钮事件处理移到这里,确保在点击按钮时获取最新的文本框内容admitB.setOnAction(actionEvent -> {String ids = idT.getText().trim();String cids=cidT.getText().trim();if (!ids.isEmpty()) {try {int id = Integer.parseInt(ids);int cid=Integer.parseInt(cids);if (studentDao.isStudent(id)) {if (scoreDao.deleteScore(id,cid)) {otherView.tipJframe("课程删除成功");scoreDao.initScore();magView.magScore();} else {otherView.tipJframe("课程删除失败");}} else {otherView.tipJframe("未找到该课程");}} catch (NumberFormatException e) {otherView.tipJframe("请输入有效的数字ID");} catch (Exception e) {e.printStackTrace();otherView.tipJframe("数据库操作失败");}} else {otherView.tipJframe("请输入课程ID");}});}

判断工具类(judgeUtil):

这个工具类是对添加数据时一些文本框内字符串的判断,是在上面三个util中要用到的

 //判断日期格式public static boolean isValidDate(String dateStr) {try {DateTimeFormatter.ofPattern("yyyy-MM-dd").parse(dateStr);return true;} catch (DateTimeParseException e) {return false;}}//判断班级格式public static String isClass(String s){String numberString = s;int numberOfCharsToTake = 6; // 指定你想截取的字符数量String prefix = numberString.substring(0, numberOfCharsToTake);return prefix;}//判断密码格式public static String isPassword(String s){String numberString = s;int numberOfCharsToTake = 6; // 指定你想截取的字符数量从末尾开始int startIndex = numberString.length() - numberOfCharsToTake;String suffix = numberString.substring(startIndex);return suffix;}//判断字符串是否为数字public static boolean isDigits(String str) {return str.matches("\\d+");}

管理员Dao类:

utilDao:


由于Connection,close,exeupdate会被经常用到,所以在这里我就直接写成三个方法了

private static final String URL = "jdbc:mysql:///studentMs";private static final String USER = "root";private static final String PASSWORD = "123321";//获取连接对象public static Connection getCon() {try {return DriverManager.getConnection(URL, USER, PASSWORD);} catch (SQLException e) {e.printStackTrace();return null;}}//关闭资源public static void close(ResultSet rs, PreparedStatement ps, Connection con) {try {if (rs != null) {rs.close();}if (ps != null) {ps.close();}if (con != null) {con.close();}} catch (SQLException e) {e.printStackTrace();}}//执行mysqlpublic static boolean exeUpdate(String sql, Object... params) {//获取连接对象Connection con = getCon();PreparedStatement ps = null;try {//获取编译对象ps = con.prepareStatement(sql);//判断参数是否为空if (Objects.nonNull(params)) {for (int i = 0; i < params.length; i++) {//实现占位赋值ps.setObject(i + 1, params[i]);}}//执行更新return ps.executeUpdate() > 0;} catch (Exception e) {e.printStackTrace();} finally {close(null, ps, con);}return false;}

studentDao*:

下面的studentDao只与管理员的界面操作有关

 //返回学生信息public static student returnStudent(int stu_id)throws Exception{student student=new student();String sql="select stuID,stuClass,stuName,stuSex,stuBirth,stuMajor,stuPassword from student where stuID=?";PreparedStatement ps=utilDao.getCon().prepareStatement(sql);//过滤其他的只留下ID为1的学生ps.setString(1,String.valueOf(stu_id));ResultSet rs=ps.executeQuery();if(rs.next()){student.setStu_id(rs.getInt("stuID"));student.setStu_class(rs.getString("stuClass"));student.setStu_name(rs.getString("stuName"));student.setStu_gender(rs.getString("stuSex"));student.setStu_birth(rs.getString("stuBirth"));student.setStu_major(rs.getString("stuMajor"));student.setStu_password(rs.getString("stuPassword"));}rs.close();ps.close();return student;}//判断是否存在该学生public static boolean isStudent(int stu_id) throws SQLException {String sql="select stuID,stuClass,stuName,stuSex,stuBirth,stuMajor from student where stuID=?";PreparedStatement ps=utilDao.getCon().prepareStatement(sql);//过滤其他的只留下ID为1的学生ps.setString(1,String.valueOf(stu_id));ResultSet rs=ps.executeQuery();if(rs.next()){return true;}else {return false;}}// 学生类信息初始化public static ArrayList<student> initStudent() throws Exception {ArrayList<student> students = new ArrayList<>();String sql = "select * from student order by stuID asc";PreparedStatement ps = utilDao.getCon().prepareStatement(sql);ResultSet rs = ps.executeQuery();// 使用 while 循环遍历 ResultSet 中的所有行while (rs.next()) {student student = new student();student.setStu_id(rs.getInt("stuID"));student.setStu_class(rs.getString("stuClass"));student.setStu_name(rs.getString("stuName"));student.setStu_gender(rs.getString("stuSex"));student.setStu_birth(rs.getString("stuBirth"));student.setStu_major(rs.getString("stuMajor"));students.add(student);}// 关闭资源rs.close();ps.close();return students;}//添加学生public static boolean addStudent(int stuId,String stuClass,String stuName, String stuSex, String stuBirth, String stuMajor,String stuPassword)throws Exception{String sql="insert into student(stuID,stuClass,stuName,stuSex,stuBirth,stuMajor,stuPassword )values (?,?,?,?,?,?,?) ";return utilDao.exeUpdate(sql,stuId,stuClass,stuName,stuSex,stuBirth,stuMajor,stuPassword);}//修改学生public static boolean updateStudent(int stuId,String stuClass,String stuName, String stuSex, String stuBirth, String stuMajor,String stuPassword)throws Exception{String sql="update student set stuID=?,stuClass=?,stuName=?,stuSex=?,stuBirth=?,stuMajor=?,stuPassword=?";return utilDao.exeUpdate(sql,stuId,stuClass,stuName,stuSex,stuBirth,stuMajor,stuPassword);}//删除学生public static boolean deleteStudent(int stuId){String sql="delete from student where stuID=?";return utilDao.exeUpdate(sql,stuId);}

courseDao:

//返回课程public static course returnCourse(int cID)throws Exception{course course=new course();String sql="select cID,cMajor,cName,cType,cStartTerm,cPeriod,cCredit from course where cID=?";PreparedStatement ps=utilDao.getCon().prepareStatement(sql);//过滤其他的只留下ID为1的学生ps.setString(1,String.valueOf(cID));ResultSet rs=ps.executeQuery();if(rs.next()){course.setCou_id(rs.getInt("cID"));course.setCou_major(rs.getString("cMajor"));course.setCou_name(rs.getString("cName"));course.setCou_type(rs.getString("cType"));course.setCou_beginTime(rs.getString("cStartTerm"));course.setCou_studyTime(rs.getInt("cPeriod"));course.setCou_score(rs.getInt("cCredit"));}rs.close();ps.close();return course;}//判断是否存在该课程public static boolean isCourse(int cID) throws Exception {String sql="select cID,cMajor,cName,cType,cStartTerm,cPeriod,cCredit from course where cID=?";PreparedStatement ps=utilDao.getCon().prepareStatement(sql);//过滤其他的只留下ID为1的学生ps.setInt(1,cID);ResultSet rs=ps.executeQuery();if(rs.next()){return true;} else {return false;}}// 学生类集合课程初始化public static ArrayList<course> initCourse() throws Exception {ArrayList<course> courses = new ArrayList<>();String sql = "select * from course order by cID asc";PreparedStatement ps = utilDao.getCon().prepareStatement(sql);ResultSet rs = ps.executeQuery();// 使用 while 循环遍历 ResultSet 中的所有行while (rs.next()) {course course = new course();course.setCou_id(rs.getInt("cID"));course.setCou_major(rs.getString("cMajor"));course.setCou_name(rs.getString("cName"));course.setCou_type(rs.getString("cType"));course.setCou_beginTime(rs.getString("cStartTerm"));course.setCou_studyTime(rs.getInt("cPeriod"));course.setCou_score(rs.getInt("cCredit"));courses.add(course);}// 关闭资源rs.close();ps.close();return courses;}//增加课程public static boolean addCourse(int cID, String cMajor, String cName, String cType, String cStartTerm, int  cPeriod, int  cCredit){String sql="insert into course(cID,cMajor,cName,cType,cStartTerm,cPeriod,cCredit)values (?,?,?,?,?,?,?) ";return utilDao.exeUpdate(sql,cID,cMajor,cName,cType,cStartTerm,cPeriod,cCredit);}//修改课程public static boolean updateCourse(int cID, String cMajor, String cName, String cType, String cStartTerm, int  cPeriod, int cCredit){String sql="update course set cID=?,cMajor=?,cName=?,cType=?,cStartTerm=?,cPeriod=?,cCredit=? ";return utilDao.exeUpdate(sql,cID,cMajor,cName,cType,cStartTerm,cPeriod,cCredit);}//删除课程public static boolean deleteCourse(int cID){String sql="delete from course where cID=?";return utilDao.exeUpdate(sql,cID);}

scoreDao:

//判断是否存在该成绩public static boolean isScore(int stu_id,int cid) throws SQLException {String sql="select * from score where stuID=? and cID=?";PreparedStatement ps=utilDao.getCon().prepareStatement(sql);//过滤其他的只留下ID为1的学生ps.setString(1,String.valueOf(stu_id));ps.setString(2,String.valueOf(cid));ResultSet rs=ps.executeQuery();if(rs.next()){return true;}return false;}// 学生类成绩初始化public static ArrayList<score> initScore() throws Exception {ArrayList<score> scores = new ArrayList<>();String sql = "select * from score order by stuID asc ";PreparedStatement ps = utilDao.getCon().prepareStatement(sql);ResultSet rs = ps.executeQuery();// 使用 while 循环遍历 ResultSet 中的所有行while (rs.next()) {score score = new score();score.setScore_id(rs.getInt("stuID"));score.setScore_cid(rs.getInt("cID"));score.setSocre_score(rs.getString("score"));score.setScore_credit(rs.getString("credit"));scores.add(score);}// 关闭资源rs.close();ps.close();return scores;}//返回学生成绩public static score returnScore(int stuID,int cID)throws Exception{score score=new score();String sql="select * from score where stuID=? and cID=? ";PreparedStatement ps=utilDao.getCon().prepareStatement(sql);//过滤其他的只留下ID为1的学生ps.setString(1,String.valueOf(stuID));ps.setString(2,String.valueOf(cID));ResultSet rs=ps.executeQuery();while (rs.next()){score.setScore_id(rs.getInt("stuID"));score.setScore_cid(rs.getInt("cID"));score.setSocre_score(rs.getString("score"));score.setScore_credit(rs.getString("credit"));}rs.close();ps.close();return score;}//增加成绩public static boolean addScore(int stuID,int cID,String score,String credit){String sql="insert into score(stuID,cID,score,credit)values (?,?,?,?) ";return utilDao.exeUpdate(sql,stuID,cID,score,credit);}//修改成绩public static boolean updateScore(int stuID,int cID,String score,String credit){String sql="update score set stuID=?,cID=?,score=?,credit=? ";return utilDao.exeUpdate(sql,stuID,cID,score,credit);}//删除成绩public static boolean deleteScore(int stuID,int cID){String sql="delete from score where stuID=? and cID=?";return utilDao.exeUpdate(sql,stuID,cID);}

judgeDao:

//找出最大学生idpublic static int maxID() throws Exception {String sql = "select max(stuID) as maxId from student";PreparedStatement ps = utilDao.getCon().prepareStatement(sql);ResultSet rs = ps.executeQuery();// 默认值或者根据需求设定初始值int maxId = 0;//如果存在if (rs.next()) {maxId = rs.getInt("maxId"); // 从结果集中获取名为 maxId 的列的值}return maxId;}//找出最大课程idpublic static int maxcID()throws Exception{String sql = "select max(cID) as maxId from course";PreparedStatement ps = utilDao.getCon().prepareStatement(sql);ResultSet rs = ps.executeQuery();int maxId = 0; // 默认值或者根据需求设定初始值if (rs.next()) {maxId = rs.getInt("maxId"); // 从结果集中获取名为 maxId 的列的值}return maxId;}//判断是否为管理员public static boolean magLogin(String name,String password)throws Exception{String sql="select * from manager where name=? and password=?";PreparedStatement ps=utilDao.getCon().prepareStatement(sql);ps.setString(1,name);ps.setString(2,password);ResultSet rs=ps.executeQuery();if (rs.next()) {utilDao.close(rs,ps,utilDao.getCon());return true;} else {utilDao.close(rs,ps,utilDao.getCon());return false;}}

domain(对象类):

student:

public class student {private int stu_id;private String stu_class;private String stu_name;private String stu_gender;private String stu_birth;private String stu_major;private String stu_password;public student() {}public int getStu_id() {return stu_id;}public void setStu_id(int stu_id) {this.stu_id = stu_id;}public String getStu_class() {return stu_class;}public void setStu_class(String stu_class) {this.stu_class = stu_class;}public String getStu_name() {return stu_name;}public void setStu_name(String stu_name) {this.stu_name = stu_name;}public String getStu_gender() {return stu_gender;}public void setStu_gender(String stu_gender) {this.stu_gender = stu_gender;}public String getStu_birth() {return stu_birth;}public void setStu_birth(String stu_birth) {this.stu_birth = stu_birth;}public String getStu_major() {return stu_major;}public void setStu_major(String stu_major) {this.stu_major = stu_major;}public String getStu_password() {return stu_password;}public void setStu_password(String stu_password) {this.stu_password = stu_password;}

course:

public class course {private int cou_id;private String cou_major;private String cou_name;private String cou_type;private String cou_beginTime;private int cou_studyTime;private int cou_score;public course() {}public int getCou_id() {return cou_id;}public void setCou_id(int cou_id) {this.cou_id = cou_id;}public String getCou_major() {return cou_major;}public void setCou_major(String cou_major) {this.cou_major = cou_major;}public String getCou_name() {return cou_name;}public void setCou_name(String cou_name) {this.cou_name = cou_name;}public String getCou_type() {return cou_type;}public void setCou_type(String cou_type) {this.cou_type = cou_type;}public String getCou_beginTime() {return cou_beginTime;}public void setCou_beginTime(String cou_beginTime) {this.cou_beginTime = cou_beginTime;}public int getCou_studyTime() {return cou_studyTime;}public void setCou_studyTime(int cou_studyTime) {this.cou_studyTime = cou_studyTime;}public void setCou_score(int cou_score) {this.cou_score = cou_score;}public int getCou_score() {return cou_score;}

score:

private int score_id;private int score_cid;private String socre_score;private String score_credit;public score() {}public int getScore_id() {return score_id;}public String getSocre_score() {return socre_score;}public void setSocre_score(String socre_score) {this.socre_score = socre_score;}public String getScore_credit() {return score_credit;}public void setScore_credit(String score_credit) {this.score_credit = score_credit;}public void setScore_id(int score_id) {this.score_id = score_id;}public int getScore_cid() {return score_cid;}

结尾

我的代码到这里就分享完了,感谢大家的观看看到这里,由于我的代码结构比较多,这里关于上面的每一个类都是完整的,除了studentDao分开写了,我这里在重新展示一下我的studentDao代码,其他的都一样就不展示了

 

studentDao(完整):

//学生登录判断public static boolean login(String idStr, String passwordStr) throws Exception {String sql = "select * from student where stuID =? and stuPassword=?";PreparedStatement ps = utilDao.getCon().prepareStatement(sql);ps.setString(1,idStr);ps.setString(2, passwordStr);ResultSet rs = ps.executeQuery();if (rs.next()) {utilDao.close(rs,ps, utilDao.getCon());return true;} else {utilDao.close(rs,ps,utilDao.getCon());return false;}}//学生查询自己成绩public static Integer gradeOneself(int stu_id) throws Exception {String sql = "SELECT SUM(credit) AS gradesum FROM score WHERE stuID=?";try (Connection connection =utilDao.getCon();PreparedStatement ps = connection.prepareStatement(sql)) {ps.setInt(1, stu_id);try (ResultSet rs = ps.executeQuery()) {if (rs.next()) {int gradesum = rs.getInt("gradesum");return gradesum;} else {// 如果没有查询到结果,可以返回 null 或者其他合适的值return null;}}}}//返回学生信息public static student returnStudent(int stu_id)throws Exception{student student=new student();String sql="select stuID,stuClass,stuName,stuSex,stuBirth,stuMajor,stuPassword from student where stuID=?";PreparedStatement ps=utilDao.getCon().prepareStatement(sql);//过滤其他的只留下ID为1的学生ps.setString(1,String.valueOf(stu_id));ResultSet rs=ps.executeQuery();if(rs.next()){student.setStu_id(rs.getInt("stuID"));student.setStu_class(rs.getString("stuClass"));student.setStu_name(rs.getString("stuName"));student.setStu_gender(rs.getString("stuSex"));student.setStu_birth(rs.getString("stuBirth"));student.setStu_major(rs.getString("stuMajor"));student.setStu_password(rs.getString("stuPassword"));}rs.close();ps.close();return student;}//判断是否存在该学生public static boolean isStudent(int stu_id) throws SQLException {String sql="select stuID,stuClass,stuName,stuSex,stuBirth,stuMajor from student where stuID=?";PreparedStatement ps=utilDao.getCon().prepareStatement(sql);//过滤其他的只留下ID为1的学生ps.setString(1,String.valueOf(stu_id));ResultSet rs=ps.executeQuery();if(rs.next()){return true;}else {return false;}}// 学生类信息初始化public static ArrayList<student> initStudent() throws Exception {ArrayList<student> students = new ArrayList<>();String sql = "select * from student order by stuID asc";PreparedStatement ps = utilDao.getCon().prepareStatement(sql);ResultSet rs = ps.executeQuery();// 使用 while 循环遍历 ResultSet 中的所有行while (rs.next()) {student student = new student();student.setStu_id(rs.getInt("stuID"));student.setStu_class(rs.getString("stuClass"));student.setStu_name(rs.getString("stuName"));student.setStu_gender(rs.getString("stuSex"));student.setStu_birth(rs.getString("stuBirth"));student.setStu_major(rs.getString("stuMajor"));students.add(student);}// 关闭资源rs.close();ps.close();return students;}//添加学生public static boolean addStudent(int stuId,String stuClass,String stuName, String stuSex, String stuBirth, String stuMajor,String stuPassword)throws Exception{String sql="insert into student(stuID,stuClass,stuName,stuSex,stuBirth,stuMajor,stuPassword )values (?,?,?,?,?,?,?) ";return utilDao.exeUpdate(sql,stuId,stuClass,stuName,stuSex,stuBirth,stuMajor,stuPassword);}//修改学生public static boolean updateStudent(int stuId,String stuClass,String stuName, String stuSex, String stuBirth, String stuMajor,String stuPassword)throws Exception{String sql="update student set stuID=?,stuClass=?,stuName=?,stuSex=?,stuBirth=?,stuMajor=?,stuPassword=?";return utilDao.exeUpdate(sql,stuId,stuClass,stuName,stuSex,stuBirth,stuMajor,stuPassword);}//删除学生public static boolean deleteStudent(int stuId){String sql="delete from student where stuID=?";return utilDao.exeUpdate(sql,stuId);}

感谢大家的观看,如果有不懂的地方可以给我留言哦,冲! ! !

 

 

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/870659.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Vue 3 中创建一个动态的组件实例

本文将介绍如何在 Vue 3 中实现一个动态 Toast 组件实例。我们将创建一个简单的 Toast 组件&#xff0c;并使用一个动态创建实例的脚本来显示 Toast 消息。在 Vue 3 中创建动态组件实例有许多好处&#xff0c;这些好处主要体现在灵活性、性能、可维护性和用户体验等方面。 创建…

【JavaScript 算法】快速排序:高效的排序算法

&#x1f525; 个人主页&#xff1a;空白诗 文章目录 一、算法原理二、算法实现三、应用场景四、优化与扩展五、总结 快速排序&#xff08;Quick Sort&#xff09;是一种高效的排序算法&#xff0c;通过分治法将数组分为较小的子数组&#xff0c;递归地排序子数组。快速排序通常…

分享一个 .NET 通过监听器拦截 EF 消息写日志的详细例子

前言 EF 开发效率确实很高也很便捷&#xff0c;但当它发生错误时&#xff0c;也挺让人头疼的&#xff0c;为什么&#xff1f;因为 EF 就像是一个黑盒子&#xff0c;一切全被封装起来&#xff0c;出错的时候很难定位原因&#xff0c;如果能够知道并打印 EF 生成的 SQL 语句&…

记录些Redis题集(1)

为什么Redis要有淘汰机制&#xff1f; 淘汰机制的存在是必要的&#xff0c;因为Redis是一种基于内存的数据库&#xff0c;所有数据都存储在内存中。然而&#xff0c;内存资源是有限的。在Redis的配置文件redis.conf中&#xff0c;有一个关键的配置项&#xff1a; # maxmemory…

Go语言入门之Map详解

Go语言入门之Map详解 1.基础定义 map是一个无序的&#xff0c;k-v键值对格式的集合 &#xff08;1&#xff09;特点 类型特点&#xff1a;map为引用类型&#xff0c;所以在函数中更新value值会永久改变顺序特点&#xff1a;map的遍历是无序的&#xff0c;因为底层是哈希表&am…

零基础学python(二)

1. 字典 字典的创建 最常见的创建方式&#xff1a; d {"k1": "v1", "k2": "v2"} 再向字典中添加一对键值&#xff1a; d["k3"] "v3" 字典还可以用dict()创建&#xff0c;这种方式中&#xff0c;键是不加引…

【Unity2D 2022:UI】制作主菜单

一、创建主菜单游戏场景 1. 在Scenes文件夹中新建一个游戏场景Main Menu 2. 为场景添加背景 &#xff08;1&#xff09;创建画布Canvas &#xff08;2&#xff09;在Canvas中创建新的空游戏物体Main Menu &#xff08;3&#xff09;在Main Menu中新建一个图像游戏物体Backgrou…

无人机之机身保养

一、外观检查 1、检查机器表面整洁无划痕、无针孔凹陷擦伤、畸变等损坏情况&#xff1b; 2、晃动机身&#xff0c;仔细听机身内部有无松动零件或者螺丝在机身内部。 二、桨叶检查 1、有无裂痕、磨损、变形等缺陷&#xff0c;如有明显缺陷建议更换&#xff1b; 2、卡扣、紧…

Animate软件基础:图层的基本用法

图层作为Animate软件中比较重要的功能&#xff0c;需要对其使用方法和作用理解充分&#xff0c;并熟练操作才可以更好的用来制作内容。 图层相关的功能和用法如下&#xff1a; 图层可以帮助在文档中组织插图。 可以在一个图层上绘制和编辑对象&#xff0c;而不会影响其他图层…

排座椅【详细代码题解】

[NOIP2008 普及组] 排座椅 题目描述 上课的时候总会有一些同学和前后左右的人交头接耳&#xff0c;这是令小学班主任十分头疼的一件事情。不过&#xff0c;班主任小雪发现了一些有趣的现象&#xff0c;当同学们的座次确定下来之后&#xff0c;只有有限的 D D D 对同学上课时…

USB转RS485+RS232+TTL串口电路

USB转RS485RS232TTL电路 USB转RS485RS232TTL电路如下图所示&#xff0c;可实现USB转RS485RS232TTL串口&#xff0c;一个电路模块即可实现电路调试过程中用到常用接口。 电路模块上留有2.54MM单排针接口和接线端子两种接线方式&#xff0c;可接线和跳线。电路模块同时有5V和3.3V…

开源浏览器引擎对比与适用场景:WebKit、Chrome、Gecko

WebKit与Chrome的Blink引擎对比 起源与关系&#xff1a; WebKit最初由苹果公司开发&#xff0c;用于Safari浏览器。后来&#xff0c;WebKit逐渐成为一个独立的开源项目&#xff0c;被多个浏览器厂商采用。Blink是Google基于WebKit项目分支出来的一个浏览器引擎&#xff0c;用于…

文献翻译与阅读《Integration Approaches for Heterogeneous Big Data: A Survey》

CYBERNETICS AND INFORMATION TECHNOLOGIES’24 论文原文下载地址&#xff1a;原文下载 目录 1 引言 2 大数据概述 3 大数据的异构性 4 讨论整合方法 4.1 大数据仓库&#xff08;BDW&#xff09; 4.2 大数据联盟&#xff08;BDF&#xff09; 5 DW 和 DF 方法的比较、分…

C++入门基础题:数组元素逆序(C++版互换方式)

1.题目&#xff1a; 数组元素逆置案例描述: 请声明一个5个元素的数组&#xff0c;并且将元素逆置. (如原数组元素为:1,3,2,5,4;逆置后输出结果为:4,5,2,3,1) 2.图解思路&#xff1a; 3.代码演示&#xff1a; #include<iostream>using namespace std;int main(){int a…

[k8s源码]1.client-go集群外部署

client-go是由k8s发布且维护的专门用于开发者和kubernetes交互的客户端库。它支持对k8s资源的CRUD操作&#xff08;create、read、update、delete&#xff09;&#xff0c;事件监听和处理&#xff0c;访问kubernetes集群的上下文和配置。 client go是独立于kubernetes集群之外…

Rust vs Go: 特点与应用场景分析

目录 介绍Rust的特点Go的特点Rust的应用场景Go的应用场景总结 介绍 Rust和Go&#xff08;Golang&#xff09;是现代编程语言中两个非常流行的选择。凭借各自的独特优势和广泛的应用场景&#xff0c;吸引了大量开发者的关注。本文将详细介绍Rust和Go的特点&#xff0c;并探讨它…

[Linux][Shell][Shell逻辑控制]详细讲解

目录 1.if 判断1.if-then2.if-then-else3.elif4.case5.实际上手 2.条件测试0.事前说明1.test 命令2.[]3.双括号1.(())2.[[]] 4.实际上手 3.循环1.for2.while3.until命令4.控制循环1.break2.continue 5.处理循环的输出 1.if 判断 1.if-then 语法&#xff1a;if command thenco…

大数据------JavaWeb------VueElement(完整知识点汇总)

Vue 定义 Vue是一套前端框架&#xff0c;可以免除原生JavaScript中的DOM操作&#xff0c;简化书写 之前所学的MyBatis框架是用来简化JDBC代码编写的&#xff1b;而Vue是前端框架&#xff0c;用来简化JavaScript代码编写的 在Axios与JSON综合案例的添加中有大量的DOM操作&#…

Ubuntu 22.04.4 LTS (linux) 安装 Auditd 安全审计

1 安装auditd sudo apt update sudo apt-get install auditd 2 修改配置 #sudo vim /etc/audit/auditd.conf #日志文件位置 log_file /var/log/audit/audit.log #日志文件大小(Mb) max_log_file 8 #日志文件数量 num_logs 53 启动服务 sudo systemctl restart aud…

【密码学】数字签名

一、数字签名的基本概念 数字签名是一种用于验证电子文档完整性和身份认证的密码学技术。它通过使用公钥加密体系中的私钥对文档的一部分&#xff08;通常是文档的摘要&#xff09;进行加密&#xff0c;从而创建一个“签名”。这个签名可以附在文档上&#xff0c;或作为一个单独…