老师,我的拿不到数据
BookDao
BookServiceImpl
BookService
BookDao.xml
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
正在回答 回答被采纳积分+1
- 参与学习 人
- 提交作业 205 份
- 解答问题 4317 个
Java中非常实用的SSM整合开发内容,从Spring开始,到MyBaits的进阶内容,再到SpringMVC的应用,最后是SSM整合开发案例,逐步深入,助你成长为一名Java工程师!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星