Java spring应用中如何压缩(减轻重量)图像

Java spring应用中如何压缩(减轻重量)图像,java,spring,spring-mvc,spring-boot,Java,Spring,Spring Mvc,Spring Boot,我有一个基于WebSpring引导的应用程序,用户可以上传图像,问题是图像大小都有3或4MB。有没有办法压缩这些图像,这样我就可以像大多数web应用程序一样将图像压缩到50或80KB。我将图像保存在文件系统中,而不是数据库中。这里是我应用程序中与图像上传相关的重要部分 add.jsp: <div class="col-md-3 "> <springform:input type="file" path="photos" name="photos" style="

我有一个基于WebSpring引导的应用程序,用户可以上传图像,问题是图像大小都有3或4MB。有没有办法压缩这些图像,这样我就可以像大多数web应用程序一样将图像压缩到50或80KB。我将图像保存在文件系统中,而不是数据库中。这里是我应用程序中与图像上传相关的重要部分

add.jsp:

<div class="col-md-3 ">
      <springform:input  type="file"  path="photos" name="photos" style=" visibility:  hidden ; " onchange="imagepreview(this);"/>
       <label for="photos" >
         <img class="images img-thumbnail"  id="imgpreview" src="/imagetemp/?chemintemp=${chemintemp}"  onError="this.onerror=null;this.src='/images/noimage.gif';" />  
       </label> 
     </div>
控制器:

@RequestMapping(value="/imagetemp",method = RequestMethod.GET)
    public @ResponseBody void affichimagetemp(//@RequestParam("chemintemp") String img,
            Model md, HttpSession session,
            HttpServletResponse response,
            HttpServletRequest request) throws IOException,
            NullPointerException

    {
        String img=(String) session.getAttribute("chemintemp");
        if (img!=null){

            try {
                System.out.println("img /imagetemp :"+img);
                File imageFile = new File(img);
                response.setContentType("image/jpeg");
                InputStream in=new FileInputStream(imageFile);
                IOUtils.copy(in, response.getOutputStream());
                in.close();
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

           }

    }
这似乎相关:这似乎相关:
@RequestMapping(value="/imagetemp",method = RequestMethod.GET)
    public @ResponseBody void affichimagetemp(//@RequestParam("chemintemp") String img,
            Model md, HttpSession session,
            HttpServletResponse response,
            HttpServletRequest request) throws IOException,
            NullPointerException

    {
        String img=(String) session.getAttribute("chemintemp");
        if (img!=null){

            try {
                System.out.println("img /imagetemp :"+img);
                File imageFile = new File(img);
                response.setContentType("image/jpeg");
                InputStream in=new FileInputStream(imageFile);
                IOUtils.copy(in, response.getOutputStream());
                in.close();
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

           }

    }