1.CategoryServlet.list()
List<Category> cs = categoryDAO.list(page.getStart(),page.getCount()) ;
int total = categoryDAO.getTotal();
page.setTotal(total);
request.setAttribute("thecs",cs);
request.setAttribute("page",page);
return "admin/listCategory.jsp";
2.分页Page
3.增加分类CategoryServlet.add()
Map<String,String> params = new HashMap<>();
InputStream is = super.parseUpload(request, params);
String name= params.get("name");
Category c = new Category();
c.setName(name);
categoryDAO.add(c);
File imageFolder= new File(request.getSession().getServletContext().getRealPath("img/category"));
File file = new File(imageFolder,c.getId()+".jpg");
try {
if(null!=is && 0!=is.available()){
try(FileOutputStream fos = new FileOutputStream(file)){
byte b[] = new byte[1024 * 1024];
int length = 0;
while (-1 != (length = is.read(b))) {
fos.write(b, 0, length);
}
fos.flush();
//通过如下代码,把文件保存为jpg格式
BufferedImage img = ImageUtil.change2jpg(file);
ImageIO.write(img, "jpg", file);
}
catch(Exception e){
e.printStackTrace();
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "@admin_category_list";