(简易版)
目录
一、建库建表
Table student
用于记录学生的基本信息
Table stu_classes
用于记录学生的选课信息
Table stuscore
用于记录学生的成绩
Table teacher_course
用于记录老师的信息
下面是该库的sql文件:
SET FOREIGN_KEY_CHECKS=0;
DROP TABLE IF EXISTS `student`;
CREATE TABLE `student` (
`stunum` int(11) NOT NULL,
`name` varchar(225) DEFAULT NULL,
`age` int(11) DEFAULT NULL,
`email` varchar(225) DEFAULT NULL,
`username` varchar(225) NOT NULL,
`password` varchar(225) NOT NULL,
PRIMARY KEY (`stunum`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `student` VALUES ('1', 'wht', '19', '120@qq.com', 'wht', '123');
INSERT INTO `student` VALUES ('2', '张三', '18', '121@qq.com', 'zhangsan', '123123');
INSERT INTO `student` VALUES ('3', '李四', '18', '122.@qq.com', 'lisi', '111');
INSERT INTO `student` VALUES ('4', '王五', '19', '123@qq.com', 'wangwu', 'ww123');
INSERT INTO `student` VALUES ('5', 'testStu1', '19', '124@qq.com', '111', '111');
INSERT INTO `student` VALUES ('6', 'testStu2', '20', '125@qq.com', '123', '123');
INSERT INTO `student` VALUES ('20190428', '吴昊天', '19', '1207052431@qq.com', 'wht666', 'wht0428');
DROP TABLE IF EXISTS `stuscore`;
CREATE TABLE `stuscore` (
`stunum` int(11) NOT NULL DEFAULT '0',
`mathscore` int(11) DEFAULT NULL,
`computerscore` int(11) DEFAULT NULL,
`Englishscore` int(11) DEFAULT NULL,
`selfcourseA` int(11) DEFAULT NULL,
`selfcourseB` int(11) DEFAULT NULL,
PRIMARY KEY (`stunum`),
CONSTRAINT `stunum` FOREIGN KEY (`stunum`) REFERENCES `student` (`stunum`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `stuscore` VALUES ('1', '100', '100', '100', '0', '0');
INSERT INTO `stuscore` VALUES ('2', '94', '93', '92', '0', '0');
INSERT INTO `stuscore` VALUES ('3', '89', '88', '87', '0', '0');
INSERT INTO `stuscore` VALUES ('4', '100', '83', '82', '0', '0');
INSERT INTO `stuscore` VALUES ('5', '68', '75', '82', '0', '0');
INSERT INTO `stuscore` VALUES ('6', '61', '78', '78', '0', '0');
INSERT INTO `stuscore` VALUES ('20190428', null, null, null, '97', '0');
DROP TABLE IF EXISTS `stu_classes`;
CREATE TABLE `stu_classes` (
`stunum` int(11) NOT NULL DEFAULT '0',
`mathclass` varchar(255) DEFAULT NULL,
`computerclass` varchar(255) DEFAULT NULL,
`Englishclass` varchar(255) DEFAULT NULL,
`classA` varchar(255) DEFAULT NULL,
`classB` varchar(255) DEFAULT NULL,
PRIMARY KEY (`stunum`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `stu_classes` VALUES ('1', '00132', '00134', '00145', '00155', '00187');
INSERT INTO `stu_classes` VALUES ('2', '00132', '00134', '00145', '00166', '00155');
INSERT INTO `stu_classes` VALUES ('3', '00132', '00134', '00145', '00155', '00187');
INSERT INTO `stu_classes` VALUES ('4', '00132', '00134', '00145', '00157', '00155');
INSERT INTO `stu_classes` VALUES ('5', '00132', '00134', '00145', '', '');
INSERT INTO `stu_classes` VALUES ('6', '00132', '00134', '00145', '', '');
INSERT INTO `stu_classes` VALUES ('20190428', '00132', '00134', '00155', '00166', '00155');
DROP TABLE IF EXISTS `teacher_course`;
CREATE TABLE `teacher_course` (
`tchnum` int(11) NOT NULL DEFAULT '0',
`tchpsw` varchar(255) NOT NULL,
`teacher` varchar(255) NOT NULL DEFAULT '',
`course` varchar(255) NOT NULL,
`classcode` varchar(255) NOT NULL,
PRIMARY KEY (`tchnum`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `teacher_course` VALUES ('110', 'wang', '王**', 'math', '00132');
INSERT INTO `teacher_course` VALUES ('120', 'li', '李**', 'computer', '00134');
INSERT INTO `teacher_course` VALUES ('130', 'jin', '金**', 'English', '00145');
INSERT INTO `teacher_course` VALUES ('140', 'wu', '吴**', 'physics', '00166');
INSERT INTO `teacher_course` VALUES ('150', 'huang', '黄**', 'chinese', '00157');
INSERT INTO `teacher_course` VALUES ('160', 'zhang', '张**', 'health', '00155');
INSERT INTO `teacher_course` VALUES ('170', 'yang', '杨**', 'filmapp', '00187');
二、项目结构
Package dao
存放对数据库操作的接口以及mapper映射文件
Package model
存放实体类以及模型类
Package utils
存放自定义工具类——用于返回Sqlsession类型
Package viewAndcontroller
存放所有的fxml类型界面文件、css样式文件、图片以及控制器类
Class Main
主类
Package java.resources
存放数据库属性配置文件、所有的界面FXML文件、css样式文件以及图片,便于Maven在compile时将这些文件编译到target的classes目录下。
需要手动将image目录拷贝到target目录下
pom.xml
在该文件中加入mybatis、mysql驱动等依赖jar包
Directory META-INF
JavaFx Application 构件的属性
用于将本项目打包成exe可运行文件。
三、项目测试
登录界面
注册界面
登录功能
登录学生界面
登录老师界面
注册功能测试
当输入不合理或者输入已注册过的学号或用户名时,给出错误提示窗口
学生选课功能测试
学生的成绩面板课程发生变化
选课必须为两门
老师修改成绩功能测试
学生的成绩面板已成功改变
当输入小于0或者大于100时给出提示窗口
四、项目的打包
打包可执行jar包
由于本项目采用Maven管理,因此很容易进行打包。
在idea的右侧打开Maven菜单点击Package操作即可打包可执行jar包到target目录下。
但是此情况打包的jar包是不包含项目所依赖包的,于是需要导入以下插件,将依赖包一同打包。
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.allen.capturewebdata.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
点击右侧Maven菜单中插件中的: assembly:assembly,即可在target目录下生成一个"**-jar-with-dependencies.jar"的jar包
转化成可执行的exe文件
–>文件打开项目结构–>点击构件
添加一个JavaFx Application构件
点击Create Manifest… 生成META-INF目录
接下来添加主类
然后右击右侧依赖包选择置于 Output Root
点击应用、确定
最后选择构建->编译 Artifacts…->Rebuild
成功在项目的out目录下生成了构件目录
以下为可执行的exe文件(图标可以根据需要更改)
五、附上具体代码
Main
package cn.zjnu.address;
import cn.zjnu.address.dao.Stu_ClassesDao;
import cn.zjnu.address.dao.StudentDao;
import cn.zjnu.address.dao.StuscoreDao;
import cn.zjnu.address.dao.Teacher_CourseDao;
import cn.zjnu.address.model.*;
import cn.zjnu.address.utils.MyBatisUtils;
import cn.zjnu.address.viewAndcontroller.*;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.control.TabPane;
import javafx.scene.image.Image;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import org.apache.ibatis.session.SqlSession;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Main extends Application {
private Stage primaryStage;
private BorderPane rootLayout;
private String username;
private Integer tchnum=0;
private ObservableList<ClassStuInfo> studentData = FXCollections.observableArrayList();
public List<ClassStuInfo> getStudentData(Integer tchnum){
String course;
String classcode;
Integer score = 0;
List<Integer> idlist = new ArrayList<>();
List<ClassStuInfo> listInfo = new ArrayList<>();
Map<Integer,String> map = new HashMap<>();
SqlSession sqlSession = MyBatisUtils.getSqlSession();
Teacher_CourseDao dao = sqlSession.getMapper(Teacher_CourseDao.class);
Teacher_Course teacher_course = new Teacher_Course();
teacher_course = dao.selectBytchnum(tchnum);
if(teacher_course != null){
course = teacher_course.getCourse();
classcode = teacher_course.getClasscode();
Stu_ClassesDao dao1 = sqlSession.getMapper(Stu_ClassesDao.class);
List<Stu_Classes> stu_classes = dao1.selectByclasscode(classcode);
for(Stu_Classes stu:stu_classes){
idlist.add(stu.getStunum());
if(stu.getClassA().equals(classcode)){
map.put(stu.getStunum(),"selfcourseA");
}else if(stu.getClassB().equals(classcode)){
map.put(stu.getStunum(),"selfcourseB");
}else if(stu.getMathclass().equals(classcode)){
map.put(stu.getStunum(),"mathscore");
}else if(stu.getComputerclass().equals(classcode)){
map.put(stu.getStunum(),"computerscore");
}else if(stu.getEnglishclass().equals(classcode)){
map.put(stu.getStunum(),"Englishscore");
}
}
StudentDao dao2 = sqlSession.getMapper(StudentDao.class);
List<StuInfo> stuInfos = dao2.selectById(idlist);
StuscoreDao dao3 = sqlSession.getMapper(StuscoreDao.class);
for(StuInfo stuInfo:stuInfos){
score = 0;
Stuscore stuscore = dao3.selectScore(stuInfo.getStunum());
String temp = map.get(stuInfo.getStunum());
System.out.println(temp);
if("mathscore".equals(temp)){
score = stuscore.getMathscore();
} else if("computerscore".equals(temp)){
score = stuscore.getComputerscore();
} else if("Englishscore".equals(temp)){
score = stuscore.getEnglishscore();
} else if("selfcourseA".equals(temp)){
score = stuscore.getSelfcourseA();
} else if("selfcourseB".equals(temp)){
score = stuscore.getSelfcourseB();
}
course = teacher_course.getCourse();
if("physics".equals(course)){
course = "大学物理";
} else if ("chinese".equals(course)){
course = "汉语词汇与文化";
} else if ("health".equals(course)){
course = "大学生卫生保健";
} else if ("filmapp".equals(course)){
course = "影视鉴赏";
}
if(score != null && course != null){
listInfo.add(new ClassStuInfo(stuInfo.getStunum(),stuInfo.getName(),score,stuInfo.getEmail(),course,classcode));
} else if(score ==null && course != null){
listInfo.add(new ClassStuInfo(stuInfo.getStunum(),stuInfo.getName(),0,stuInfo.getEmail(),course,classcode));
} else if(course == null && score != null){
listInfo.add(new ClassStuInfo(stuInfo.getStunum(),stuInfo.getName(),0,stuInfo.getEmail(),"null",classcode));
}
}
sqlSession.close();
System.out.println(listInfo);
}
return listInfo;
}
public void setStudentData(List<ClassStuInfo> list){
for(int i = 0; i < list.size(); i++){
this.studentData.add(list.get(i));
}
}
public ObservableList<ClassStuInfo> getStudentData() {
return studentData;
}
public String getUsername() {
return username;
}
@Override
public void start(Stage primaryStage) throws Exception {
this.primaryStage = primaryStage;
this.primaryStage.setTitle("StuInfoSystem");
this.primaryStage.getIcons().add(new Image("images/picture.png"));
initRootLayout();
showLoginView();
}
public void showLoginView() {
try {
// Load person overview.
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("/LogView.fxml"));
GridPane LoginView = (GridPane) loader.load();
rootLayout.setCenter(LoginView);
LoginViewController controller = loader.getController();
controller.setMain(this);
} catch (IOException e) {
e.printStackTrace();
}
}
public void initRootLayout() {
try {
// Load root layout from fxml file.
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("/Root.fxml"));
rootLayout = (BorderPane) loader.load();
// Show the scene containing the root layout.
Scene scene = new Scene(rootLayout);
primaryStage.setScene(scene);
primaryStage.setResizable(false);
primaryStage.show();
} catch (IOException e) {
e.printStackTrace();
}
}
public boolean showUserRegister(){
try {
// Load the fxml file and create a new stage for the popup dialog.
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("/UserRegisterView.fxml"));
GridPane page = (GridPane) loader.load();
// Create the dialog Stage.
Stage dialogStage = new Stage();
dialogStage.setTitle("Register");
dialogStage.initModality(Modality.WINDOW_MODAL);
dialogStage.initOwner(primaryStage);
Scene scene = new Scene(page);
dialogStage.setScene(scene);
UserRegisterViewController controller = loader.getController();
controller.setDialogStage(dialogStage);
dialogStage.showAndWait();
return controller.isOkClicked();
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
public void showStudentView(String username){
try {
this.username = username;
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("/StudentView.fxml"));
TabPane tabPane = (TabPane)loader.load();
this.primaryStage.close();
Stage dialogStage = new Stage();
dialogStage.getIcons().add(new Image("images/picture.png"));
dialogStage.initStyle(StageStyle.UNIFIED);
dialogStage.setTitle("学生界面");
dialogStage.initModality(Modality.WINDOW_MODAL);
dialogStage.initOwner(primaryStage);
Scene scene = new Scene(tabPane);
dialogStage.setScene(scene);
StudentViewController controller = loader.getController();
controller.setMain(this);
controller.setDialogStage(dialogStage);
controller.setInfoText(username);
controller.setCourse(username);
controller.setScore(Integer.parseInt(controller.getStunumview().getText()));
controller.chooseCourse();
dialogStage.showAndWait();
} catch (IOException e) {
e.printStackTrace();
}
}
public void showTeacherView(Integer tchnum){
try {
this.tchnum = tchnum;
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("/TeacherView.fxml"));
AnchorPane stuOverview = (AnchorPane) loader.load();
this.primaryStage.close();
Stage dialogStage = new Stage();
dialogStage.getIcons().add(new Image("images/picture.png"));
dialogStage.setTitle("Info");
dialogStage.initModality(Modality.WINDOW_MODAL);
dialogStage.initOwner(primaryStage);
Scene scene = new Scene(stuOverview);
dialogStage.setScene(scene);
TeacherViewController controller = loader.getController();
controller.setMain(this);
controller.setDialogStage(dialogStage);
dialogStage.showAndWait();
} catch (IOException e) {
e.printStackTrace();
}
}
public Integer showEditStuScoreView(Integer stunum, String course){
try {
Integer stunumber = stunum;
String coursename = course;
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("/EditStuscoreView.fxml"));
AnchorPane editview = (AnchorPane) loader.load();
Stage dialogStage = new Stage();
dialogStage.setTitle("Register");
dialogStage.initModality(Modality.WINDOW_MODAL);
dialogStage.initOwner(primaryStage);
Scene scene = new Scene(editview);
dialogStage.setScene(scene);
EditStuscoreViewController controller = loader.getController();
controller.setDialogStage(dialogStage);
controller.setStunum(stunum);
controller.setCourse(course);
dialogStage.showAndWait();
return controller.getScore();
} catch (IOException e) {
e.printStackTrace();
return 0;
}
}
public static void main(String[] args) {
launch(args);
}
}
Package model
ClassStuInfo
package cn.zjnu.address.model;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
public class ClassStuInfo {
private IntegerProperty stunumber;
private StringProperty stuname;
private IntegerProperty score;
private StringProperty email;
private StringProperty course;
private StringProperty classcode;
public ClassStuInfo(){
}
public ClassStuInfo(Integer stunumber, String stuname, Integer score, String email, String course) {
this.stunumber = new SimpleIntegerProperty(stunumber);
this.stuname = new SimpleStringProperty(stuname);
this.score = new SimpleIntegerProperty(score);
this.email = new SimpleStringProperty(email);
this.course = new SimpleStringProperty(course);
}
public ClassStuInfo(Integer stunumber, String stuname, Integer score, String email, String course, String classcode) {
this.stunumber = new SimpleIntegerProperty(stunumber);
this.stuname = new SimpleStringProperty(stuname);
this.score = new SimpleIntegerProperty(score);
this.email = new SimpleStringProperty(email);
this.course = new SimpleStringProperty(course);
this.classcode = new SimpleStringProperty(classcode);
}
public int getStunumber() {
return stunumber.get();
}
public IntegerProperty stunumberProperty() {
return stunumber;
}
public void setStunumber(int stunumber) {
this.stunumber.set(stunumber);
}
public String getStuname() {
return stuname.get();
}
public StringProperty stunameProperty() {
return stuname;
}
public void setStuname(String stuname) {
this.stuname.set(stuname);
}
public int getScore() {
return score.get();
}
public IntegerProperty scoreProperty() {
return score;
}
public void setScore(int score) {
this.score.set(score);
}
public String getEmail() {
return email.get();
}
public StringProperty emailProperty() {
return email;
}
public void setEmail(String email) {
this.email.set(email);
}
public String getCourse() {
return course.get();
}
public StringProperty courseProperty() {
return course;
}
public void setCourse(String course) {
this.course.set(course);
}
public String getClasscode() {
return classcode.get();
}
public StringProperty classcodeProperty() {
return classcode;
}
public void setClasscode(String classcode) {
this.classcode.set(classcode);
}
@Override
public String toString() {
return "ClassStuInfo{" +
"stunumber=" + stunumber +
", stuname=" + stuname +
", score=" + score +
", email=" + email +
", course=" + course +
", classcode=" + classcode +
'}';
}
}
course
package cn.zjnu.address.model;
public class course {
private String course;
public String getCourse() {
return course;
}
public void setCourse(String course) {
this.course = course;
}
}
Stu_Classes
package cn.zjnu.address.model;
public class Stu_Classes {
private Integer stunum;
private String mathclass;
private String computerclass;
private String Englishclass;
private String classA;
private String classB;
public Integer getStunum() {
return stunum;
}
public void setStunum(Integer stunum) {
this.stunum = stunum;
}
public String getMathclass() {
return mathclass;
}
public void setMathclass(String mathclass) {
this.mathclass = mathclass;
}
public String getComputerclass() {
return computerclass;
}
public void setComputerclass(String computerclass) {
this.computerclass = computerclass;
}
public String getEnglishclass() {
return Englishclass;
}
public void setEnglishclass(String englishclass) {
Englishclass = englishclass;
}
public String getClassA() {
return classA;
}
public void setClassA(String classA) {
this.classA = classA;
}
public String getClassB() {
return classB;
}
public void setClassB(String classB) {
this.classB = classB;
}
@Override
public String toString() {
return "Stu_Classes{" +
"stunum=" + stunum +
", mathclass='" + mathclass + '\'' +
", computerclass='" + computerclass + '\'' +
", Englishclass='" + Englishclass + '\'' +
", classA='" + classA + '\'' +
", classB='" + classB + '\'' +
'}';
}
}
Student
package cn.zjnu.address.model;
public class Student {
private Integer stunum;
private String name;
private Integer age;
private String email;
private String username;
private String password;
public Integer getStunum() {
return stunum;
}
public void setStunum(Integer stunum) {
this.stunum = stunum;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
@Override
public String toString() {
return "Student{" +
"stunum=" + stunum +
", name='" + name + '\'' +
", age=" + age +
", email='" + email + '\'' +
", username='" + username + '\'' +
", password='" + password + '\'' +
'}';
}
}
StuInfo
package cn.zjnu.address.model;
public class StuInfo {
private Integer stunum;
private String name;
private String email;
private String username;
public Integer getStunum() {
return stunum;
}
public void setStunum(Integer stunum) {
this.stunum = stunum;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
@Override
public String toString() {
return "StuInfo{" +
"stunum=" + stunum +
", name='" + name + '\'' +
", email='" + email + '\'' +
", username='" + username + '\'' +
'}';
}
}
Stuscore
package cn.zjnu.address.model;
public class Stuscore {
private Integer stunum;
private Integer mathscore;
private Integer computerscore;
private Integer Englishscore;
private Integer selfcourseA;
private Integer selfcourseB;
public Integer getStunum() {
return stunum;
}
public void setStunum(Integer stunum) {
this.stunum = stunum;
}
public Integer getMathscore() {
return mathscore;
}
public void setMathscore(Integer mathscore) {
this.mathscore = mathscore;
}
public Integer getComputerscore() {
return computerscore;
}
public void setComputerscore(Integer computerscore) {
this.computerscore = computerscore;
}
public Integer getEnglishscore() {
return Englishscore;
}
public void setEnglishscore(Integer englishscore) {
Englishscore = englishscore;
}
public Integer getSelfcourseA() {
return selfcourseA;
}
public void setSelfcourseA(Integer selfcourseA) {
this.selfcourseA = selfcourseA;
}
public Integer getSelfcourseB() {
return selfcourseB;
}
public void setSelfcourseB(Integer selfcourseB) {
this.selfcourseB = selfcourseB;
}
@Override
public String toString() {
return "Stuscore{" +
"stunum=" + stunum +
", mathscore=" + mathscore +
", computerscore=" + computerscore +
", Englishscore=" + Englishscore +
", selfcourseA=" + selfcourseA +
", selfcourseB=" + selfcourseB +
'}';
}
}
Teacher_Course
package cn.zjnu.address.model;
public class Teacher_Course {
private Integer tchnum;
private String tchpsw;
private String teacher;
private String course;
private String classcode;
public Integer getTchnum() {
return tchnum;
}
public void setTchnum(Integer tchnum) {
this.tchnum = tchnum;
}
public String getTchpsw() {
return tchpsw;
}
public void setTchpsw(String tchpsw) {
this.tchpsw = tchpsw;
}
public String getTeacher() {
return teacher;
}
public void setTeacher(String teacher) {
this.teacher = teacher;
}
public String getCourse() {
return course;
}
public void setCourse(String course) {
this.course = course;
}
public String getClasscode() {
return classcode;
}
public void setClasscode(String classcode) {
this.classcode = classcode;
}
@Override
public String toString() {
return "Teacher_Course{" +
"tchnum=" + tchnum +
", tchpsw='" + tchpsw + '\'' +
", teacher='" + teacher + '\'' +
", course='" + course + '\'' +
", classcode='" + classcode + '\'' +
'}';
}
}
Package dao
interface courseDao
package cn.zjnu.address.dao;
import cn.zjnu.address.model.course;
public interface courseDao {
course selectcourseA(String username);
course selectcourseB(String username);
}
courseDao.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.zjnu.address.dao.courseDao">
<select id="selectcourseA" resultType="cn.zjnu.address.model.course">
select t.course from teacher_course t
join stu_classes s
on s.classA = t.classcode
where s.stunum=(select stunum from student where username=#{username})
</select>
<select id="selectcourseB" resultType="cn.zjnu.address.model.course">
select t.course from teacher_course t
join stu_classes s
on s.classB = t.classcode
where s.stunum=(select stunum from student where username=#{username})
</select>
</mapper>
interface Stu_ClassesDao
package cn.zjnu.address.dao;
import cn.zjnu.address.model.Stu_Classes;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface Stu_ClassesDao {
int registerInsert(Stu_Classes stu);
int updateCourseA(@Param("stunum")Integer stunum,@Param("classcode") String classcode);
int updateCourseB(@Param("stunum")Integer stunum,@Param("classcode") String classcode);
List<Stu_Classes> selectByclasscode(String classcode);
Stu_Classes selectByclasscode2(@Param("stunum") Integer stunum,@Param("classcode") String classcode);
}
Stu_ClassesDao.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.zjnu.address.dao.Stu_ClassesDao">
<insert id="registerInsert">
insert into stu_classes values(#{stunum},#{mathclass},#{computerclass},#{Englishclass},#{classA},#{classB})
</insert>
<update id="updateCourseA">
update stu_classes set classA=#{classcode} where stunum=#{stunum}
</update>
<update id="updateCourseB">
update stu_classes set classB=#{classcode} where stunum=#{stunum}
</update>
<select id="selectByclasscode" resultType="cn.zjnu.address.model.Stu_Classes">
select * from stu_classes where mathclass=#{classcode} or computerclass=#{classcode}
or Englishclass=#{classcode} or classA=#{classcode} or classB=#{classcode}
</select>
<select id="selectByclasscode2" resultType="cn.zjnu.address.model.Stu_Classes">
select * from stu_classes where (mathclass=#{classcode} or computerclass=#{classcode}
or Englishclass=#{classcode} or classA=#{classcode} or classB=#{classcode}) and stunum=#{stunum}
</select>
</mapper>
interface StudentDao
package cn.zjnu.address.dao;
import cn.zjnu.address.model.StuInfo;
import cn.zjnu.address.model.Student;
import cn.zjnu.address.model.Stuscore;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface StudentDao {
List<Student> selectAll();
Student Loginselect(@Param("username") String username, @Param("password")String password);
Student Registerselectstunum(@Param("stunum") Integer stunum);
Student Registerselectusername(@Param("username") String username);
int UserRegister(Student student);
StuInfo selectInfo(String username);
List<StuInfo> selectById(List<Integer> idlist);
}
StudentDao.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.zjnu.address.dao.StudentDao">
<select id="selectAll" resultType="cn.zjnu.address.model.Student">
select * from student
</select>
<select id="Loginselect" resultType="cn.zjnu.address.model.Student">
select username, password from student where username=#{username} and password=#{password}
</select>
<select id="Registerselectstunum" resultType="cn.zjnu.address.model.Student">
select * from student where stunum=#{stunum}
</select>
<select id="Registerselectusername" resultType="cn.zjnu.address.model.Student">
select * from student where username=#{username}
</select>
<select id="selectInfo" resultType="cn.zjnu.address.model.StuInfo">
select stunum,name,email,username from student where username=#{username}
</select>
<insert id="UserRegister">
insert into student values(#{stunum},#{name},#{age},#{email},#{username},#{password})
</insert>
<select id="selectById" resultType="cn.zjnu.address.model.StuInfo">
select * from student where stunum in
<foreach collection="list" item="stunum" open="(" close=")" separator=",">
#{stunum}
</foreach>
</select>
</mapper>
interface StuscoreDao
package cn.zjnu.address.dao;
import cn.zjnu.address.model.Stuscore;
import org.apache.ibatis.annotations.Param;
public interface StuscoreDao {
int insertStuscore(Stuscore stuscore);
Stuscore selectScore(Integer stunum);
int chooseUpdate(@Param("stunum") Integer stunum);
int updateScore(@Param("stunum") Integer stunum, @Param("course") String course, @Param("score") Integer score);
}
StuscoreDao.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.zjnu.address.dao.StuscoreDao">
<insert id="insertStuscore">
insert into stuscore values(#{stunum},#{mathscore},#{computerscore},#{Englishscore},#{selfcourseA},#{selfcourseB})
</insert>
<select id="selectScore" resultType="cn.zjnu.address.model.Stuscore">
select * from stuscore where stunum=#{stunum}
</select>
<update id="chooseUpdate">
update stuscore set selfcourseA=0, selfcourseB=0 where stunum=#{stunum}
</update>
<update id="updateScore">
update stuscore set ${course}=#{score} where stunum=#{stunum}
</update>
</mapper>
interface Teacher_CourseDao
package cn.zjnu.address.dao;
import cn.zjnu.address.model.Teacher_Course;
import org.apache.ibatis.annotations.Param;
public interface Teacher_CourseDao {
Teacher_Course loginselect(@Param("tchnum") Integer tchnum, @Param("tchpsw")String tchpsw);
Teacher_Course selectCourse(String course);
Teacher_Course selectBytchnum(Integer tchnum);
}
Teacher_CourseDao.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.zjnu.address.dao.Teacher_CourseDao">
<select id="loginselect" resultType="cn.zjnu.address.model.Teacher_Course">
select tchnum, tchpsw from teacher_course where tchnum=#{tchnum} and tchpsw=#{tchpsw}
</select>
<select id="selectCourse" resultType="cn.zjnu.address.model.Teacher_Course">
select * from teacher_course where course=#{course}
</select>
<select id="selectBytchnum" resultType="cn.zjnu.address.model.Teacher_Course">
select * from teacher_course where tchnum=#{tchnum}
</select>
</mapper>
Package utils
MyBatisUtils
package cn.zjnu.address.utils;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import java.io.IOException;
import java.io.InputStream;
public class MyBatisUtils {
private static SqlSessionFactory factory = null;
static {
String config = "mybatis.xml";
try {
InputStream in = Resources.getResourceAsStream(config);
factory = new SqlSessionFactoryBuilder().build(in);
} catch (IOException e) {
e.printStackTrace();
}
}
public static SqlSession getSqlSession(){
SqlSession sqlSession = null;
if(factory != null){
sqlSession= factory.openSession();
}
return sqlSession;
}
}
Package viewAndcontroller
LoginViewController
package cn.zjnu.address.viewAndcontroller;
import cn.zjnu.address.Main;
import cn.zjnu.address.dao.StudentDao;
import cn.zjnu.address.dao.Teacher_CourseDao;
import cn.zjnu.address.model.ClassStuInfo;
import cn.zjnu.address.model.Student;
import cn.zjnu.address.model.Teacher_Course;
import cn.zjnu.address.utils.MyBatisUtils;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.text.Text;
import org.apache.ibatis.session.SqlSession;
import java.util.List;
public class LoginViewController {
@FXML
private GridPane grid;
@FXML
private Label welcome;
@FXML
private Label usename;
@FXML
private Label passwsd;
@FXML
private TextField userTextField;
@FXML
private TextField pwdTextField;
@FXML
private Button btn;
@FXML
private Button btn2;
@FXML
private HBox hbBtn;
@FXML
private Text actiontarget;
@FXML
private CheckBox loginchoose;
private Main main;
@FXML
public void handleLogin() {
if(!loginchoose.isSelected()){
String username = userTextField.getText();
String password = pwdTextField.getText();
SqlSession sqlSession = MyBatisUtils.getSqlSession();
StudentDao dao = sqlSession.getMapper(StudentDao.class);
Student student = new Student();
student = dao.Loginselect(username, password);
sqlSession.close();
if (student != null) {
actiontarget.setText("登陆成功!");
main.showStudentView(username);
} else {
actiontarget.setText("登陆失败!");
}
}else {
Integer tchnum = Integer.parseInt(userTextField.getText());
String tchpsw = pwdTextField.getText();
SqlSession sqlSession = MyBatisUtils.getSqlSession();
Teacher_CourseDao dao = sqlSession.getMapper(Teacher_CourseDao.class);
Teacher_Course teacher_course = dao.loginselect(tchnum,tchpsw);
sqlSession.close();
if(teacher_course != null){
actiontarget.setText("登陆成功!");
List<ClassStuInfo> list = main.getStudentData(tchnum);
main.setStudentData(list);
main.showTeacherView(tchnum);
} else {
actiontarget.setText("登陆失败!");
}
}
}
@FXML
public void handleRegister() {
boolean okClicked = main.showUserRegister();
}
public void setMain(Main main){
this.main = main;
}
}
StudentViewController
package cn.zjnu.address.viewAndcontroller;
import cn.zjnu.address.Main;
import cn.zjnu.address.dao.*;
import cn.zjnu.address.model.*;
import cn.zjnu.address.utils.MyBatisUtils;
import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Label;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import org.apache.ibatis.session.SqlSession;
import java.util.ArrayList;
import java.util.List;
public class StudentViewController {
@FXML
private Text stunumview;
@FXML
private Text nameview;
@FXML
private Text emailview;
@FXML
private Text username;
@FXML
private Text mathscore;
@FXML
private Text computerscore;
@FXML
private Text Englishscore;
@FXML
private Text selfcourseA;
@FXML
private Text selfcourseB;
@FXML
private CheckBox physics;
@FXML
private CheckBox chinese;
@FXML
private CheckBox health;
@FXML
private CheckBox filmapp;
@FXML
private Button okchoose;
@FXML
private Label courseA;
@FXML
private Label courseB;
private Stage dialogStage;
private Main main;
public Text getStunumview() {
return stunumview;
}
private Integer choosecount = 0;
public void setMain(Main main){
this.main = main;
}
public void setCourseA(String courseA) {
this.courseA.setText(courseA);
}
public void setCourseB(String courseB) {
this.courseB.setText(courseB);
}
public void setStunumview(Text stunumview) {
this.stunumview = stunumview;
}
public void setDialogStage(Stage dialogStage){
this.dialogStage = dialogStage;
}
public void setInfoText(String user){
SqlSession sqlSession = MyBatisUtils.getSqlSession();
StudentDao dao = sqlSession.getMapper(StudentDao.class);
StuInfo stuInfo = new StuInfo();
stuInfo = dao.selectInfo(user);
stunumview.setText(Integer.toString(stuInfo.getStunum()));
username.setText(stuInfo.getUsername());
nameview.setText(stuInfo.getName());
emailview.setText(stuInfo.getEmail());
sqlSession.close();
}
public void setScore(Integer stunum){
SqlSession sqlSession = MyBatisUtils.getSqlSession();
StuscoreDao dao = sqlSession.getMapper(StuscoreDao.class);
Stuscore stuscore = new Stuscore();
stuscore = dao.selectScore(stunum);
sqlSession.close();
if(stuscore.getMathscore() != null){
mathscore.setText(Integer.toString(stuscore.getMathscore()));
}else{
mathscore.setText("NULL");
}
if(stuscore.getComputerscore() != null){
computerscore.setText(Integer.toString(stuscore.getComputerscore()));
}else{
computerscore.setText("NULL");
}
if(stuscore.getEnglishscore() != null){
Englishscore.setText(Integer.toString(stuscore.getEnglishscore()));
}else{
Englishscore.setText("NULL");
}
if(stuscore.getSelfcourseA() != null){
selfcourseA.setText(Integer.toString(stuscore.getSelfcourseA()));
}else{
selfcourseA.setText("NULL");
}
if(stuscore.getSelfcourseB() != null){
selfcourseB.setText(Integer.toString(stuscore.getSelfcourseB()));
}else{
selfcourseB.setText("NULL");
}
}
public String getClasscode(){
return null;
}
public void setCourse(String username){
SqlSession sqlSession = MyBatisUtils.getSqlSession();
courseDao dao = sqlSession.getMapper(courseDao.class);
course cA = dao.selectcourseA(username);
course cB = dao.selectcourseB(username);
String courseA = "";
String courseB = "";
if(cA != null){
courseA = cA.getCourse();
}else{
courseA = "null";
}
if(cB != null){
courseB = cB.getCourse();
}else{
courseB = "null";
}
this.setCourseA(this.changetochinese(courseA));
this.setCourseB(this.changetochinese(courseB));
}
private String changetochinese(String course){
if("physics".equals(course)){
course = "大学物理";
} else if ("chinese".equals(course)){
course = "汉语词汇与文化";
} else if ("health".equals(course)){
course = "大学生卫生保健";
} else if ("filmapp".equals(course)){
course = "影视鉴赏";
}
return course;
}
@FXML
public void chooseCourse() {
this.choosecount = 0;
List<String> list = new ArrayList<>();
List<String> list1 = new ArrayList<>();
if (this.physics.isSelected()) {
this.choosecount++;
list.add("physics");
list1.add("大学物理");
}
if (this.chinese.isSelected()) {
this.choosecount++;
list.add("chinese");
list1.add("汉语词汇与文化");
}
if (this.health.isSelected()) {
this.choosecount++;
list.add("health");
list1.add("大学生卫生保健");
}
if (this.filmapp.isSelected()) {
this.choosecount++;
list.add("filmapp");
list1.add("影视鉴赏");
}
if (this.choosecount > 2) {
Alert alert = new Alert(Alert.AlertType.WARNING);
alert.setTitle("spill over");
alert.setHeaderText("Look, a Warning Dialog");
alert.setContentText("you can only choose two courses!");
alert.showAndWait();
} else if (choosecount == 2) {
okchoose.setText("选课成功!");
this.setCourseA(list1.get(0));
this.setCourseB(list1.get(1));
SqlSession sqlSession = MyBatisUtils.getSqlSession();
Teacher_CourseDao dao = sqlSession.getMapper(Teacher_CourseDao.class);
Teacher_Course temp = new Teacher_Course();
Teacher_Course temp1 = new Teacher_Course();
temp = dao.selectCourse(list.get(0));
temp1 = dao.selectCourse(list.get(1));
StudentDao dao1 = sqlSession.getMapper(StudentDao.class);
StuInfo stu = new StuInfo();
stu = dao1.selectInfo(main.getUsername());
Stu_ClassesDao dao2 = sqlSession.getMapper(Stu_ClassesDao.class);
int num = dao2.updateCourseA(stu.getStunum(),temp.getClasscode());
int num1 = dao2.updateCourseB(stu.getStunum(),temp1.getClasscode());
StuscoreDao dao3 = sqlSession.getMapper(StuscoreDao.class);
int num2 = dao3.chooseUpdate(stu.getStunum());
sqlSession.commit();
sqlSession.close();
}
}
}
UserRegisterViewController
package cn.zjnu.address.viewAndcontroller;
import cn.zjnu.address.dao.Stu_ClassesDao;
import cn.zjnu.address.dao.StudentDao;
import cn.zjnu.address.dao.StuscoreDao;
import cn.zjnu.address.model.Stu_Classes;
import cn.zjnu.address.model.Student;
import cn.zjnu.address.model.Stuscore;
import cn.zjnu.address.utils.MyBatisUtils;
import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.TextField;
import javafx.stage.Stage;
import org.apache.ibatis.session.SqlSession;
public class UserRegisterViewController {
@FXML
private TextField stunumField;
@FXML
private TextField nameField;
@FXML
private TextField ageField;
@FXML
private TextField emailField;
@FXML
private TextField usernameField;
@FXML
private TextField passwordField;
private Stage dialogStage;
private Student student;
private boolean okClicked = false;
private void initialize(){
}
public void setDialogStage(Stage dialogStage){
this.dialogStage = dialogStage;
}
public UserRegisterViewController() {
}
public boolean isOkClicked() {
return okClicked;
}
public Student getStudent(){
return this.student;
}
@FXML
private void handleOk() {
if (isInputValid()) {
Integer stunum = Integer.parseInt(stunumField.getText());
String name = nameField.getText();
Integer age = Integer.parseInt(ageField.getText());
String email = emailField.getText();
String username = usernameField.getText();
String password = passwordField.getText();
Student student1 = new Student();
student1.setStunum(stunum);
student1.setName(name);
student1.setAge(age);
student1.setEmail(email);
student1.setUsername(username);
student1.setPassword(password);
Stu_Classes stu = new Stu_Classes();
stu.setStunum(stunum);
stu.setMathclass("00132");
stu.setComputerclass("00134");
stu.setEnglishclass("00155");
stu.setClassA("null");
stu.setClassB("null");
Stuscore stuscore = new Stuscore();
stuscore.setStunum(stunum);
SqlSession sqlSession = MyBatisUtils.getSqlSession();
StudentDao dao = sqlSession.getMapper(StudentDao.class);
int num = dao.UserRegister(student1);
StuscoreDao dao1 = sqlSession.getMapper(StuscoreDao.class);
int num1 = dao1.insertStuscore(stuscore);
Stu_ClassesDao dao2 = sqlSession.getMapper(Stu_ClassesDao.class);
int num2 = dao2.registerInsert(stu);
sqlSession.commit();
sqlSession.close();
okClicked = true;
dialogStage.close();
}
}
@FXML
private void handleCancel() {
dialogStage.close();
}
private boolean isInputValid() {
String errorMessage = "";
if (stunumField.getText() == null || stunumField.getText().length() == 0) {
errorMessage += "No valid student number!\n";
}
if (nameField.getText() == null || nameField.getText().length() == 0) {
errorMessage += "No valid name!\n";
}
if (ageField.getText() == null || ageField.getText().length() == 0) {
errorMessage += "No valid age!\n";
}
if (emailField.getText() == null || emailField.getText().length() == 0) {
errorMessage += "No valid email name!\n";
}
if (usernameField.getText() == null || usernameField.getText().length() == 0) {
errorMessage += "No valid username!\n";
}
if (passwordField.getText() == null || passwordField.getText().length() == 0) {
errorMessage += "No valid password!\n";
}
try {
Integer.parseInt(ageField.getText());
Integer.parseInt(stunumField.getText());
SqlSession sqlSession = MyBatisUtils.getSqlSession();
StudentDao dao = sqlSession.getMapper(StudentDao.class);
Student student1 = dao.Registerselectstunum(Integer.parseInt(stunumField.getText()));
sqlSession.close();
if(student1 != null){
errorMessage += "stunum registered..\n";
}
SqlSession sqlSession2 = MyBatisUtils.getSqlSession();
StudentDao dao2 = sqlSession2.getMapper(StudentDao.class);
Student student2 = dao2.Registerselectusername(usernameField.getText());
sqlSession2.close();
if(student2 != null){
errorMessage += "stunum registered..\n";
}
} catch (NumberFormatException e) {
errorMessage += "No valid age or student number (must be an integer)!\n";
}
if (errorMessage.length() == 0) {
return true;
} else {
Alert alert = new Alert(Alert.AlertType.WARNING);
alert.setTitle("Warning Dialog");
alert.setHeaderText("Look, a Warning Dialog");
alert.setContentText(errorMessage);
alert.showAndWait();
return false;
}
}
}
TeacherViewController
package cn.zjnu.address.viewAndcontroller;
import cn.zjnu.address.Main;
import cn.zjnu.address.dao.Stu_ClassesDao;
import cn.zjnu.address.model.ClassStuInfo;
import cn.zjnu.address.model.Stu_Classes;
import cn.zjnu.address.utils.MyBatisUtils;
import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.stage.Stage;
import org.apache.ibatis.session.SqlSession;
public class TeacherViewController {
@FXML
private TableView<ClassStuInfo> ClassStuInfoTable;
@FXML
private TableColumn<ClassStuInfo,String> stunameColumn;
@FXML
private Label stunumberLabel;
@FXML
private Label stunameLabel;
@FXML
private Label scoreLabel;
@FXML
private Label emailLabel;
@FXML
private Label courseLabel;
@FXML
private Label classcodeLabel;
private Main main;
private Stage dialogStage;
public void setDialogStage(Stage dialogStage) {
this.dialogStage = dialogStage;
}
@FXML
private void initialize() {
stunameColumn.setCellValueFactory(cellData -> cellData.getValue().stunameProperty());
showStuDetails(null);
ClassStuInfoTable.getSelectionModel().selectedItemProperty().addListener(
(observable,oldValue,newValue) ->showStuDetails(newValue));
}
public void setMain(Main main) {
this.main = main;
ClassStuInfoTable.setItems(main.getStudentData());
}
private void showStuDetails(ClassStuInfo stu){
if(stu!=null){
stunumberLabel.setText(Integer.toString(stu.getStunumber()));
stunameLabel.setText(stu.getStuname());
scoreLabel.setText(Integer.toString(stu.getScore()));
emailLabel.setText(stu.getEmail());
courseLabel.setText(stu.getCourse());
classcodeLabel.setText(stu.getClasscode());
} else {
stunumberLabel.setText("");
stunameLabel.setText("");
scoreLabel.setText("");
emailLabel.setText("");
courseLabel.setText("");
classcodeLabel.setText("");
}
}
@FXML
private void editStuscore() {
ClassStuInfo selectedInfo = ClassStuInfoTable.getSelectionModel().getSelectedItem();
String course = courseLabel.getText();
String classcode = classcodeLabel.getText();
System.out.println(course);
if (selectedInfo != null) {
if ("math".equals(course)) {
course = "mathscore";
} else if ("computer".equals(course)) {
course = "computerscore";
} else if ("English".equals(course)) {
course = "Englishscore";
}
SqlSession sqlSession = MyBatisUtils.getSqlSession();
Stu_ClassesDao dao1 = sqlSession.getMapper(Stu_ClassesDao.class);
Stu_Classes stu = dao1.selectByclasscode2(Integer.parseInt(stunumberLabel.getText()),classcode);
if (stu.getClassA().equals(classcode)) {
course = "selfcourseA";
} else if (stu.getClassB().equals(classcode)) {
course = "selfcourseB";
} else if (stu.getMathclass().equals(classcode)) {
course = "mathscore";
} else if (stu.getComputerclass().equals(classcode)) {
course = "computerscore";
} else if (stu.getEnglishclass().equals(classcode)) {
course = "Englishscore";
}
Integer okclick = 0;
if(course != null){
okclick = main.showEditStuScoreView(Integer.parseInt(stunumberLabel.getText()), course);
}
if (okclick >= 0 && okclick <= 100) {
showStuDetails(selectedInfo);
scoreLabel.setText(Integer.toString(okclick));
}
} else {
Alert alert = new Alert(Alert.AlertType.WARNING);
alert.setTitle("No Selection");
alert.setHeaderText("No Studnent Selected");
alert.setContentText("Please select a student");
alert.showAndWait();
}
}
}
EditStuscoreViewController
package cn.zjnu.address.viewAndcontroller;
import cn.zjnu.address.dao.StuscoreDao;
import cn.zjnu.address.utils.MyBatisUtils;
import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.stage.Stage;
import org.apache.ibatis.session.SqlSession;
public class EditStuscoreViewController {
@FXML
private TextField score;
@FXML
private Button ok;
@FXML
private Button cancel;
private Stage dialogStage;
private Integer stunum;
private String course;
public Integer getStunum() {
return stunum;
}
public void setStunum(Integer stunum) {
this.stunum = stunum;
}
public String getCourse() {
return course;
}
public void setCourse(String course) {
this.course = course;
}
public Integer getScore() {
return Integer.parseInt(score.getText());
}
private Boolean okclike = false;
public Boolean isOkclike() {
return okclike;
}
public void setDialogStage(Stage dialogStage){
this.dialogStage = dialogStage;
}
@FXML
private void EditCancel() {
dialogStage.close();
}
@FXML
private void okClike(){
if(stunum != null && course !=null){
this.update();
}
}
private void update(){
SqlSession sqlSession = MyBatisUtils.getSqlSession();
StuscoreDao dao = sqlSession.getMapper(StuscoreDao.class);
Integer s = this.getScore();
int num = 0;
if(s>=0 && s<=100){
num = dao.updateScore(stunum,course,s);
}else{
Alert alert = new Alert(Alert.AlertType.WARNING);
alert.setTitle("value spliting");
alert.setHeaderText("Digital crossing!");
alert.setContentText("Please put in a proper value..");
alert.showAndWait();
}
sqlSession.commit();
sqlSession.close();
if(num == 1){
okclike = true;
}
dialogStage.close();
}
}