Loading

2.13第一次课前测试总结

今天,周一下午软件工程第一次课课前测试,要求实现一个完整MIs系统的开发流程。

在此次课前测试中的成绩不甚理想。由此总结。

题目:

1、项目需求:

河北省环保监测中心网络新闻为搭建公众信息交流平台,决定建立新闻发布平台。新闻发布平台按内容包括中心新闻、企业环保信息发布等若干新闻栏目,新闻撰稿人可登陆平台发布新闻,每个新闻栏目至少有一位新闻栏目管理员,负责审查新闻撰稿人所发的新闻稿件,在审查通过后,对应新闻才可以显示在对应新闻栏目上,一般用户登录后才可以看到,另外还可以删除过时或无用的信息。另外,系统管理员可以对用户进行管理和对新闻栏目进行调整。新闻发布流程如下:

2.系统要求与功能设计

2.1 页面要求

1)通过浏览器查看,能适应常用分辨率;(1分)

2)布局合理、结构清晰、页面完整;(1分)

3)网站页面整体风格统一;(1分)

4)首页为用户登录页面,不同角色用户登录后,进入相应的功能页,要求密码在数据库中加密;(4分)

5)新闻撰稿人功能页:在线撰写与修改稿件、查看已写稿件及修改意见;

6)普通用户功能页:浏览相应栏目新闻、用户评论新闻(可匿名)、浏览其他用户评论;

7)新闻栏目管理员功能页:浏览与管理本栏目待发与已发新闻;

8)系统管理功能页:用户注册、用户权限管理、新闻栏目管理;

9)对每页中的查询结果推荐采用分页显示。

2.2 功能要求

1)在线撰写新闻稿件:新闻撰稿人在线撰写新闻,选择栏目,正式提交;(2分)

2)查看修改意见:新闻撰稿人查看新闻栏目管理员提出的修改意见;(1分)

3)修改新闻稿件:新闻撰稿人根据修改意见可以对新闻进行修改;(1分)

4)查询已经撰写的新闻:新闻撰稿人可以查看自己已经撰写的新闻;(1分)

5)浏览新闻:普通用户可以浏览栏目的新闻(按照时间倒排);(1分)

6)发表评论回复:普通用户可以对新闻进行发表评论,可选择匿名回复;(1分)

7)按照一定条件查询新闻:栏目管理员可以按照时间段,新闻关键字等条件进行查询;(2分)

8)管理待发与已发新闻:新闻栏目管理员可以批准新闻发布、删除不合适新闻、给出撰稿人修改意见、对已发的过时新闻进行删除;(2分)

9)管理新闻评论回复:新闻栏目管理员可以查看、删除、禁止新闻的回复;(2分)

10)管理新闻栏目:新开新闻栏目、删除新闻栏目、合并新闻栏目、更改新闻栏目的基本信息;(2分)

11)用户管理:管理员可以查询用户、批准新用户、暂停用户、为用户赋予角色,普通用户可以修改用户资料。(2分)

2.1,2.2 评分标准:以上各项分值为页面要求和功能要求,各项分值合计(24分);除此以外设计出合理的数据库和数据表(3分),数据库连接正常(2分),设计出用户权限管理(6分)。

2.3 网站发布

1)网站制作完成后需指定一台机器作为服务器发布。

2)在其他主机上可正常浏览。

评分标准:能够在Tomcat服务器中正确部署(3分),其它主机可正常浏览(2分);

 

部分代码(待修改)

 

  1 package test;
  2 
  3 import java.sql.*;
  4 import java.util.regex.Pattern;
  5 
  6 public class News_writer {
  7     private String  number1,name0,time1,content1;
  8 
  9     public String getContent1() { return content1;}
 10 
 11     public String getName0() {return name0;}
 12 
 13     public String getNumber1() { return number1; }
 14 
 15     public String getTime1() {
 16         return time1;
 17     }
 18 
 19     public void setContent1(String content1) {
 20         this.content1 = content1;
 21     }
 22 
 23     public void setName0(String name0) {
 24         this.name0 = name0;
 25     }
 26 
 27     public void setNumber1(String number1) {
 28         this.number1 = number1;
 29     }
 30 
 31     public void setTime1(String time1) {
 32         this.time1 = time1;
 33     }
 34 
 35     //***********************************************************************
 36     public Connection getConnection()//连接数据库
 37     {
 38         try{
 39             Class.forName("com.mysql.cj.jdbc.Driver");
 40             System.out.println("加载驱动成功");
 41         }catch(ClassNotFoundException e)
 42         {
 43             e.printStackTrace();
 44         }
 45         String user="root";
 46         String password="1506583922";
 47         String url ="jdbc:mysql://localhost:3306/rsy1?characterEncoding=utf8&useSSL=false&serverTimezone=UTC&rewriteBatchedStatements=true";
 48         Connection con=null;
 49         try{
 50             con=DriverManager.getConnection(url,user,password);
 51             System.out.println("数据库连接成功");
 52         }catch(SQLException e)
 53         {
 54             e.printStackTrace();
 55         }
 56         return con;
 57     }
 58     //**********************************************************************
 59     //关闭方法
 60     public  void close (Connection con)
 61     {
 62         try{
 63             if(con!=null)
 64             {
 65                 con.close();
 66             }
 67         }catch(SQLException e)
 68         {
 69             e.printStackTrace();
 70         }
 71     }
 72     public  void close (PreparedStatement preparedStatement)
 73     {
 74         try{
 75             if(preparedStatement!=null)
 76             {
 77                 preparedStatement.close();
 78             }
 79         }catch(SQLException e)
 80         {
 81             e.printStackTrace();
 82         }
 83     }
 84     public  void close(ResultSet resultSet)
 85     {
 86         try{
 87             if(resultSet!=null)
 88             {
 89                 resultSet.close();
 90             }
 91         }catch(SQLException e)
 92         {
 93             e.printStackTrace();
 94         }
 95     }
 96     //******************************************************************
 97     //
 98     public void adddata(String number1,String name0,String time1,String content1)
 99     {
100         Connection connection = getConnection();
101         PreparedStatement preparedStatement=null;
102         try {
103             String sql = "insert into newswriter (账号,昵称,时间,内容) values (?,?,?,?)";
104             preparedStatement=connection.prepareStatement(sql);
105             preparedStatement.setString(1,number1);
106             preparedStatement.setString(2,name0);
107             preparedStatement.setString(3,time1);
108             preparedStatement.setString(4,content1);
109             preparedStatement.executeUpdate();
110             //System.out.println("添加成功");
111 
112         } catch (SQLException  e) {
113             e.printStackTrace();
114         }finally{
115             close(preparedStatement);
116             close(connection);
117         }
118 
119     }
120     //
121     public void deletedata(String number1)
122     {
123         Connection connection = getConnection();
124         PreparedStatement preparedStatement=null;
125         try {
126             String sql = "delete from newswriter where 账号 = ?";
127             preparedStatement=connection.prepareStatement(sql);
128             preparedStatement.setString(1,number1);
129             preparedStatement.executeUpdate();
130             //System.out.println("删除成功");
131 
132         } catch (SQLException  e) {
133             e.printStackTrace();
134         }finally{
135             close(preparedStatement);
136             close(connection);
137         }
138     }
139     //
140     public void revisedata(String number2, String name0, String time1, String content1 , String number1)
141     {
142         Connection connection = getConnection();
143         PreparedStatement preparedStatement=null;
144         try {
145 
146             String sql = "update newswriter set 账号=?, 昵称=?, 时间=?,内容=?  where  账号=?";
147             preparedStatement=connection.prepareStatement(sql);
148             preparedStatement.setString(1,name0);
149             preparedStatement.setString(2,time1);
150             preparedStatement.setString(3,content1);
151             preparedStatement.setString(4,number1);
152             preparedStatement.setString(5,number2);
153             preparedStatement.executeUpdate();
154 
155         } catch (SQLException  e) {
156             e.printStackTrace();
157         }finally{
158             close(preparedStatement);
159             close(connection);
160         }
161     }
162 
163     public boolean isEmpty(String number1,String name0,String time1,String content1)
164     {
165         if(number1==null||name0==null||time1==""||content1=="")
166             return true;
167         else return false;
168     }
169     public boolean isNumber(String str) {
170         Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$");
171         return pattern.matcher(str).matches();
172     }
173     //判重/判存在
174     public boolean isSame(String s)
175     {
176         Connection connection = getConnection();
177         PreparedStatement preparedStatement=null;
178         ResultSet rs=null;
179         try {
180             String sql = "select * from newswriter";
181             preparedStatement=connection.prepareStatement(sql);
182             rs=preparedStatement.executeQuery();
183             while(rs.next()){
184                 if( s.equals(rs.getObject(1))||s.equals(rs.getObject(2)) )
185                     return true;
186             }
187             //preparedStatement.executeUpdate();
188 
189         } catch (SQLException  e) {
190             e.printStackTrace();
191         }finally{
192             close(rs);
193             close(preparedStatement);
194             close(connection);
195         }
196         return false;
197     }
198 
199     //*****************************************************************
200     public static void main(String[] args)
201     {
202         //Data a=new Data();
203     }
204 
205 }

 

package bean;
import java.sql.*;

public class DBBean {
    private String driverStr = "com.mysql.jdbc.Driver";
    private String connStr = "jdbc:mysql://localhost:3306/rsy1";
    private String dbusername = "root";
    private String dbpassword = "1506583922";
    private Connection conn = null;
    private Statement stmt = null;

    public DBBean() {
        try {
            Class.forName(driverStr);
            conn = DriverManager.getConnection(connStr, dbusername, dbpassword);
            stmt = conn.createStatement();
        } catch (Exception ex) {
            System.out.println(ex.getMessage());
            System.out.println("数据连接失败!");
        }

    }

    public int executeUpdate(String s) {
        int result = 0;
        System.out.println("--更新语句:" + s + "\n");
        try {
            result = stmt.executeUpdate(s);
        } catch (Exception ex) {
            System.out.println("执行更新错误!");
        }
        return result;
    }
    public ResultSet executeQuery(String s) {
        ResultSet rs = null;
        System.out.print("--查询语句:" + s + "\n");
        try {
            rs = stmt.executeQuery(s);
        } catch (Exception ex) {
            System.out.println("执行查询错误!");
        }
        return rs;
    }

    public void execQuery(String s) {
        try {
            stmt.executeUpdate(s);
        } catch (SQLException e) {

            System.out.println("执行插入错误!");
        }
    }




    public void close() {
        try {
            stmt.close();
            conn.close();
        } catch (Exception e) {
        }
    } }
package test;

import java.sql.*;
import java.util.regex.Pattern;


/*
新闻撰稿人News_writer
普通用户Ordinary_user
新闻栏目管理员Desk_manager
系统管理员System_administrator
*/
public class Zhanghao {

    private String zhanghao,password,shenfen;


    public String getZhanghao() {
        return zhanghao;
    }

    public String getPassword() {
        return password;
    }

    public String getShenfen() {
        return shenfen;
    }

    public void setZhanghao(String zhanghao) {
        this.zhanghao = zhanghao;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public void setShenfen(String shenfen) {
        this.shenfen = shenfen;
    }
    //***********************************************************************
    public Connection getConnection()//连接数据库
    {
        try{
            Class.forName("com.mysql.cj.jdbc.Driver");
            System.out.println("加载驱动成功");
        }catch(ClassNotFoundException e)
        {
            e.printStackTrace();
        }
        String user="root";
        String password="1506583922";
        String url ="jdbc:mysql://localhost:3306/rsy1?characterEncoding=utf8&useSSL=false&serverTimezone=UTC&rewriteBatchedStatements=true";
        Connection con=null;
        try{
            con= DriverManager.getConnection(url,user,password);
            System.out.println("数据库连接成功");
        }catch(SQLException e)
        {
            e.printStackTrace();
        }
        return con;
    }
    //**********************************************************************
    //关闭方法
    public  void close (Connection con)
    {
        try{
            if(con!=null)
            {
                con.close();
            }
        }catch(SQLException e)
        {
            e.printStackTrace();
        }
    }
    public  void close (PreparedStatement preparedStatement)
    {
        try{
            if(preparedStatement!=null)
            {
                preparedStatement.close();
            }
        }catch(SQLException e)
        {
            e.printStackTrace();
        }
    }
    public  void close(ResultSet resultSet)
    {
        try{
            if(resultSet!=null)
            {
                resultSet.close();
            }
        }catch(SQLException e)
        {
            e.printStackTrace();
        }
    }
    //******************************************************************
    //
    public void adddata(String zhanghao,String password,String shenfen)
    {
        Connection connection = getConnection();
        PreparedStatement preparedStatement=null;
        try {
            String sql = "insert into zhanghao111 (账号,密码,身份) values (?,?,?)";
            preparedStatement=connection.prepareStatement(sql);
            preparedStatement.setString(1,zhanghao);
            preparedStatement.setString(2,password);
            preparedStatement.setString(3,shenfen);
            preparedStatement.executeUpdate();
            //System.out.println("添加成功");

        } catch (SQLException  e) {
            e.printStackTrace();
        }finally{
            close(preparedStatement);
            close(connection);
        }

    }

    //判断方法****************************************************************
    //判空
    public boolean isEmpty(String zhanghao,String password,String shenfen)
    {
        if(zhanghao==null||password==null||shenfen==null)
            return true;
        else return false;
    }
    public boolean isNumber(String str) {
        Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$");
        return pattern.matcher(str).matches();
    }
    //判重/判存在
    public boolean isSame(String s)
    {
        Connection connection = getConnection();
        PreparedStatement preparedStatement=null;
        ResultSet rs=null;
        try {
            String sql = "select * from zhanghao111";
            preparedStatement=connection.prepareStatement(sql);
            rs=preparedStatement.executeQuery();
            while(rs.next()){
                if( s.equals(rs.getObject(1))||s.equals(rs.getObject(2)) )
                    return true;
            }
            //preparedStatement.executeUpdate();

        } catch (SQLException  e) {
            e.printStackTrace();
        }finally{
            close(rs);
            close(preparedStatement);
            close(connection);
        }
        return false;
    }


    //*****************************************************************
    public static void main(String[] args)
    {
        //Data a=new Data();
    }

}

连接数据库失败

在寒假中没有自主学习专业知识,后来也没有再复习,导致没有多少进步还遗忘了许多知识,今后一定要吸取教训

 

posted @ 2023-02-13 18:21  冰稀饭Aurora  阅读(9)  评论(0编辑  收藏  举报