老师,我的拿不到数据

老师,我的拿不到数据

BookDao

http://img1.sycdn.imooc.com//climg/5d6fb7a000018f0105510404.jpg

BookServiceImpl

http://img1.sycdn.imooc.com//climg/5d6fb7d90001816a06490685.jpg

BookService

http://img1.sycdn.imooc.com//climg/5d6fb7f00001ce8804800420.jpg

BookDao.xml

http://img1.sycdn.imooc.com//climg/5d6fb82b00016acf12340852.jpg

BookController

@Controller("bookController")
public class BookController {
   @Autowired
   private BookService bookService;

   public void list(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       List<Book> list = bookService.getAll();
       request.setAttribute("LIST",list);
       request.getRequestDispatcher("../category.jsp").forward(request,response);
   }

   public void toAdd(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       List<Book> list = bookService.getAll();
       request.setAttribute("DLIST",list);
       request.getRequestDispatcher("../staff_add.jsp").forward(request,response);
   }
   public void add(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, IOException {
       Integer categoryId = Integer.valueOf(request.getParameter("categoryId"));
       String name = request.getParameter("name");
       Integer level = Integer.valueOf(request.getParameter("level"));
       Integer price = Integer.valueOf(request.getParameter("price"));
       String imgPath = request.getParameter("imgPath");
       Date createTime = null;
       Date updateTime = null;
       try {
           createTime = new SimpleDateFormat("yyyy-MM-dd").parse(request.getParameter("createTime"));
           updateTime = new SimpleDateFormat("yyyy-MM-dd").parse(request.getParameter("updateTime"));
       } catch (ParseException e) {
           e.printStackTrace();
       }

       Book book = new Book();
       book.setCategoryId(categoryId);
       book.setName(name);
       book.setLevel(level);
       book.setPrice(price);
       book.setImgPath(imgPath);
       book.setCreateTime(createTime);
       book.setUpdateTime(updateTime);
       bookService.add(book);
       response.sendRedirect("list.do");
   }

   public void toEdit(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       Integer id = Integer.parseInt(request.getParameter("id"));
       Book book = bookService.get(id);
       request.setAttribute("OBJ",book);
       List<Book> list = bookService.getAll();
       request.setAttribute("DLIST",list);
       request.getRequestDispatcher("../staff_edit.jsp").forward(request,response);
   }
   public void edit(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       Integer id = Integer.parseInt(request.getParameter("id"));
       Integer categoryId = Integer.valueOf(request.getParameter("categoryId"));
       String name = request.getParameter("name");
       Integer level = Integer.valueOf(request.getParameter("level"));
       Integer price = Integer.valueOf(request.getParameter("price"));
       String imgPath = request.getParameter("imgPath");
       Date createTime = null;
       Date updateTime = null;
       try {
           createTime = new SimpleDateFormat("yyyy-MM-dd").parse(request.getParameter("createTime"));
           updateTime = new SimpleDateFormat("yyyy-MM-dd").parse(request.getParameter("updateTime"));
       } catch (ParseException e) {
           e.printStackTrace();
       }

       Book book = bookService.get(id);
       book.setCategoryId(categoryId);
       book.setName(name);
       book.setLevel(level);
       book.setPrice(price);
       book.setImgPath(imgPath);
       book.setCreateTime(createTime);
       book.setUpdateTime(updateTime);

       bookService.edit(book);
       response.sendRedirect("list.do");
   }
   public void remove(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       Integer id = Integer.parseInt(request.getParameter("id"));
       bookService.remove(id);
       response.sendRedirect("list.do");
   }

   public void detail(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       Integer id = Integer.parseInt(request.getParameter("id"));
       Book book = bookService.get(id);
       request.setAttribute("OBJ",book);
       request.getRequestDispatcher("../staff_detail.jsp").forward(request,response);
   }
}


category.jsp

http://img1.sycdn.imooc.com//climg/5d6fb88e00016d2410880624.jpg

正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

2回答
好帮手慕阿满 2019-09-05 11:01:13

同学你好,首先先确定数据库中有数据,select * from book可以在数据库中可以查询到数据,然后在list()方法中获取数据后,输出一下,如:

http://img1.sycdn.imooc.com//climg/5d707a340001b8c307940239.jpg

重启项目,查看控制台是否有输出,如果有,则表示显示数据时有问题,如果没有,则是查询数据时有问题,再根据结果查看具体出现问题的原因。

如果有报错,请将报错信息贴一下。

祝:学习愉快~

好帮手慕阿满 2019-09-05 09:43:12

同学你好,同学说的拿不到数据是指什么呢?无法获取数据库的数据?还是无法添加数据,建议同学描述清楚。

祝:学习愉快~

  • 提问者 慕标6095225 #1
    老师,是拿不到数据库的数据
    2019-09-05 10:05:01
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
SSM主流框架入门与综合项目实战2018版
  • 参与学习           人
  • 提交作业       205    份
  • 解答问题       4317    个

Java中非常实用的SSM整合开发内容,从Spring开始,到MyBaits的进阶内容,再到SpringMVC的应用,最后是SSM整合开发案例,逐步深入,助你成长为一名Java工程师!

了解课程
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师