zoukankan      html  css  js  c++  java
  • 千锤百炼软工11.20-11.27

    首先这么长时间来,不止这个礼拜,我看了很多很多书,JAVAweb已经看完了,但是我还是不满足,我又看了很多其他的书,

    而这个礼拜我主要看了JAVAscript这本书,这本书讲的内容让我耳目一新,很多JSP中的操作都是需要javascript

    而且在这本书中我第一次接触到了CSS,也就是javaweb前端页面的开发,接触到这个之后我感到非常的新奇,于是也赶快记下了笔记,

    下面是我的笔记:

     建民在这周发了一个大作业,让我们做了一个石家庄铁道大学的选课管理系统,因为我作为一个初学者,除了练习熟练度,

    最主要的还是学习一下框架,怎么熟练地运用MVC,所以我首先就是自己写了一个这个项目的大纲,如下:

     值得一提的是,以前我用Dao连接数据库的时候,是一个过那个能写一个class,但是这次我进行了改进,我把他们每一个功能,包括打开,关闭数据库等

    全部都封装在了一个函数内。而且我的包除了servlet和Dao又多了一个service层,因为我优化了我的Dao层代码,革除里面的sql语句,我将sql语句放到了service

    里面,这样可以实现一个函数的多次使用,比如一个函数就可以实现增删改三个功能:

    public static Connection getCon() throws SQLException, ClassNotFoundException {
         Class.forName(DBDRIVER);
         Connection con = DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD);
         return con;
    }
    /*  close sql
    *****
    ******
    *******/
    public static void close(Connection con,PreparedStatement ps,ResultSet rs,Statement stat) {
        if(rs!= null) {
            try {
                rs.close();
            }catch(SQLException e) {
                e.printStackTrace();
            }
        }
        if(stat!= null) {
            try {
                stat.close();
            }catch(SQLException e) {
                e.printStackTrace();
            }
        }
        if(ps!= null) {
            try {
                ps.close();
            }catch(SQLException e) {
                e.printStackTrace();
            }
        }
        if(con!= null) {
            try {
                con.close();
            }catch(SQLException e) {
                e.printStackTrace();
            }
        }
    }
    /* add update delete
    *****
    ******
    *******/
    public static boolean addUpdateDelete(String sql,String[] arr) {
        Connection con = null;
        PreparedStatement ps = null;
        Statement stat =null;
        ResultSet rs = null;
        try {
            con = getCon();
            ps = con.prepareStatement(sql);
            if(arr!=null&& arr.length!=0) {
                for(int i=0;i<arr.length;i++) {
                    ps.setString(i+1, arr[i]);
                }
            }
            int count = ps.executeUpdate();
            if(count>0) {
                return true;
            }else {
                return false;
            }
        }catch(ClassNotFoundException e) {
            e.printStackTrace();
        }catch(SQLException e) {
            e.printStackTrace();
        }
        close(con,ps,rs,stat);
        return false;
    }

    然后service里面:

    public class service {
        /*  add a teacher or student
         * 
         */
        public boolean addCrew(String arr[],String name){
            String sql = "insert into "+name+"(account,password,id,name,sex,college,insti) values(?,?,?,?,?,?,?)";
            boolean res = Dao.addUpdateDelete(sql, arr);
            return res;
        }
        /* add a class
         * 
         */
        public boolean addClass(String arr[]) {
            String sql = "insert into class(id,name,number,teacher) values(?,?,?,?)";
            boolean res = Dao.addUpdateDelete(sql, arr);
            return res;
        }
    /*  update messages
         * 
         */
        public boolean update(String ID,String[]arr,String ele) {
            String sql = "update teacher set "+ele+" = ? where id = ? ";
            boolean res = false;
            res = Dao.addUpdateDelete(sql, arr);
            return res;
        }

    这样就实现了一个Dao函数实现三个功能:

    然后就是学到了通过CSS编写ul>li>ul>li 这种嵌套的格式,

    以及嵌套在里面的ul>li 的显示和隐藏,并通过JAVAscript代码实现单机后显隐的控制:

    <style type="text/css">
    body{
    background-color:#eed00e0;
    }
    #navigation{
    200px;
    font-family:Arial;
    }
    #navigation > ul> li{
    border-bottom:1px solid #AD9F9;
    }
    #navigation > ul> li > a{
    display:block;
    padding:5px 5px 5px 0.5em;
    text-decoration:none;
    border-left:12px solid #7111111;
    }
    #navigation > ul> li > a:link, #navigation > ul > li > a:visited{
     background-color :#cllll36;
     color:#880020;
    }
    #navigation > ul > li > a:hover{
    background-color:#880020;
    color:#ff0000;
    }
    h1{
    color:red;
    background-color:#49ff01;
    text-align:center;
    padding:20px;
    }
    img{
    float:left;
    border:2px #F00 solid;
    margin:5px;
    }
    #navigation ul li ul{
     margin:0px;
     padding:0px 0px 0px 0px;
     display:none;
    }
    #navigation ul lu ul li{
    border-top:1px solid #ED9F9F;
    }
    #navigation ul li ul li a{
    display:block;
    padding:3px 3px 3px 0.5em;
    text-decoration:none;
    border-left:28px solid #a71f1f;
    border-right:1px solid #711515;
    }
    #navigation ul li ul li a:link, #navigation ul li ul li  a:visited{
    background-color:#c2425d;
    color:#ffff00;
    }
    #navigation ul li ul.myShow{
    display:none;
    }
    #navigation ul li ul.myHide{
    display:block;
    }
    </style>

    这是css代码

    下面是通过点击控制显隐性:

    function change(){
        var secondDiv = this.parentNode.getElementsByTagName("ul")[0];
        if(secondDiv.className=="myHide")
            secondDiv.className = "myShow";
        else
            secondDiv.className = "myHide";
    }
    window.onload = function(){
        
        var Ul = document.getElementById("listUL");
        var aLi = Ul.childNodes;
        var A;
        for(var i=0;i<aLi.length;i++){
            if(aLi[i].tagName=="LI" && aLi[i].getElementsByTagName("ul").length){
                A = aLi[i].firstChild;
                A.onclick = change;
            }
        }
    }

    这是一次非常成功的web小项目,其中很让我头疼的就是库内很多很多表的来回调用和计算,很费脑子。

    好在经过长时间的思考还是让我想出来了。

  • 相关阅读:
    -bash: fork: Cannot allocate memory 问题的处理
    Docker top 命令
    docker常见问题修复方法
    The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)
    What's the difference between encoding and charset?
    hexcode of é î Latin-1 Supplement
    炉石Advanced rulebook
    炉石bug反馈
    Sidecar pattern
    SQL JOIN
  • 原文地址:https://www.cnblogs.com/chaogehahaha/p/14149612.html
Copyright © 2011-2022 走看看