国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Javaweb項目案例:一個簡單的用戶管理系統(tǒng)實現(xiàn)

這篇具有很好參考價值的文章主要介紹了Javaweb項目案例:一個簡單的用戶管理系統(tǒng)實現(xiàn)。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

1.項目背景

我們來設(shè)計一個簡單的用戶管理系統(tǒng),具有查看用戶,添加用戶,刪除用戶,更新用戶的所有功能,并能支持分頁顯示,以及通過關(guān)鍵詞模糊查詢的

本項目采用Druid數(shù)據(jù)庫連接池

注意:JDBC和DAO部分本文不予演示,請自行完成此部分代碼的編寫???


2.展示用戶列表

模板頁面,showuser.html

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>用戶列表</title>
</head>
<style>
    table {
        width: 80%;
        border-color: white;
    }

    table tr {
        line-height: 30px;
        border-color: white;
    }

    table tr:FIRST-CHILD {
        background: #f2f2f2;
    }

    table tr:nth-child(even) {
        background: #d5eeeb;
    }


</style>
<script type="text/javascript">
    /**
     * 刪除用戶
     * @param uid 用戶ID信息
     */
    function delUser(uid) {
        if (confirm('是否確認(rèn)刪除?')) {
            window.location.href = 'del.do?id=' + uid;
        }
    }

    /**
     * 獲取某一頁的用戶數(shù)據(jù)
     * @param pageNo 頁碼
     */
    function page(pageNo) {
        if (pageNo > 0) {
            window.location.href = 'showuser?pageNo=' + pageNo;
        }
    }

</script>
<body>
<form action="showuser" method="post">
    <input type="hidden" name="oper" value="search">
    查找關(guān)鍵字:<input type="text" name="keyword" th:value="${session.keyword}">
    <button type="submit">提 交</button>
</form>
<table>
    <tbody>
    <tr align="center">
        <td>用戶名</td>
        <td>學(xué)校</td>
        <td>刪除內(nèi)容</td>
        <td>添加內(nèi)容</td>
    </tr>
    <tr align="center" th:if="${#lists.isEmpty(session.userList)}">
        <td>沒有啦</td>
        <td>沒有啦</td>
        <td>沒有啦</td>
        <td>沒有啦</td>
    </tr>

    <tr align="center" th:unless="${#lists.isEmpty(session.userList)}" th:each="user : ${session.userList}">
        <td><a th:text="${user.username}" th:href="@{/edit.do(uid=${user.id})}"></a></td>
        <td><a th:text="${user.school}" th:href="@{/edit.do(uid=${user.id})}"></a></td>
        <td><a th:onclick="|delUser(${user.id})|">刪除</a></td>
        <td><a th:href="@{/add.html}">添加</a></td>
    </tr>
    </tbody>
</table>
<!--分頁-->
<div>
    <input type="button" value="首 頁" th:onclick="|page(1)|">
    <input type="button" value="上一頁" th:onclick="|page(${session.pageNo - 1})|">
    <input type="button" value="下一頁" th:onclick="|page(${session.pageNo + 1})|">
    <input type="button" value="尾 頁" th:onclick="|page(${session.totalPageNo})|">
</div>
</body>
</html>

ShowUserServlet:

/**
 * 使用Thymeleaf渲染頁面展示user列表
 */
@WebServlet("/showuser")
public class ShowUserServlet extends ViewBaseServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        HttpSession session = req.getSession();
        int pageNo = 1;
        // 如果oper為null,說明是通過表單查詢按鈕點擊過來的
        // 如果oper是null,說明不是通過表單查詢按鈕點擊過來的
        String oper = req.getParameter("oper");
        String keyword = null;
        if ("search".equals(oper)) {
            pageNo = 1;
            keyword = req.getParameter("keyword");
            if (keyword == null) {
                keyword = "";
            }
            session.setAttribute("keyword", keyword);
        } else {
            String pageNoStr = req.getParameter("pageNo");
            if (pageNoStr != null) {
                pageNo = Integer.parseInt(pageNoStr);
            }
            Object keywordObj = session.getAttribute("keyword");
            if (keywordObj != null) {
                keyword = (String) keywordObj;
            } else {
                keyword = "";
            }
        }

        // 將頁碼保存到session作用域
        session.setAttribute("pageNo", pageNo);

        UserDAO userDAO = new UserDAO();
        List<User> userList = userDAO.getUserListByPageAndKeyword(pageNo, keyword);
        // 將userList放到session 作用域
        session.setAttribute("userList", userList);

        // 得到用戶總數(shù)
        long userCount = userDAO.getUserCount(keyword);
        // 得到頁數(shù)
        long totalPageNo = userCount / 5 + 1;
        session.setAttribute("totalPageNo", totalPageNo);

        // 注意:物理視圖名稱 = view-prefix + view-suffix
        // 這里結(jié)合xml文件拼接也就是/showuser.html
        super.processTemplate("showuser", req, resp);
    }
}

3.添加用戶

add.html

<!-- user表添加頁面 -->
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="UTF-8">
  <title>用戶添加頁面</title>
</head>
<style>
  * {
    margin: 0;
    padding: 0;
  }

  /*漸變背景樣式*/
  body {
    height: 100vh;
    width: 100%;
    overflow: hidden;
    background-image: linear-gradient(125deg, #F44336, #E91E63, #9C27B0, #3F51B5, #2196F3);
    background-size: 400%;
    font-family: "montserrat";
    animation: bganimation 15s infinite;
  }

  @keyframes bganimation {
    0% {
      background-position: 0% 50%;
    }
    50% {
      background-position: 100% 50%;
    }
    100% {
      background-position: 0% 50%;
    }
  }

  /*表單樣式*/
  .form {
    width: 85%;
    max-width: 600px;
    /* max-height:700px;
    */
    background-color: rgba(255, 255, 255, .05);
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    padding: 40px;
    border-radius: 10px;
    box-shadow: 0 0 5px #000;
    text-align: center;
    font-family: "微軟雅黑";
    color: #fff;
  }

  /*表單標(biāo)題樣式*/
  .form h1 {
    margin-top: 0;
    font-weight: 200;
  }

  .form .txtb {
    border: 1px solid #aaa;
    margin: 8px 0;
    padding: 12px 18px;
    border-radius: 10px;
  }

  .txtb label {
    display: block;
    text-align: left;
    color: #fff;
    font-size: 14px;
  }

  /*輸入框樣式*/
  .txtb input, .txtb textarea {
    width: 100%;
    background: none;
    border: none;
    outline: none;
    margin-top: 6px;
    font-size: 18px;
    color: #fff;
  }

  /*備注框樣式*/
  .txtb textarea {
    max-height: 300px;
  }

  /*提交按鈕樣式*/
  .btn {
    display: block;
    /* background-color:rgba(156,39,176,.5);
    */
    padding: 14px 0;
    color: #fff;
    cursor: pointer;
    margin-top: 8px;
    width: 100%;
    border: 1px solid #aaa;
    border-radius: 10px;
  }
</style>
<body>
<div class="form">
  <form action="add.do" method="post">
    <h1>用戶信息添加</h1>
    <div class="txtb">
      <label for="">用戶名:</label>
      <input type="text" placeholder="請輸入用戶名" name="username"
             th:value="${userInfo.username}"></div>
    <div class="txtb">
      <label for="">密碼:</label>
      <input type="text" placeholder="請輸入密碼" name="password"
             th:value="${userInfo.password}"></div>
    <div class="txtb">
      <label for="">學(xué)校:</label>
      <input type="text" placeholder="請輸入學(xué)校" name="school"
             th:value="${userInfo.school}">
    </div>

    <div class="txtb">
      <label for="">備注:</label>
      <textarea name="shit" id=""></textarea>
    </div>
    <input type="submit" value="提 交" class="btn" style="color: #E91E63">
  </form>
</div>
</body>
</html>

AddUserServlet:

/**
 * 向User表中添加數(shù)據(jù)
 */
@WebServlet("/add.do")
public class AddUserServlet extends ViewBaseServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        String school = req.getParameter("school");
        UserDAO userDAO = new UserDAO();
        userDAO.addUserNoId(username, password, school);
        resp.sendRedirect("showuser");
    }
}

4.刪除用戶

DelServlet:

/**
 * 根據(jù)ID刪除用戶
 */
@WebServlet("/del.do")
public class DelServlet extends ViewBaseServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int id = Integer.parseInt(req.getParameter("id"));
        UserDAO userDAO = new UserDAO();
        userDAO.delUser(id);
        resp.sendRedirect("showuser");
    }
}

5.修改用戶

edit.html:

<!-- user表編輯頁面 -->
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>用戶編輯頁面</title>
</head>
<style>
    * {
        margin: 0;
        padding: 0;
    }

    /*漸變背景樣式*/
    body {
        height: 100vh;
        width: 100%;
        overflow: hidden;
        background-image: linear-gradient(125deg, #F44336, #E91E63, #9C27B0, #3F51B5, #2196F3);
        background-size: 400%;
        font-family: "montserrat";
        animation: bganimation 15s infinite;
    }

    @keyframes bganimation {
        0% {
            background-position: 0% 50%;
        }
        50% {
            background-position: 100% 50%;
        }
        100% {
            background-position: 0% 50%;
        }
    }

    /*表單樣式*/
    .form {
        width: 85%;
        max-width: 600px;
        /* max-height:700px;
        */
        background-color: rgba(255, 255, 255, .05);
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        padding: 40px;
        border-radius: 10px;
        box-shadow: 0 0 5px #000;
        text-align: center;
        font-family: "微軟雅黑";
        color: #fff;
    }

    /*表單標(biāo)題樣式*/
    .form h1 {
        margin-top: 0;
        font-weight: 200;
    }

    .form .txtb {
        border: 1px solid #aaa;
        margin: 8px 0;
        padding: 12px 18px;
        border-radius: 10px;
    }

    .txtb label {
        display: block;
        text-align: left;
        color: #fff;
        font-size: 14px;
    }

    /*輸入框樣式*/
    .txtb input, .txtb textarea {
        width: 100%;
        background: none;
        border: none;
        outline: none;
        margin-top: 6px;
        font-size: 18px;
        color: #fff;
    }

    /*備注框樣式*/
    .txtb textarea {
        max-height: 300px;
    }

    /*提交按鈕樣式*/
    .btn {
        display: block;
        /* background-color:rgba(156,39,176,.5);
        */
        padding: 14px 0;
        color: #fff;
        cursor: pointer;
        margin-top: 8px;
        width: 100%;
        border: 1px solid #aaa;
        border-radius: 10px;
    }
</style>
<body>
<div class="form">
    <form th:action="@{/update.do}" method="post">
        <h1>用戶信息修改</h1>
        <!--隱藏傳遞用戶ID信息,使用隱藏域-->
        <input type="hidden" name="id" th:value="${userInfo.id}">
        <div class="txtb">
            <label for="">用戶名:</label>
            <input type="text" placeholder="請輸入用戶名" name="username"
                   th:value="${userInfo.username}"></div>
        <div class="txtb">
            <label for="">密碼:</label>
            <input type="text" placeholder="請輸入密碼" name="password"
                   th:value="${userInfo.password}"></div>
        <div class="txtb">
            <label for="">學(xué)校:</label>
            <input type="text" placeholder="請輸入學(xué)校" name="school"
                   th:value="${userInfo.school}">
        </div>

        <div class="txtb">
            <label for="">備注:</label>
            <textarea name="shit" id=""></textarea>
        </div>
        <input type="submit" value="提 交" class="btn" style="color: #E91E63">
    </form>
</div>
</body>
</html>

EditServlet:

/**
 * 編輯user表中的數(shù)據(jù)
 */
@WebServlet("/edit.do")
public class EditServlet extends ViewBaseServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String uidStr = req.getParameter("uid");
        if (uidStr != null && !"".equals(uidStr)) {
            int uid = Integer.parseInt(uidStr);
            UserDAO userDAO = new UserDAO();
            User user = userDAO.getUserById(uid);
            // 保存到request作用域
            req.setAttribute("userInfo", user);
            super.processTemplate("edit", req, resp);
        }
    }
}

6.界面展示

展示用戶列表:(此頁面支持分頁,模糊查詢,修改,刪除,添加)??

Javaweb項目案例:一個簡單的用戶管理系統(tǒng)實現(xiàn)

用戶信息修改:(用戶信息添加類似)??

Javaweb項目案例:一個簡單的用戶管理系統(tǒng)實現(xiàn)文章來源地址http://www.zghlxwxcb.cn/news/detail-489144.html

到了這里,關(guān)于Javaweb項目案例:一個簡單的用戶管理系統(tǒng)實現(xiàn)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進(jìn)行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • JavaWeb綜合案例——商品后臺管理系統(tǒng)

    JavaWeb綜合案例——商品后臺管理系統(tǒng)

    目錄 1.功能介紹 2.工程準(zhǔn)備 2.1pom.xml 2.2mybatis-config.xml 2.3SqlSessionFactoryUtils 2.4CheckCodeUtil 3.注冊頁面 3.1User 3.2UserMapper.xml 3.3UserMapper 3.4UserService 3.5register.html 3.6RegisterServlet 3.7CheckCodeServlet 4.登錄頁面 4.1login.html 4.2LoginServlet 4.3LoginFilter 5.后臺主頁面 5.1Brand 5.2BrandMapper 5.3BrandMapper.xml

    2024年02月07日
    瀏覽(16)
  • 一個簡單的vue項目之圖書管理系統(tǒng),自用,無ui,持續(xù)更新...

    一個簡單的vue項目之圖書管理系統(tǒng),自用,無ui,持續(xù)更新...

    由于自己上一把忘記寫log導(dǎo)致不小心把我的前端項目刪了 重新隨便寫點log記錄一下 由于各種版本不適配問題,請大家謹(jǐn)慎 看攻略 參考。 另外,由于博主主要還是寫后端,所以對ui并沒有加以處理,進(jìn)階就不需要參考了!但是博主還是很樂于學(xué)習(xí)的,如果有什么好的意見和建

    2024年02月06日
    瀏覽(97)
  • SpringBoot小項目——簡單的小區(qū)物業(yè)后臺管理系統(tǒng) & 認(rèn)證鑒權(quán) 用戶-角色模型 & AOP切面日志 & 全局異?!驹创a】

    SpringBoot小項目——簡單的小區(qū)物業(yè)后臺管理系統(tǒng) & 認(rèn)證鑒權(quán) 用戶-角色模型 & AOP切面日志 & 全局異?!驹创a】

    基于SpringBoot的簡單的小區(qū)物業(yè)后臺管理系統(tǒng),主要功能有報修的處理,樓宇信息和房屋信息的管理,業(yè)主信息的管理【核心】,以及數(shù)據(jù)統(tǒng)計分析模塊Echarts繪圖;此外采用用戶-角色權(quán)限模型,結(jié)合自定義注解實現(xiàn)簡單的權(quán)限管理功能,采用aop切面實現(xiàn)日志的存儲,全局異常

    2024年02月06日
    瀏覽(14)
  • JavaWeb:(練習(xí))十二、簡單的學(xué)生管理系統(tǒng)

    JavaWeb:(練習(xí))十二、簡單的學(xué)生管理系統(tǒng)

    ? 基于練習(xí)八、練習(xí)九、練習(xí)十、練習(xí)十一的逐步練習(xí)基礎(chǔ)上,實現(xiàn)了一個簡單的學(xué)生管理系統(tǒng)。 ? 練習(xí)八鏈接:JavaWeb:(練習(xí))八、Servlet前端發(fā)送數(shù)據(jù)到后端練習(xí) ? 練習(xí)九鏈接:JavaWeb:(練習(xí))九、Servlet數(shù)據(jù)交互、XMLHttpRequest、JSON、AJAX、AXIOS練習(xí) ? 練習(xí)十鏈接:J

    2024年02月09日
    瀏覽(22)
  • JavaWeb階段案例--簡易版管理圖書系統(tǒng)(增刪改查)

    JavaWeb階段案例--簡易版管理圖書系統(tǒng)(增刪改查)

    ? 在WEB-INF下創(chuàng)建一個lib包,并導(dǎo)入以下jar包:(導(dǎo)入后,鼠標(biāo)右鍵選中l(wèi)ib文件夾,單擊“add as lib...” ?注:使用Lombok包時,除了需要導(dǎo)入jar包還需要從idea中下載Lombok插件 file -- setting -- plugins -- 搜Lombok -- 勾選上 -- Apply -- OK file -- setting -- Build Exec.....? -- Compiler -- Annotation Pro

    2024年02月08日
    瀏覽(18)
  • 【新手級】JavaWeb用戶管理系統(tǒng)—使用JSP, Servlet, JDBC, MySQL

    【新手級】JavaWeb用戶管理系統(tǒng)—使用JSP, Servlet, JDBC, MySQL

    這是我學(xué)完JavaWeb后做的期末大作業(yè),是一個用戶管理系統(tǒng),包括登錄注冊功能,對于列表的增、刪、改、查功能,由于我也是參考的網(wǎng)上大佬的的代碼,之后進(jìn)行了一些修改,完成的這個新手項目,于是我也把這個項目源碼放在這里供大家參考,同時也對這次學(xué)習(xí)做一個記錄

    2024年02月07日
    瀏覽(32)
  • JavaWeb期末項目 圖書館管理系統(tǒng)

    JavaWeb期末項目 圖書館管理系統(tǒng)

    1 項目基本信息 1.1 項目名稱 圖書館管理系統(tǒng) 1.2 開發(fā)運行環(huán)境 Window 10 64位 JDK 1.8.0 Eclipse 4.8版本 MySql 5.5 Tomcat 9.0 2 項目需求分析 2.1 學(xué)生登錄部分 (1)學(xué)生注冊:在進(jìn)入圖書館前必須要登錄,如果沒有學(xué)號則要注冊,注冊時系統(tǒng)會將用戶填寫的學(xué)號與數(shù)據(jù)庫里面的數(shù)據(jù)對比,

    2024年02月10日
    瀏覽(31)
  • JAVAWEB學(xué)生信息管理系統(tǒng)保姆級教程(增刪改查+<普通用戶和管理員>登錄注冊+Filter+mysql+批量刪除信息+用戶退出登錄注銷)eclipse版(升級版)

    JAVAWEB學(xué)生信息管理系統(tǒng)保姆級教程(增刪改查+<普通用戶和管理員>登錄注冊+Filter+mysql+批量刪除信息+用戶退出登錄注銷)eclipse版(升級版)

    該項目源碼地址: 源碼地址請點擊這里喲! ????????AdminBean.java ? ? ? ?對數(shù)據(jù)庫里的用戶名的表的數(shù)據(jù)進(jìn)行封裝。 ????????StudentBean.java ????????對數(shù)據(jù)庫里的學(xué)生信息的表的數(shù)據(jù)進(jìn)行封裝。 ????????AdminDao.java ? ? ? ? 實現(xiàn)登錄和注冊的方法。 ????????

    2024年02月08日
    瀏覽(26)
  • JavaWeb項目:航班信息管理系統(tǒng)(tomcat+jsp)

    JavaWeb項目:航班信息管理系統(tǒng)(tomcat+jsp)

    航班信息管理系統(tǒng)是學(xué)習(xí)Javaweb的一個小項目,首先對該項目的業(yè)務(wù)需求進(jìn)行分析,根據(jù)項目文檔知它的主要實現(xiàn)技術(shù)為 SERVLET、JSP、MVC 架構(gòu)、JDBC 和 MySQL。該項目著重學(xué)生的實際應(yīng)用場景來設(shè)計,模擬 機場中的航班系統(tǒng)的業(yè)務(wù)實現(xiàn)以及擴展,能夠?qū)崿F(xiàn)航班信息管理的的所有功

    2024年04月12日
    瀏覽(21)
  • 超適合練手的一套JavaWeb項目 (超市后臺管理系統(tǒng))

    超適合練手的一套JavaWeb項目 (超市后臺管理系統(tǒng))

    1.搭建一個maven web項目 2.配置Tomcat 3.測試項目是否能夠跑起來 4.導(dǎo)入項目中遇到的jar包 5.創(chuàng)建項目結(jié)構(gòu) 1.數(shù)據(jù)庫配置文件 db.properties文件代碼 2.編寫數(shù)據(jù)庫的公共類 java代碼 3.編寫字符編碼過濾器 xml代碼 java dao層接口代碼 java dao接口的實現(xiàn)類代碼 java service接口代碼

    2024年02月05日
    瀏覽(22)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包