Commit 40a6d740 by xuwenhao

12.22压缩图片

parent 665fe7f6
package com.qianhe.system.controller; package com.qianhe.system.controller;
import com.qianhe.common.annotation.Log; import com.qianhe.common.annotation.Log;
import com.qianhe.common.annotation.RepeatSubmit;
import com.qianhe.common.core.controller.BaseController; import com.qianhe.common.core.controller.BaseController;
import com.qianhe.common.core.domain.AjaxResult; import com.qianhe.common.core.domain.AjaxResult;
import com.qianhe.common.core.page.TableDataInfo; import com.qianhe.common.core.page.TableDataInfo;
...@@ -80,6 +81,7 @@ public class WaterGoodsCartController extends BaseController { ...@@ -80,6 +81,7 @@ public class WaterGoodsCartController extends BaseController {
* 新增购物车商品 * 新增购物车商品
*/ */
@PostMapping @PostMapping
@RepeatSubmit(message = "请勿重复操作!")
public AjaxResult add(@RequestBody WaterGoodsCart waterGoodsCart) public AjaxResult add(@RequestBody WaterGoodsCart waterGoodsCart)
{ {
return toAjax(waterGoodsCartService.insertWaterGoodsCart(waterGoodsCart)); return toAjax(waterGoodsCartService.insertWaterGoodsCart(waterGoodsCart));
...@@ -107,6 +109,7 @@ public class WaterGoodsCartController extends BaseController { ...@@ -107,6 +109,7 @@ public class WaterGoodsCartController extends BaseController {
* 删除购物车商品 * 删除购物车商品
*/ */
@DeleteMapping("/{ids}") @DeleteMapping("/{ids}")
@RepeatSubmit(message = "请勿重复操作!")
public AjaxResult remove(@PathVariable Long[] ids) public AjaxResult remove(@PathVariable Long[] ids)
{ {
return toAjax(waterGoodsCartService.deleteWaterGoodsCartByIds(ids)); return toAjax(waterGoodsCartService.deleteWaterGoodsCartByIds(ids));
...@@ -118,6 +121,7 @@ public class WaterGoodsCartController extends BaseController { ...@@ -118,6 +121,7 @@ public class WaterGoodsCartController extends BaseController {
* @return * @return
*/ */
@GetMapping("/getInfo/{ids}") @GetMapping("/getInfo/{ids}")
@RepeatSubmit(message = "请勿重复操作!")
public AjaxResult getWaterGoodsCart(@PathVariable Long[] ids){ public AjaxResult getWaterGoodsCart(@PathVariable Long[] ids){
//查询全部商品图片 //查询全部商品图片
List<WaterGoodsImg> waterGoodsImgList = waterGoodsImgService.selectWaterGoodsImgList(new WaterGoodsImg()); List<WaterGoodsImg> waterGoodsImgList = waterGoodsImgService.selectWaterGoodsImgList(new WaterGoodsImg());
......
package com.qianhe.system.utils; package com.qianhe.system.utils;
import com.idrsolutions.image.png.PngCompressor; import com.idrsolutions.image.png.PngCompressor;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.imageio.*;
import javax.imageio.metadata.IIOMetadata;
import javax.imageio.stream.FileImageInputStream;
import javax.imageio.stream.FileImageOutputStream;
import javax.imageio.stream.ImageInputStream;
import javax.imageio.stream.ImageOutputStream;
import java.awt.image.BufferedImage;
import java.io.*; import java.io.*;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Random;
import java.util.zip.GZIPOutputStream;
import static com.qianhe.common.utils.file.MimeTypeUtils.IMAGE_PNG;
/** /**
* 图片压缩工具 * 图片压缩工具
...@@ -42,22 +27,26 @@ public class ImageThumbnailsUtil { ...@@ -42,22 +27,26 @@ public class ImageThumbnailsUtil {
// 设置目标图片保存路径及名称 // 设置目标图片保存路径及名称
outputImagePath = profile + outputImagePath.replace("/profile",""); outputImagePath = profile + outputImagePath.replace("/profile","");
// 创建输入流对象 File file = new File(inputImagePath); // 源文件
FileInputStream fis = new FileInputStream(new File(inputImagePath)); File outfile = new File(outputImagePath); // 目标输出文件,可与源文件一致,一致会覆盖
PngCompressor.compress(file, outfile);
// 获取图片信息
BufferedImage image = ImageIO.read(fis);
// 创建输出流对象
FileOutputStream fos = new FileOutputStream(new File(outputImagePath));
// 将图片写入到输出流中并进行压缩处理
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(fos);
encoder.encode(image);
// 关闭输入、输出流 // // 创建输入流对象
fis.close(); // FileInputStream fis = new FileInputStream(new File(inputImagePath));
fos.close(); //
// // 获取图片信息
// BufferedImage image = ImageIO.read(fis);
//
// // 创建输出流对象
// FileOutputStream fos = new FileOutputStream(new File(outputImagePath));
//
// // 将图片写入到输出流中并进行压缩处理
// JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(fos);
// encoder.encode(image);
//
// // 关闭输入、输出流
// fis.close();
// fos.close();
} }
/*** /***
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment