zoukankan      html  css  js  c++  java
  • controller之间跳转 重定向

    如 添加 删除完成之后要还有进行查询

      @RequestMapping("/findAll.html")
        public ModelAndView findAll() {
            ModelAndView mv = new ModelAndView();
            List<Product> pList = productService.findAll();
            mv.addObject("pList", pList);
            mv.setViewName("product");
            return mv;
        }
    
        @RequestMapping("/add.do")
        public String add(HttpServletRequest request, MultipartFile upFile, Product product) throws IOException {
            // String filename = upFile.getName(); // 表单控件的name属性
            String filename = upFile.getOriginalFilename();
            // 通过文件名得到后缀名
            int index = filename.lastIndexOf("."); // 获取最后一个点的索引
            String ext = filename.substring(index);
    
            // 因为图片可能存在重名的问题,因此需要使用随机算法生成随机字符串
            filename = UUIDUtil.getUUID() + ext;
            String imgurl = "static/images/products/" + filename;
            // 如何获取项目的根目录?项目对象使用ServletContext对象来表示
            // 返回项目所在路径
            String realPath = request.getSession().getServletContext().getRealPath("");
            filename = realPath + imgurl;
            System.out.println(filename);
            File file = new File(filename);
            upFile.transferTo(file);
            // 将图片路径imgurl放到product对象中
            product.setImgurl(imgurl);
            productService.add(product);
            // 重新查询列表数据
          //  奇迹
            return "redirect:/product/findAll.html";
        }
    
    不停的思考,就会不停的进步
  • 相关阅读:
    codeforces C. No to Palindromes!
    codeforces D. Pashmak and Parmida's problem
    codeforces C. Little Pony and Expected Maximum
    codeforces D. Count Good Substrings
    codeforces C. Jzzhu and Chocolate
    codeforces C. DZY Loves Sequences
    codeforces D. Multiplication Table
    codeforces C. Painting Fence
    hdu 5067 Harry And Dig Machine
    POJ 1159 Palindrome
  • 原文地址:https://www.cnblogs.com/zhenqk/p/13551463.html
Copyright © 2011-2022 走看看