1.前端效果展示
1.進(jìn)入之后是一個(gè)分頁(yè)查詢所有數(shù)據(jù)的內(nèi)容? 該頁(yè)面有基礎(chǔ)的增刪改查? 還有分頁(yè)查詢? 批量刪除
?進(jìn)行條件查詢? 有什么不對(duì)的地方歡迎提出? 謝謝
?2.增刪改查
1.添加
添加成功
2.刪除? 將剛才添加的OPPO刪除
3.修改?
?
?4.查詢的話就是主頁(yè)查詢所有? 頁(yè)面所用的是分頁(yè)查詢+查詢所有
2.數(shù)據(jù)庫(kù)設(shè)計(jì)
1.使用navicat?或者用idea自帶的數(shù)據(jù)庫(kù)進(jìn)行設(shè)計(jì)即可
?2.注意數(shù)據(jù)庫(kù)中varchar?設(shè)計(jì)為utf8
3.后臺(tái)邏輯
1.后臺(tái)結(jié)構(gòu)
?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.批量刪除? ?從前端獲得要?jiǎng)h除的id數(shù)組?在進(jìn)行對(duì)id數(shù)組的查詢? 去進(jìn)行刪除
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); //響應(yīng)刪除成功的標(biāo)識(shí) if(row>0){ resp.getWriter().write("true"); }else { resp.getWriter().write("false"); } }
6.分頁(yè)查詢
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.分頁(yè)查詢帶條件查詢文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-499164.html
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.總結(jié)
? ?上面給的是web層總的方法? ?dao層和service太簡(jiǎn)單了? 就不一一書(shū)寫(xiě)了? dao層就是寫(xiě)各種方法?上面的?然后查詢語(yǔ)句 service層就是調(diào)用dao層的方法? web層再調(diào)用service的方法.文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-499164.html
到了這里,關(guān)于JavaWeb期末大作業(yè) Javaweb項(xiàng)目 Javaweb Servlet html的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!