• 【软件设计】DAO分层设计练习


    一、数据库系统的三层架构

    1、界面层(UI)

    我们要做一个项目,想要什么样的外观,这是界面层要解决的问题
    请添加图片描述

    2、业务逻辑层(BLL)

    为用户的每个功能模块,设计一个业务逻辑类。此时,需要利用相关的数据访问层类中,记录操作方法的特定集合,来实现每个逻辑功能。

    3、数据访问层(DAO:Data Access Object)

    业务层在实现相应功能的时候,需要访问数据库,而访问数据库就是对其进行增删查改的操作,因此DAO层实际上是面向数据库的增删查改而设计的,业务层通过调用数据访问层的服务实现业务处理。数据访问层实际上就是用Java语句来执行SQL语句。对于数据的存储,数据库中使用数据表,在程序中要使用对象,对象是对数据库中数据表的一种建模,对象名一定要与数据库中数据表的名称一致,这些对象就是简单Java类,通过这些简单Java类来存储和运输数据。

    • 开发数据访问层的标准:命名方式严格使用xxxDao
    • 数据更新:doXxx(),doCreate(),doUpdate(),doRemove()
    • 数据查询:查询数据表中的数据:findXxx()。findByID(),findByName()
    • 查询数据表中的统计信息:getXxx(),getAllCount()
    • 在设计接口的时候,要写清楚属性和方法的注释

    4、三层之间的调用关系

    数据访问层的类:直接访问数据库,实现基本记录操作
    业务逻辑层的类:调用相关的数据访问层的类,实现用户所需功能
    界面层:部署控件后,调用业务逻辑层的类,实现功能

    5、实体类(Entity)

    存放实体类,实现数据对象实体和方法分离,以便在多个层中传递数据

    6、业务测试

    在test包中进行测试,明确这里的测试对象,这里主要是对业务进行测试,因此使用的主要就是业务层工厂类。

    7、使用DAO进行分层设计

    注意程序的结构搭建,实体层,DAO接口,DAO实现类:

    • 数据库访问辅助类:DBUtil.java
    • 实体类:User.java
    • 数据访问接口:UserDao.java
    • 数据访问接口的实现类:UserDaoImpl.java
    • 并运行业务处理类:TestDao

    二、JDBC

    JDBC的全称是Java数据库连接==(Java Database connect)==,它是一套用于执行SQL语句的Java API。应用程序可通过这套API连接到关系数据库,并使用SQL语句来完成对数据库中数据的查询、更新和删除等操作。应用程序使用JDBC访问数据库的方式如下图所示:
    请添加图片描述

    1、搭建实验环境

    启动 mysql 数据库,打开“myschool.sql”文件并执行,创建数据库 myschool

    2、导入数据库驱动

    在项目中新建文件夹lib,将jar包mysql-connector-java-8.0.13.jar复制到lib下,右击lib,选择“add as library”。
    请添加图片描述

    3、编写JDBC程序

    加载驱动mysql8.0版本

    Class.forName("com.mysql.cj.jdbc.Driver");
    
    • 1

    建立连接

    conn = DriverManager.getConnection("jdbc:mysql:///myschool?serverTimezone=Hongkong", "root", "数据库密码");
    
    • 1

    编写SQL语句

    String sql = "insert into users(username,password) values('Rose','123')";
    
    • 1

    三、使用DAO分层设计练习

    1、实验要求

    • 配置好maven;
    • 创建一个maven项目,将mysql-connector-java-8.0.13.jar配置到pom.xml文件中;
    • 参考TestDao.java程序,自行设计一个程序,访问myschool数据库的course表;
    • 将运行结果截图,和程序一起提交

    2、配置maven

    pom.xml
    
    <project xmlns="http://maven.apache.org/POM/4.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0modelVersion>
    
        <groupId>org.examplegroupId>
        <artifactId>week5_20201000000artifactId>
        <version>1.0-SNAPSHOTversion>
        
        <properties>
          <maven.compiler.source>8maven.compiler.source>
            <maven.compiler.target>8maven.compiler.target>
        properties>
            <dependencies>
                <dependency>
                    <groupId>mysqlgroupId>
                    <artifactId>mysql-connector-javaartifactId>
                    <version>8.0.13version>
                dependency>
            dependencies>
    project>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22

    请添加图片描述

    配置成功后,点开此路径,可以查看自动下载的文件

    D:\Maven_Repository\Repository\mysql\mysql-connector-java\8.0.13

    请添加图片描述

    3、访问myschool数据库的course表(代码)

    User.java
    package com.entity;
    
    // User实体类,针对数据表User,实现数据表到类结构的转换,供 DAO层使用
    //一个user对象对应 mysql表中一行
    public class User {
        private int id;// 主键
    
        private String username;// 用户名
    
        private String password;// 密码
    
    
        public User(int id, String username, String password) {
            super();
            this.id = id;
            this.username = username;
            this.password = password;
        }
    
        public User(String username, String password) {
            super();
            this.username = username;
            this.password = password;
        }
    
    
        public User() {
            super();
            // TODO Auto-generated constructor stub
        }
    
        public int getId() {
            return id;
        }
    
        public void setId(int id) {
            this.id = id;
        }
    
        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;
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    Course.java
    package com.entity;
    public class Course {
        private int id;
    
        private String cname;
    
        private int credit;
    
        private String department;
    
        private String content;
    
        public Course() {
    
        }
    
        public Course(String cname, int credit, String department, String content) {
            this.cname = cname;
            this.credit = credit;
            this.department = department;
            this.content = content;
        }
    
        public Course(int id, String cname, int credit, String department, String content) {
            this.id = id;
            this.cname = cname;
            this.credit = credit;
            this.department = department;
            this.content = content;
        }
    
        public int getId() {
            return id;
        }
    
        public void setId(int id) {
            this.id = id;
        }
    
        public String getCname() {
            return cname;
        }
    
        public void setCname(String cname) {
            this.cname = cname;
        }
    
        public int getCredit() {
            return credit;
        }
    
        public void setCredit(int credit) {
            this.credit = credit;
        }
    
        public String getDepartment() {
            return department;
        }
    
        public void setDepartment(String department) {
            this.department = department;
        }
    
        public String getContent() {
            return content;
        }
    
        public void setContent(String content) {
            this.content = content;
        }
    
        @Override
        public String toString() {
            return "Course{" +
                    "id=" + id +
                    ", cname='" + cname + '\'' +
                    ", credit=" + credit +
                    ", department='" + department + '\'' +
                    ", content='" + content + '\'' +
                    '}';
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    UserDao.java
    package com.dao;
    
    import com.entity.User;
    
    import java.util.List;
    
    //专门处理user表的接口
    public interface UserDao {
    
        public boolean doAdd(User item);
    
        public boolean doDeleteById(int id);
    
        public boolean doUpdate(User item);
    
        public List<User> findAll();
    
        public List<User> findById(int id);
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    CourseDao.java
    package com.dao;
    import com.entity.Course;
    
    import java.util.List;
    
    public interface CourseDao {
        public boolean doAdd(Course item);
    
        public boolean doDeleteById(int id);
    
        public boolean doUpdate(Course item);
    
        public List<Course> findAll();
    
        public List<Course> findById(int id);
    
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    UserDaoImpl.java
    package com.dao.impl;
    import com.dao.UserDao;
    import com.db.DBUtilConfig;
    import com.entity.User;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.util.ArrayList;
    import java.util.List;
    
    //UserDao的实现类,通过DBUtil访问数据库
    public class UserDaoImpl implements UserDao {
        private DBUtilConfig db;
    
        public UserDaoImpl() {
            db=new DBUtilConfig();
        }
    
        @Override
        public boolean doAdd(User item) {
            String sql="insert into users(id,username,password) values(null,?,?)";
            Object[] params = { item.getUsername(),item.getPassword() };
            return db.execUpdate(sql,params);
        }
    
        @Override
        public boolean doDeleteById(int id) {
            String sql="delete from users where id = ?";
            Object[] params = { id };
            return db.execUpdate(sql,params);
    
        }
    
    
        @Override
        public boolean doUpdate(User item) {
            String sql="update users set username= ?,password = ? where id = ?";
            Object[] params = { item.getUsername(),item.getPassword(),item.getId() };
            return db.execUpdate(sql,params);
        }
    
        @Override
        public List<User> findById(int id) {
            List<User> usersList = new ArrayList<User>();
            String selectUsers="select * from users where id = ?";
            Object[] selparams = {id};
            //2.执行并接收查询结果
            ResultSet rest= db.execQueryById(selectUsers,selparams);
            try {
                while(rest.next())
                {
                    int iid=rest.getInt("id");
                    String username=rest.getString("username");
                    String password=rest.getString("password");
                    usersList.add(new User(iid,username,password));
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
            finally
            {
                db.DBclose();
            }
            return usersList;
        }
    
        @Override
        public List<User> findAll() {
            List<User> usersList = new ArrayList<User>();
            String selectUsers="select * from users";
            //2.执行并接收查询结果
            ResultSet rest= db.execQueryAll(selectUsers);
            try {
                while(rest.next())
                {
                    int iid=rest.getInt("id");
                    String username=rest.getString("username");
                    String password=rest.getString("password");
                    usersList.add(new User(iid,username,password));
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
            finally
            {
                db.DBclose();
            }
            return usersList;
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    CourseDaoImpl.java
    package com.dao.impl;
    import com.db.DBUtilConfig;
    import com.dao.CourseDao;
    import com.entity.Course;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.util.ArrayList;
    import java.util.List;
    public class CourseDaoImpl implements CourseDao {
        private DBUtilConfig db;
    
        public CourseDaoImpl() {
            db=new DBUtilConfig();
        }
    
        @Override
        public boolean doAdd(Course item) {
    //        String sql="insert into course(cname,credit,department,content) values('"+item.getCname()+"','"+item.getCredit()+"','"+item.getDepartment()+"','"+item.getContent()+"')";
            String sql="insert into course(id,cname,credit,department,content) values(null,?,?,?,?)";
            Object[] params = { item.getCname(),item.getCredit(),item.getDepartment(),item.getContent() };
            return db.execUpdate(sql,params);
        }
    
        @Override
        public boolean doDeleteById(int id) {
            String sql="delete from course where id = ?";
            Object[] params = { id };
            return db.execUpdate(sql,params);
    
        }
    
        @Override
        public boolean doUpdate(Course item) {
            String sql="update course set cname= ?,credit = ?,department = ?,content = ? where id = ?";
            Object[] params = { item.getCname(),item.getCredit(),item.getDepartment(),item.getContent(),item.getId() };
            return db.execUpdate(sql,params);
        }
    
        @Override
        public List<Course> findById(int id) {
            List<Course> courseList = new ArrayList<Course>();
            String selectCourse="select * from course where id = ?";
    //        封装参数
            Object[] selparams = { id };
            //2.执行并接收查询结果
            ResultSet rest= db.execQueryById(selectCourse,selparams);
            try {
                while(rest.next())
                {
                    int iid=rest.getInt("id");
                    String cname=rest.getString("cname");
                    int credit=rest.getInt("credit");
                    String department=rest.getString("department");
                    String content=rest.getString("content");
                    courseList.add(new Course(iid,cname,credit,department,content));
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
            finally
            {
                db.DBclose();
            }
            return courseList;
        }
    
        @Override
        public List<Course> findAll() {
            List<Course> courseList = new ArrayList<Course>();
            String selectCourse="select * from course";
    //        封装参数
    //        Object[] selparams = { 1 };
            //2.执行并接收查询结果
            ResultSet rest= db.execQueryAll(selectCourse);
            try {
                while(rest.next())
                {
                    int id=rest.getInt("id");
                    String cname=rest.getString("cname");
                    int credit=rest.getInt("credit");
                    String department=rest.getString("department");
                    String content=rest.getString("content");
                    courseList.add(new Course(id,cname,credit,department,content));
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
            finally
            {
                db.DBclose();
            }
            return courseList;
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    DBUtilConfig.java
    package com.db;
    import java.io.InputStream;
    import java.sql.*;
    import java.util.Properties;
    //DBUtilConfig读取配置文件
    public class DBUtilConfig {
    
        private static String driver = null;
        private static String url = null;
        private static String username = null;
        private static String password = null;
        protected Connection conn;
    
        //静态代码块,在类初次被加载的时候执行且仅会被执行一次
        static {
            try {
                // 在Java中,其配置文件常为.properties文件,是以键值对的形式进行参数配置的。
                // 用Properties类来读取.properties文件数据
    
                // 步骤说明:1.调用类加载器的方法加载资源,返回的字节流
                // DBUtilConfig.class是获得当前对象所属的class对象
                // getClassLoader()是取得该Class对象的类装载器
                // getResourceAsStream(“database.properties”)
                InputStream ins = DBUtilConfig.class.getClassLoader().getResourceAsStream("database.properties");
    
                // 2.使用Properties类,从.properties属性文件对应的文件输入流中,加载属性列表到Properties类对象,
                Properties props = new Properties();
                props.load(ins);
    
                // 3.通过getProperty方法用指定的键在此属性列表中搜索属性, 动态获取.properties配置文件中的数据
                driver = props.getProperty("driver");
                url = props.getProperty("url");
                username = props.getProperty("username");
                password = props.getProperty("password");
    
                // 4、加载驱动
                Class.forName(driver);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    
        public static Connection getConnection() throws SQLException {
            return DriverManager.getConnection(url, username, password);
        }
    
        // 3.执行更新数据库的预编译SQL命令
        public boolean execUpdate(String sql, Object[] params) {
            try {
                conn = getConnection();
            } catch (SQLException e1) {
                e1.printStackTrace();
            }
            try {
    
                // 1.创建预编译命令对象
                PreparedStatement stmt = conn.prepareStatement(sql);
                // 2.设置为字段匹配参数
                for (int i = 0; params != null && i < params.length; i++) {
    
                    Object param = params[i];
                    if (param instanceof Integer) {
                        stmt.setInt(i + 1, Integer.parseInt(param.toString()));
                    }
                    if (param instanceof Float) {
                        stmt.setFloat(i + 1, Float.parseFloat(param.toString()));
                    }
                    if (param instanceof Double) {
                        stmt.setDouble(i + 1, Double.parseDouble(param.toString()));
                    }
                    if (param instanceof String) {
                        stmt.setString(i + 1, param.toString());
                    }
                }
    
                // 3.执行预编译命令
                if (stmt.executeUpdate() > 0) {
                    return true;
                }
    
            } catch (SQLException e) {
                e.printStackTrace();
            } finally {
                if (conn != null) {
                    try {
                        conn.close();
                    } catch (SQLException e) {
                        e.printStackTrace();
                    }
                }
            }
            return false;
        }
    
        // 4.执行预编译查询
        public ResultSet execQueryById(String sql, Object[] params) {
            try {
                conn = getConnection();
            } catch (SQLException e1) {
                e1.printStackTrace();
            }
    
            try {
                // 1.创建预编译命令对象
                PreparedStatement stmt = conn.prepareStatement(sql);
                // 2.设置为字段匹配参数
                for (int i = 0; params != null && i < params.length; i++) {
    
                    Object param = params[i];
                    if (param instanceof Integer) {
                        stmt.setInt(i + 1, Integer.parseInt(param.toString()));
                    }
                    if (param instanceof Float) {
                        stmt.setFloat(i + 1, Float.parseFloat(param.toString()));
                    }
                    if (param instanceof Double) {
                        stmt.setDouble(i + 1, Double.parseDouble(param.toString()));
                    }
                    if (param instanceof String) {
                        stmt.setString(i + 1, param.toString());
                    }
                }
    
                // 3.执行预编译命令
                return stmt.executeQuery();
    
            } catch (SQLException e) {
                e.printStackTrace();
            }
            return null;
        }
    
        // 4.执行查询全部
        public ResultSet execQueryAll(String sql) {
            try {
                conn = getConnection();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            try {
                Statement stmt = conn.createStatement();
                return stmt.executeQuery(sql);
            } catch (SQLException e) {
                e.printStackTrace();
            }
            return null;
        }
    
        // 5.关闭数据库
        public void DBclose() {
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
    
        }
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    TestMavenCourseDao.java
    import com.dao.CourseDao;
    import com.dao.impl.CourseDaoImpl;
    import com.entity.Course;
    import java.util.List;
    public class TestMavenCourseDao {
    
        public static void main(String[] args) {
            CourseDao courseDao = new CourseDaoImpl();
            System.out.println("———————————————add插入———————————————————");
            courseDao.doAdd(new Course("数据挖掘",3,"软件工程","content"));
            courseDao.doAdd(new Course("自然语言处理",3,"软件工程","content"));
    
            System.out.println("———————————————findById查找ID———————————————————");
            List<Course> courseListById = courseDao.findById(5);
            for (Course item:courseListById){
                System.out.println(item.toString());
            }
            System.out.println("———————————————当前表格———————————————");
            List<Course> courseListAll1 = courseDao.findAll();
            for (Course item:courseListAll1){
                System.out.println(item.toString());
            }
    
            courseDao.doDeleteById(5);
            System.out.println("———————————————delete删除———————————————————");
            System.out.println("———————————————当前表格———————————————");
            List<Course> courseListAll2 = courseDao.findAll();
            for (Course item:courseListAll2){
                System.out.println(item.toString());
            }
    
            courseDao.doUpdate(new Course(9,"更新name",10,"更新depart","更新content"));
            System.out.println("———————————————当前表格———————————————");
            List<Course> courseListAll3 = courseDao.findAll();
            for (Course item:courseListAll3){
                System.out.println(item.toString());
            }
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39

    4、实验结果

    请添加图片描述

  • 相关阅读:
    常用的数字签名,信息加密算法
    NSSCTF2nd与羊城杯部分记录
    Ubuntu入门05——磁盘管理与备份压缩
    『Android基础控件』Lottie实现复杂动画效果
    基于强化学习的电动汽车的储能系统优化控制和存储容量优化(Matlab代码实现)
    JWT安全及案例实战
    基于PHP的Laravel框架实现学生管理系统(1+X Web前端开发中级 例题)——初稿
    己知一棵有 2011 个结点的树,其叶结点个数为 116,该树对应的二叉树无右孩子的结点个数是
    spring boot thymeleaf 404 error
    PaddleOCR 更换模型
  • 原文地址:https://blog.csdn.net/weixin_51293984/article/details/127086876