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.rhkb.cn/news/375137.html

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

相关文章

在Anaconda环境中安装TensorFlow+启动jupyter notebook

1.打开cmd&#xff0c;输入C:\Users\xy>conda create -n tensorflow python3.7 这是在环境中创建了一个名为tensorflow的环境&#xff0c;具体会显示以下信息&#xff1a; C:\Users\xy>conda create -n tensorflow python3.7 Retrieving notices: ...working... done Co…

昇思25天学习打卡营第23天|K近邻算法实现红酒聚类

学AI还能赢奖品&#xff1f;每天30分钟&#xff0c;25天打通AI任督二脉 (qq.com) K近邻算法实现红酒聚类 本实验主要介绍使用MindSpore在部分wine数据集上进行KNN实验。 1、实验目的 了解KNN的基本概念&#xff1b;了解如何使用MindSpore进行KNN实验。 2、K近邻算法原理介绍…

Python酷库之旅-第三方库Pandas(018)

目录 一、用法精讲 44、pandas.crosstab函数 44-1、语法 44-2、参数 44-3、功能 44-4、返回值 44-5、说明 44-6、用法 44-6-1、数据准备 44-6-2、代码示例 44-6-3、结果输出 45、pandas.cut函数 45-1、语法 45-2、参数 45-3、功能 45-4、返回值 45-5、说明 4…

SpringBoot新手快速入门系列教程二:MySql5.7.44的免安装版本下载和配置,以及简单的Mysql生存指令指南。

我们要如何选择MySql 目前主流的Mysql有5.0、8.0、9.0 主要区别 MySQL 5.0 发布年份&#xff1a;2005年特性&#xff1a; 基础事务支持存储过程、触发器、视图基础存储引擎&#xff08;如MyISAM、InnoDB&#xff09;外键支持基本的全文搜索性能和扩展性&#xff1a; 相对较…

【python】PyQt5顶层窗口相关操作API原理剖析,企业级应用实战分享

✨✨ 欢迎大家来到景天科技苑✨✨ &#x1f388;&#x1f388; 养成好习惯&#xff0c;先赞后看哦~&#x1f388;&#x1f388; &#x1f3c6; 作者简介&#xff1a;景天科技苑 &#x1f3c6;《头衔》&#xff1a;大厂架构师&#xff0c;华为云开发者社区专家博主&#xff0c;…

【C++题解】1153 - 查找“支撑数”

问题&#xff1a;1153 - 查找“支撑数” 类型&#xff1a;数组基础 题目描述&#xff1a; 在已知一组整数中&#xff0c;有这样一种数非常怪&#xff0c;它们不在第一个&#xff0c;也不在最后一个&#xff0c;而且刚好都比左边和右边相邻的数大&#xff0c;你能找到它们吗&a…

《Windows API每日一练》9.2.1 菜单

■和菜单有关的概念 窗口的菜单栏紧挨着标题栏下面显示。这个菜单栏有时叫作程序的“主菜单”或“顶级菜单“&#xff08;top-level menu&#xff09;。顶级菜单中的菜单项通常会激活下拉菜单&#xff08;drop-downmenu&#xff09;&#xff0c;也 叫“弹出菜单”&#xff08;…

26.6 Django模型层

1. 模型层 1.1 模型层的作用 模型层(Model Layer)是MVC或MTV架构中的一个核心组成部分, 它主要负责定义和管理应用程序中的数据结构及其行为. 具体职责包括: * 1. 封装数据: 模型层封装了应用程序所需的所有数据, 这些数据以结构化的形式存在, 如数据库表, 对象等. * 2. 数据…

java中Error与Exception的区别

java中Error与Exception的区别 1、错误&#xff08;Error&#xff09;1.1 示例 2、 异常&#xff08;Exception&#xff09;2.1 示例 3、 区别总结 &#x1f496;The Begin&#x1f496;点点关注&#xff0c;收藏不迷路&#x1f496; 当我们谈论编程中的错误&#xff08;Error&…

STM32杂交版(HAL库、音乐盒、闹钟、点阵屏、温湿度)

一、设计描述 本设计精心构建了一个以STM32MP157A高性能单片机为核心控制单元的综合性嵌入式系统。该系统巧妙融合了蜂鸣器、数码管显示器、点阵屏、温湿度传感器、LED指示灯以及按键等多种外设模块&#xff0c;形成了一个功能丰富、操作便捷的杂交版智能设备。通过串口…

如何解决 PostgreSQL 中由于索引不当导致的性能下降问题?

文章目录 如何解决 PostgreSQL 中由于索引不当导致的性能下降问题一、常见的索引不当情况&#xff08;一&#xff09;缺失关键索引&#xff08;二&#xff09;过多的冗余索引&#xff08;三&#xff09;不合适的索引类型 二、如何发现索引不当的问题&#xff08;一&#xff09;…

docker-2

27.构建python应用镜像-dockerfile实践项目 1.基于官方的镜像&#xff0c;构建python代码运行环境 dockerfile 2.运行镜像&#xff0c;开启一个读写的容器空间&#xff08;定制操作&#xff0c;将代码丢进去&#xff0c;运行调试&#xff09; 3.提交这个变化的容器层数据&#…

生产英特尔CPU处理器繁忙的一天

早晨&#xff1a;准备与检查 7:00 AM - 起床与准备 工厂员工们早早起床&#xff0c;快速洗漱并享用早餐。为了在一天的工作中保持高效&#xff0c;他们会进行一些晨间锻炼&#xff0c;保持头脑清醒和身体活力。 8:00 AM - 到达工厂 员工们到达英特尔的半导体制造工厂&#…

数据库使用SSL加密连接

简介 数据库开通SSL加密连接是确保数据传输过程中安全性的关键措施&#xff0c;它通过加密数据、验证服务器身份、保护敏感信息、维护数据完整性和可靠性&#xff0c;同时满足行业标准和法规要求&#xff0c;进而提升用户体验和信任度&#xff0c;为企业的数据安全和业务连续性…

javaweb中的请求与响应--基于postman工具的应用(附带postman的详细安装步骤)

一、前言 后端的第一天感觉难度就上来了&#xff0c;可能是基础太过薄弱了吧。目前看视频已经有点跟不上了&#xff0c;果然15天想要拿下还是太勉强了点。30天还差不多。不知道读者们有没有好好的去学这方面的知识&#xff0c;没有什么是学不会的&#xff0c;关键是坚持。 Po…

Ubuntu22.04安装NIVIDIA显卡驱动总结

1.首先在安装驱动时需要判断系统有无GPU以及GPU的型号 可以参考这篇文章&#xff1a; https://blog.51cto.com/u_13171517/8814753#:~:textubuntu%20%E7%B3%BB%E7%BB%9F%20%E6%80%8E%E4%B9%88%E5%88%A4%E6%96%AD%E7%B3%BB%E7%BB%9F%E6%9C%89%E6%B2%A1%E6%9C%89GPU%201%20%E6%…

STM32实战篇:闪灯 × 流水灯 × 蜂鸣器

IO引脚初始化 即开展某项活动之前所做的准备工作&#xff0c;对于一个IO引脚来说&#xff0c;在使用它之前必须要做一些参数配置&#xff08;例如&#xff1a;选择工作模式、速率&#xff09;的工作&#xff08;即IO引脚的初始化&#xff09;。 IO引脚初始化流程 1、使能IO引…

乐观锁原理

乐观锁是一种并发控制的方法&#xff0c;主要用于多线程环境下&#xff0c;用于保证数据的一致性。其核心思想是&#xff1a;"在多个事务中乐观地读取数据&#xff0c;在提交时再验证是否有冲突&#xff0c;如果没有&#xff0c;则提交&#xff1b;如果有&#xff0c;则回…

每天五分钟深度学习:向量化技术在神经网络中的应用

本文重点 向量化技术,简而言之,就是利用矩阵运算(而非传统的for循环)来执行大规模的计算任务。这种技术依赖于单指令多数据(SIMD)架构,允许一个指令同时对多个数据元素执行相同的操作。例如,在向量化加法中,不再需要逐个元素进行加法操作,而是可以一次性对整个向量执…

Android使用AndServer在安卓设备上搭建服务端(Java)(Kotlin)两种写法

一直都是通过OkHttp远程服务端进行数据交互&#xff0c;突发奇想能不能也通过OkHttp在局域网的情况下对两个安卓设备或者手机进行数据交互呢&#xff1f; 这样一方安卓设备要当做服务端与另一个安卓设备通过OkHttp进行数据交互即可 当然还可以通过 socket 和 ServerSocket 通…