后台-分类管理

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";
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容