如何使用ajax在java中找到数据库中的学生列表?

时间:2018-06-12 05:29:50

标签: javascript java mysql json ajax

我有一个项目,我使用DAO / ajax / servlet / hibernate和mysql。我用javascript编写了一个动态表,显示了每个操作的结果:删除,添加,更新,搜索 这是我的代码:

<table id="allStudent" class="table table-bordered">
                <thead>
                <tr>
                    <th>FirstName</th>
                    <th>LastName</th>
                    <th>studentCode</th>
                    <th>Major</th>
                    <th>FatherName</th>
                    <th>id</th>
                    <th>Action</th>
                </tr>
                </thead>
                <tbody id="tmplBody">
                    <script id="scriptTmp">

                    <tr id="deleteTr" >

                        <td>
                            ${firstName}

                        <td>
                            ${lastName}
                        </td>
                        <td>
                            ${studentCode}
                        </td>
                        <td>
                            ${major}
                        </td>
                        <td>
                            ${fatherName}
                        </td>
                         <td>
                            ${id}
                        </td>
                        <td>

                            <button id="updateStudent" class="btn btn-success"><i class="fa fa-pencil" style="padding-right: 10px;"></i>
                                Update
                            </button>

                            <a href="#" type="button"  class="btn btn-danger deletebtn" role="button" onclick="deleteSt(${id})"><i class="fa fa-trash" style="padding-right: 10px;"></i>
                                Delete
                            </a>
                            <button  class="btn btn-info" role="button"><i class="fa fa-check" style="padding-right: 10px;"></i>Course
                                Selection
                            </button>
                        </td>
                    </tr>

                    </script>
                </tbody>


            </table>

        </div>

在servlet中我有findAll()来显示所有学生。我还有一个ajax:

  protected void findAll(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    PrintWriter out = resp.getWriter();
    ArrayList<Student> list = service.GetAll();
    json = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(list);
    out.print(json);
}

我不知道如何在搜索框中搜索用户的所有内容....互联网使用春天的例子但我现在不想使用它。请帮助

0 个答案:

没有答案