Commit 40a6d740 by xuwenhao

12.22压缩图片

parent 665fe7f6
package com.qianhe.system.controller;
import com.qianhe.common.annotation.Log;
import com.qianhe.common.annotation.RepeatSubmit;
import com.qianhe.common.core.controller.BaseController;
import com.qianhe.common.core.domain.AjaxResult;
import com.qianhe.common.core.page.TableDataInfo;
......@@ -80,6 +81,7 @@ public class WaterGoodsCartController extends BaseController {
* 新增购物车商品
*/
@PostMapping
@RepeatSubmit(message = "请勿重复操作!")
public AjaxResult add(@RequestBody WaterGoodsCart waterGoodsCart)
{
return toAjax(waterGoodsCartService.insertWaterGoodsCart(waterGoodsCart));
......@@ -107,6 +109,7 @@ public class WaterGoodsCartController extends BaseController {
* 删除购物车商品
*/
@DeleteMapping("/{ids}")
@RepeatSubmit(message = "请勿重复操作!")
public AjaxResult remove(@PathVariable Long[] ids)
{
return toAjax(waterGoodsCartService.deleteWaterGoodsCartByIds(ids));
......@@ -118,6 +121,7 @@ public class WaterGoodsCartController extends BaseController {
* @return
*/
@GetMapping("/getInfo/{ids}")
@RepeatSubmit(message = "请勿重复操作!")
public AjaxResult getWaterGoodsCart(@PathVariable Long[] ids){
//查询全部商品图片
List<WaterGoodsImg> waterGoodsImgList = waterGoodsImgService.selectWaterGoodsImgList(new WaterGoodsImg());
......
package com.qianhe.system.utils;
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.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.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 {
// 设置目标图片保存路径及名称
outputImagePath = profile + outputImagePath.replace("/profile","");
// 创建输入流对象
FileInputStream fis = new FileInputStream(new File(inputImagePath));
// 获取图片信息
BufferedImage image = ImageIO.read(fis);
// 创建输出流对象
FileOutputStream fos = new FileOutputStream(new File(outputImagePath));
// 将图片写入到输出流中并进行压缩处理
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(fos);
encoder.encode(image);
File file = new File(inputImagePath); // 源文件
File outfile = new File(outputImagePath); // 目标输出文件,可与源文件一致,一致会覆盖
PngCompressor.compress(file, outfile);
// 关闭输入、输出流
fis.close();
fos.close();
// // 创建输入流对象
// FileInputStream fis = new FileInputStream(new File(inputImagePath));
//
// // 获取图片信息
// 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