(3)Service层:
package pers.zhb.student.services;import java.util.List;import pers.zhb.student.dao.StudentDao;import pers.zhb.student.domain.Course;import pers.zhb.student.domain.Log;import pers.zhb.student.domain.Student;import pers.zhb.student.domain.Score;public class StudentService { private StudentDao dao = new StudentDao(); public List<Log> Login() { return dao.Login(); } public void register(Log reg) { dao.register(reg); } public void addStudent(Student stu) { dao.addStudent(stu); } public void deleteStudent(String snum) { dao.deleteStudent(snum); } public void updataStudent(Student stu) { dao.updataStudent(stu); } public List<Student> selectAllStudent() { return dao.selectAllStudent(); } public List<Course> selectCourse() { return dao.selectCourse(); } public List<Score> selectScore() { return dao.selectScore(); } public boolean checkPassword(String str) { boolean b = str.matches("[a-zA-Z_0-9]{6}"); return b; }}4、Controller层
package pers.zhb.student.controller;import java.util.List;import pers.zhb.student.domain.Course;import pers.zhb.student.domain.Log;import pers.zhb.student.domain.Student;import pers.zhb.student.domain.Score;import pers.zhb.student.services.StudentService;public class StudentController { private StudentService service = new StudentService(); public void register(Log reg){ service.register(reg); } public List<Log> Login() { return service.Login();} public void addStudent(Student stu) { service.addStudent(stu); } public void deleteStudent(String snum) { service.deleteStudent(snum); } public void updataStudent(Student stu, String studentno) { service.updataStudent(stu); } public List<Student> selectAllStudent() { return service.selectAllStudent(); } public List<Course> selectCourse() { return service.selectCourse(); } public List<Score> selectScore() { return service.selectScore(); } }(5)视图层
package pers.zhb.student.view;import java.util.Iterator;import java.util.List;import java.util.Scanner;import pers.zhb.student.controller.StudentController;import pers.zhb.student.domain.Course;import pers.zhb.student.domain.Log;import pers.zhb.student.domain.Score;import pers.zhb.student.domain.Student;import pers.zhb.student.services.StudentService;public class MainView { private StudentController controller = new StudentController(); private StudentService service = new StudentService(); public void run() { Scanner sc = new Scanner(System.in); while (true) {System.out.println();System.out.println("============欢迎登录学生管理系统============");System.out.println("1:增加学生信息");System.out.println("2:删除学生信息");System.out.println("3:修改学生信息");System.out.println("4:查询学生信息");System.out.println("5:退出");System.out.println("请您输入要操作的功能序号:");int choose = sc.nextInt();switch (choose) {case 1:addStudent();break;case 2:deleteStudent();break;case 3:updataStudent();break;case 4:select();break;case 5:System.out.println("您已退出学生信息管理系统 。");System.exit(0);break;default:System.out.println("输入有误");break;} } } public void select() {// 学生查询、课程查询、 Scanner sc = new Scanner(System.in); while (true) {System.out.println();System.out.println("============欢迎进入学生信息查询页面============");System.out.println("1:查询所有学生信息");System.out.println("2:查询学分在2到5之间的课程号、课程名、课程类型");System.out.println("3:查询计算机学院各个班级的编号、名称 , 如果平均值低于700则不显示");System.out.println("4:进入主页面");System.out.println("请您输入要操作的功能序号:");int choose = sc.nextInt();switch (choose) {case 1:selectAll();break;case 2:selectCourse();break;case 3:selectScore();break;case 4:run();} } } public void register() {// 注册 System.out.println("a:新用户"); System.out.println("b:老用户"); Scanner sc = new Scanner(System.in); String registerChoose = sc.next(); if (registerChoose.equals("a")) {Log l = new Log();System.out.println("请输入账号:");l.setAccount(sc.next());System.out.println("请输入六位密码(字母、数字、下划线):");String password=sc.next();if(service.checkPassword(password)){l.setPassword(password);}else{System.out.println("密码的格式不正确");System.exit(0);}service.register(l);System.out.println("您已注册成功"); } if (registerChoose.equals("b")) {Login(); } } public void Login() { Scanner sc = new Scanner(System.in); System.out.println("请输入账号"); String account = sc.next(); System.out.println("请输入密码"); String password = sc.next(); Iterator<Log> listIt = service.Login().iterator();// 获取集合的实现类对象 , 并调用集合的iterator() while (listIt.hasNext()) {Log l = listIt.next();if (account.equals(l.getAccount())&& password.equals(l.getPassword())) {System.out.println(l.getAccount() + " , " + "您已登陆成功");run();} } Iterator<Log> listIt1 = service.Login().iterator();// 获取集合的实现类对象 , 并调用集合的iterator() while (listIt1.hasNext()) {Log l = listIt1.next();if (account.equals(l.getAccount()) == true|| password.equals(l.getPassword()) == false) {System.out.println("登陆失败");System.exit(0);} } } public void addStudent() {// 添加学生信息 Scanner sc = new Scanner(System.in); Student stu = new Student(); System.out.println("请输入学号:"); stu.setStudentno(sc.next()); System.out.println("请输入姓名:"); stu.setSname(sc.next()); System.out.println("请输入性别"); stu.setSex(sc.next()); System.out.println("请输入出生日期"); stu.setBirthday(sc.next()); System.out.println("请输入班级编号"); stu.setClassno(sc.next()); System.out.println("请输入入学成绩"); stu.setPoint(sc.nextFloat()); System.out.println("请输入联系电话"); stu.setPhone(sc.next()); System.out.println("请输入电子邮箱"); stu.setEmail(sc.next()); service.addStudent(stu); System.out.println(stu.getSname() + "的信息添加成功"); } public void deleteStudent() {// 删除某一个学生的信息 System.out.println("请输入要删除的学生的学号"); Scanner sc = new Scanner(System.in); String snum = sc.next(); service.deleteStudent(snum); System.out.println("学号为" + snum + "的学生信息删除成功"); } public void updataStudent() {// 修改学生信息 Scanner sc = new Scanner(System.in); Student stu = new Student(); System.out.println("请输入学号:"); stu.setStudentno(sc.next()); System.out.println("请输入新的姓名:"); stu.setSname(sc.next()); System.out.println("请输入新的性别"); stu.setSex(sc.next()); System.out.println("请输入新的出生日期"); stu.setBirthday(sc.next()); System.out.println("请输入新的班级编号"); stu.setClassno(sc.next()); System.out.println("请输入新的入学成绩"); stu.setPoint(sc.nextFloat()); System.out.println("请输入新的联系电话"); stu.setPhone(sc.next()); System.out.println("请输入新的电子邮箱"); stu.setEmail(sc.next()); service.updataStudent(stu); } public void selectAll() {// 查询所有 List<Student> list = controller.selectAllStudent(); if (list.size()!= 0)print(list); elseSystem.out.println("没有查询到数据"); } private void print(List<Student> list) {// 查询所有 System.out.println("全部学生信息:"); for (Student students : list) {System.out.println(students); } } public void selectCourse() {// 查询课程 List<Course> list = controller.selectCourse(); if (list.size() != 0)printCourse(list); elseSystem.out.println("没有查询到数据"); } private void printCourse(List<Course> list) {// 查询课程 System.out.println("学分在2到5之间的课程号、课程名、课程类型 , 并将查询结果按课程类型升序排列 , 同一类型的课程按学分降序排列:"); for (Course courses : list) {System.out.println(courses); } } public void selectScore() {// 查询分数 List<Score> list = controller.selectScore(); if (list.size() != 0)printScore(list); elseSystem.out.println("没有查询到数据"); } private void printScore(List<Score> list) {// 查询分数 System.out.println("查询计算机学院各个班级的编号、名称 , 如果平均值低于700则不显示:"); for (Score scores : list) {System.out.println(scores); } }}
- mysql:数据库之删除记录对自动增长的影响
- mysql数据库中的sql语句——作业题讲解-2
- RetentionPolicy.RUNTIME Java运用注解处理器接口注解生成SQL表
- MySQL教程4 MySQL8运算符 22.向JSON数据中插入新值 学习猿地
- 学生教师节送什么礼物好?
- insert mysql数据库介绍:创建和读取(select)数据库的数据
- JavaEE精讲-MyBatis框架实战-SQL复习
- 践行价值观文明我先行手抄报,超级简单又好看的小学生文明手抄报
- 学习猿地 PHP教程 20 PHP连接MySQL 4.修改数据操作
- C#如何动态创建MySql数据库和表