当前位置:   article > 正文

JavaWeb期末大作业 Javaweb项目 Javaweb Servlet html_javaweb期末大作业简单项目

javaweb期末大作业简单项目

1.前端效果展示

1.进入之后是一个分页查询所有数据的内容  该页面有基础的增删改查  还有分页查询  批量删除

 进行条件查询  有什么不对的地方欢迎提出  谢谢

 2.增删改查

1.添加

添加成功

2.删除  将刚才添加的OPPO删除

3.修改 

 

 4.查询的话就是主页查询所有  页面所用的是分页查询+查询所有

2.数据库设计

1.使用navicat 或者用idea自带的数据库进行设计即可

 2.注意数据库中varchar 设计为utf8

3.后台逻辑

1.后台结构

 2.增删改查方法

1.查询所有

protected void findAll(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{
    List<Brand> brand = brandService.selectAll();
    String s = JSON.toJSONString(brand);

    resp.getWriter().write(s);
}

2.修改

protected void update(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String line = req.getReader().readLine();
    Brand brand = JSON.parseObject(line, Brand.class);
    int row = brandService.update(brand);
    if(row>0){
        resp.getWriter().write("true");
    }
    else {
        resp.getWriter().write("false");
    }
}

3.添加

protected void add(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String line = req.getReader().readLine();
    Brand brand = JSON.parseObject(line, Brand.class);
    int row = brandService.insert(brand);
    if(row>0){
        resp.getWriter().write("true");
    }
    else {
        resp.getWriter().write("false");
    }
}

4.删除

protected void delete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String id=req.getParameter("id");
    int row = brandService.deleteBrand(Integer.parseInt(id));
    if(row>0){
        resp.getWriter().write("true");
    }else {
        resp.getWriter().write("false");
    }

}

5.批量删除   从前端获得要删除的id数组 在进行对id数组的查询  去进行删除

protected void deleteById(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String s = req.getReader().readLine();
    int[] ints = JSON.parseObject(s, int[].class);
    int row = brandService.delete(ints);
    //响应删除成功的标识
    if(row>0){
        resp.getWriter().write("true");
    }else {
        resp.getWriter().write("false");
    }
}

6.分页查询

protected void findByPage(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    Integer currentPage = Integer.parseInt(req.getParameter("currentPage"));
    Integer pageSize = Integer.parseInt(req.getParameter("pageSize"));
    PageInfo<Brand> pb = brandService.selectByPage(currentPage, pageSize);
    String s = JSON.toJSONString(pb);
    resp.getWriter().write(s);

}

7.分页查询带条件查询

protected void findByPageAndCondition(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    Integer currentPage = Integer.parseInt(req.getParameter("currentPage"));
    Integer pageSize = Integer.parseInt(req.getParameter("pageSize"));
    String line = req.getReader().readLine();
    Brand brand = JSON.parseObject(line, Brand.class);
    PageInfo<Brand> pb = brandService.findByPageCondition(currentPage, pageSize,brand);
    String s = JSON.toJSONString(pb);
    resp.getWriter().write(s);
}

3.总结

   上面给的是web层总的方法   dao层和service太简单了  就不一一书写了  dao层就是写各种方法 上面的 然后查询语句 service层就是调用dao层的方法  web层再调用service的方法.

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/神奇cpp/article/detail/757529
推荐阅读
相关标签
  

闽ICP备14008679号