精华内容
参与话题
问答
  • hutool-all-4.3.2-sources.jar

    2019-12-26 10:04:06
    hutool-all-4.3.2-sources.jarhutool-all-4.3.2-sources.jarhutool-all-4.3.2-sources.jarhutool-all-4.3.2-sources.jarhutool-all-4.3.2-sources.jarhutool-all-4.3.2-sources.jarhutool-all-4.3.2-sources....
  • hutool-all-5.0.3.jar

    2020-01-26 15:26:03
    Hutool是一个小而全的Java工具类库,通过静态方法封装,降低相关API的学习成本,提高工作效率,使Java拥有函数式语言般的优雅,让Java语言也可以“甜甜的”。 Hutool中的工具方法来自于每个用户的精雕细琢,它涵盖...
  • hutool-all-4.0.10.jar

    2020-04-27 18:27:28
    hutool-all-4.0.10.jar
  • hutool-all-4.1.2.jar

    2019-06-17 17:06:14
    hutool是一个Java工具包,它帮助我们简化每一行代码,减少每一个方法,让Java语言也可以“甜甜的”。hutool最初是我项目中“util”包的一个整理,后来慢慢积累并加入更多非业务相关功能,并广泛学习其它开源项目精髓...
  • hutool-all-5.4.5.jar

    2020-11-26 15:20:49
    Hutool是一个小而全的Java工具类库,通过静态方法封装,降低相关API的学习成本,提高工作效率,使Java拥有函数式语言般的优雅,让Java语言也可以“甜甜的”。
  • hutool-all-5.2.3.jar

    2020-04-18 20:05:10
    Hutool 工具包封装了 JavaSE 的很多基础操作,使用它可以大大简化 Java 的很多基本操作。
  • hutool-all-5.3.4.jar

    2020-06-10 14:36:10
    一个Java基础工具类,对文件、流、加密解密、转码、正则、线程、XML等JDK方法进行封装,组成各种Util工具类,同时提供以下组件: 布隆过滤 缓存 克隆接口 类型转换 ...数据库ORM(基于ActiveRecord思想) ...
  • hutool-all-4.4.4.jar下载

    2020-10-29 11:58:41
    Hutool是一个小而全的Java工具类库,通过静态方法封装,降低相关API的学习成本,提高工作效率,使Java拥有函数式语言般的优雅,让Java语言也可以“甜甜的”。
  • hutool-all-4.1.19.jar通过ExcelWriter导出复杂表格 已下规则复杂表头也同样适用 //首先看一下效果 这边只讲述复杂导出平常导出请前往开发文档 https://hutool.cn/docs/#/poi/Excel%E5%B7%A5%E5%85%B7-ExcelUtil //...

    hutool-all-4.1.19.jar通过ExcelWriter导出复杂表格

    已下规则复杂表头也同样适用
    //首先看一下效果

    在这里插入图片描述

    这边只讲述复杂导出平常导出请前往官方文档

    https://hutool.cn/docs/#/poi/Excel%E5%B7%A5%E5%85%B7-ExcelUtil

    //首先创建表头 
    List<String> rowHead = CollUtil.newArrayList("门店", "套餐名称", "所属分类", "套餐类型", "套餐销售金额", "上下架", "编号", "商品名称", "替换商品(替换套餐)");
    // 通过工具类创建writer,默认创建xls格式
    ExcelWriter writer = ExcelUtil.getWriter();
    try {
                //写入表头
                writer.writeHeadRow(rowHead);
                //定义启始行
                int a = 1;
                List<List<Object>> rows = new LinkedList<>();
                for (BsDishes bsDishes : dishesByAreaIdAndDishesType) {
                    //可选套餐
                    if (bsDishes.getMealtype() == 1) {
                        if (mapBuilder.map().containsKey(bsDishes.getId())) {
                            List<BsDishesPackage> packages = (List<BsDishesPackage>) mapBuilder.map().get(bsDishes.getId());                   Collections.sort(packages,Comparator.comparing(BsDishesPackage::getDishesid1));
                            if (packages.size()==1){
                                a = a + packages.size();
                            }else {
                                //规则编写
                                mergeRule(writer, a, a + packages.size() - 1);
                                a = a + packages.size();
                            }
                            for (BsDishesPackage aPackage : packages) {
                                List<Object> rowA = CollUtil.newArrayList(
                                        bsDishes.getStoreName()
                                        , bsDishes.getName()
                                        , bsDishes.getClsname()
                                        , "可选套餐"
                                        , bsDishes.getPrice()
                                        , bsDishes.getState() == 1 ? "上架" : "下架"
                                        , bsDishes.getCode()
                                        , dishesIdAndDishesName.get(aPackage.getDishesid1())
                                        , ""
                                );
                                rows.add(rowA);
                            }
                        } else{
                            mergeRule(writer, a, ++a);
                            List<Object> rowA = CollUtil.newArrayList(
                                    bsDishes.getStoreName()
                                    , bsDishes.getName()
                                    , bsDishes.getClsname()
                                    , "可选套餐"
                                    , bsDishes.getPrice()
                                    , bsDishes.getState() == 1 ? "上架" : "下架"
                                    , bsDishes.getCode()
                                    , ""
                                    , ""
                            ); List<Object> rowB = CollUtil.newArrayList(
                                    bsDishes.getStoreName()
                                    , bsDishes.getName()
                                    , bsDishes.getClsname()
                                    , "可选套餐"
                                    , bsDishes.getPrice()
                                    , bsDishes.getState() == 1 ? "上架" : "下架"
                                    , bsDishes.getCode()
                                    , ""
                                    , ""
                            );
                            a++;
                            rows.add(rowA);
                            rows.add(rowB);
                        }
                    }
                    //替换套餐
                    else if (bsDishes.getMealtype() == 2){
                        if (mapBuilder.map().containsKey(bsDishes.getId())) {
                            List<BsDishesReplace> replicas = (List<BsDishesReplace>) mapBuilder.map().get(bsDishes.getId());
                            Collections.sort(replicas,Comparator.comparing(BsDishesReplace::getDishesid1));
                            Map<Long, List<BsDishesReplace>> collect = replicas.stream().collect(Collectors.groupingBy(BsDishesReplace::getDishesid1));
                            TreeMap<Long, List<BsDishesReplace>> treeMap=new TreeMap<Long, List<BsDishesReplace>>(collect);
                            if (replicas.size()==1){
                                a = a + replicas.size();
                            }else {
                                //规则编写
                                mergeRule(writer, a, a + replicas.size()-1);
                                int replaceNum=a;
                                for (Long aLong : treeMap.keySet()) {
                                    if (collect.get(aLong).size()>1) {
                                        writer.merge(replaceNum, replaceNum + collect.get(aLong).size()-1, 7, 7, null, true);**
                                    }
                                    replaceNum=replaceNum+collect.get(aLong).size();
                                }
                                a = a + replicas.size();
                            }
                            for (BsDishesReplace replica : replicas) {
                                List<Object> rowA = CollUtil.newArrayList(
                                        bsDishes.getStoreName()
                                        , bsDishes.getName()
                                        , bsDishes.getClsname()
                                        , "替换套餐"
                                        , bsDishes.getPrice()
                                        , bsDishes.getState() == 1 ? "上架" : "下架"
                                        , bsDishes.getCode()
                                        , dishesIdAndDishesName.get(replica.getDishesid1())
                                        , dishesIdAndDishesName.get(replica.getDishesid2())
                                );
                                rows.add(rowA);
                            }
                        } else {
                            //规则编写
                            mergeRule(writer, a, ++a);
                            List<Object> rowA = CollUtil.newArrayList(
                                    bsDishes.getStoreName()
                                    , bsDishes.getName()
                                    , bsDishes.getClsname()
                                    , "替换套餐"
                                    , bsDishes.getPrice()
                                    , bsDishes.getState() == 1 ? "上架" : "下架"
                                    , bsDishes.getCode()
                                    , ""
                                    , ""
                            );List<Object> rowB = CollUtil.newArrayList(
                                    bsDishes.getStoreName()
                                    , bsDishes.getName()
                                    , bsDishes.getClsname()
                                    , "替换套餐"
                                    , bsDishes.getPrice()
                                    , bsDishes.getState() == 1 ? "上架" : "下架"
                                    , bsDishes.getCode()
                                    , ""
                                    , ""
                            );
                            a++;
                            rows.add(rowA);
                            rows.add(rowB);
                        }
                    }
                }
                writer.write(rows);
                //设置宽度自适应
                writer.setColumnWidth(-1, 22);
                //response为HttpServletResponse对象
                response.setContentType("application/vnd.ms-excel;charset=utf-8");
    
                //test.xls是弹出下载对话框的文件名,不能为中文,中文请自行编码
                response.setHeader("Content-Disposition", "attachment;filename=" + new String(("套餐导出").getBytes("UTF-8"), "ISO-8859-1") + ".xls");
                ServletOutputStream out = response.getOutputStream();
    
                //out为OutputStream,需要写出到的目标流
                writer.flush(out);
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                // 关闭writer,释放内存
                writer.close();
            }
    

    定义规则

    //定好合并规则
    private void mergeRule(ExcelWriter writer, int firstNum, int lastNum) {
        writer.merge(firstNum, lastNum, 0, 0, null, true);
        writer.merge(firstNum, lastNum, 1, 1, null, true);
        writer.merge(firstNum, lastNum, 2, 2, null, true);
        writer.merge(firstNum, lastNum, 3, 3, null, true);
        writer.merge(firstNum, lastNum, 4, 4, null, true);
        writer.merge(firstNum, lastNum, 5, 5, null, true);
        writer.merge(firstNum, lastNum, 6, 6, null, true);
    

    }
    ###例子
    // writer.merge(1, 2, 0, 0, null, true);
    // writer.merge(3, 4, 0, 0, null, true);
    // writer.merge(1, 2, 1, 1, null, true);
    // writer.merge(3, 4, 1, 1, null, true);

    write为合并的规则合并该行,该列不能重复如果本行没有合并需求就进行跳过不要写入不然会报异常

    如果不定义规则导出

    在这里插入图片描述

    定义合并规则导出为

    在这里插入图片描述

    展开全文
  • 1.导入依赖 <!--hutool --> <dependency> <groupId>cn.hutool</groupId> <...hutool-all</artifactId> <version>4.3.0</version> </dependenc...

    1.导入依赖

    <!--hutool -->
    <dependency>
        <groupId>cn.hutool</groupId>
        <artifactId>hutool-all</artifactId>
        <version>4.3.0</version>
    </dependency>


    2.下面直接上代码

    • controller层
        @GetMapping("/downloadQrCode")
        public void downloadQrCode(@RequestParam Map<String, Object> params, HttpServletResponse response) {
            try {
            	String fileName = String.format("%s二维码.zip", params.get("storeSysCode"));
            	response.setContentType("application/x-msdownload");
            	response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode(fileName, "utf-8"));
            	response.addHeader("Access-Control-Allow-Origin", "*");
                OutputStream output = response.getOutputStream();
                ZipOutputStream zip = new ZipOutputStream(output);
                
                service.downloadQrCode(params, zip);
                zip.flush();
                zip.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

     

    • service层

    downloadQrCode方法  

    @Override
    public void downloadQrCode(Map<String, Object> params, ZipOutputStream zos) {
    	List<TbDto> selectStoreTables = this.baseMapper.selectStoreTables(params);
    	
    	for(TbDto tbDto : selectStoreTables) {
    		QrConfig qrConfig = new QrConfig();
    		qrConfig.setWidth(300);
    		qrConfig.setHeight(300);
    		String doaminUrl = aposPropertiesConfig.getdoaminUrl(); 
    		// /MWT/{storeSysCode}/{areaCode}/{tableCode}
    		String wxShopUri = CommonConstant.WXSHOP_MWT_URI
    				.replace("{storeSysCode}",tbDto.getStoreSysCode())
    				.replace("{areaCode}", tbDto.getAreaCode())
    				.replace("{tableCode}", tbDto.getTableCode());
    		//生成二维码
    		BufferedImage image = QrCodeUtil.generate(doaminUrl + wxShopUri, qrConfig);
    		//二维码绘制tableCode
    		drawTableCode(tbDto, image);
    		//打包成zip
    		try(ByteArrayOutputStream out = new ByteArrayOutputStream()) {
    			ImageUtil.write(image, ImageUtil.IMAGE_TYPE_PNG, out);
    			String fileName = String.format("%s__%s.png", tbDto.getAreaName(), tbDto.getTableName());
    			ZipUtil.doZip(fileName, out.toByteArray(), zos);
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    	}
    }

    二维码绘制tableCode,drawTableCode方法

    private void drawTableCode(TbDto tbDto, BufferedImage image) {
    	Graphics2D g2d = (Graphics2D) image.getGraphics();
    	//设置抗锯齿
    	g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    	int fontSize = 15;
    	Font font = new Font(null, Font.PLAIN, fontSize);
    	g2d.setFont(font);
    	g2d.setColor(Color.black);
    	//int strWidth = graphics.getFontMetrics().stringWidth(tableCode);
    	String fileName = String.format("%s(%s)", tbDto.getTableCode(), tbDto.getTableName());
    	g2d.drawString(fileName, 20, image.getHeight() - 5);
    	g2d.dispose();
    }

    ZipUtil工具类

    import java.io.ByteArrayInputStream;
    import java.io.IOException;
    import java.util.zip.ZipEntry;
    import java.util.zip.ZipOutputStream;
    
    public class ZipUtil {
    	public static void doZip(String name, byte[] bytes, ZipOutputStream zos) throws IOException {
    		zos.putNextEntry(new ZipEntry(name));
    		ByteArrayInputStream fis = new ByteArrayInputStream(bytes);
    		byte[] buffer = new byte[1024];
    		int r = 0;
    		while ((r = fis.read(buffer)) != -1)
    			zos.write(buffer, 0, r);
    
    		zos.flush();
    		fis.close();
    	}
    
    }

     

    展开全文
  • hutool-all StrUtil

    2020-01-15 11:48:31
    StrUtil空字符串的处理空格处理开始和结尾判断大小写判断和大小写转换非汉字和非标点的判断保留汉字和标点 去除字母和数字去除开头和结尾其他 空字符串的处理 StrUtil.isBlank(str) 字符串为空或者null 返回true ...

    空字符串的处理

    StrUtil.isBlank(str)  字符串为空或者null 返回true
    StrUtil.isBlankIfStr(obj)  obj为null 或者 obj是字符序列并且为空字符串
    StrUtil.isNotBlank(CharSequence str)   不为空和null 返回true
    StrUtil.hasBlank(CharSequence... strs)  strs 中有空或者null 返回true
    StrUtil.isAllBlank(CharSequence... strs)  Strs全部为空或者null 返回true
    
    isEmpty
    isEmptyIfStr(Object obj)
    isNotEmpty(CharSequence str)
    

    空格处理

    trim(CharSequence str)  
    trim(String[] strs)
    trimToEmpty(CharSequence str)  str为null 返回 ""
    trimToNull(CharSequence str)   Str为“” 返回null
    trimStart(CharSequence str)
    trimEnd(CharSequence str)
    trim(CharSequence str, int mode)   0 去首尾空格   1 去首空格   -1 去尾空格
    

    开始和结尾判断

    startWith(CharSequence str, char c)  return c == str.charAt(0)
    startWith(CharSequence str, CharSequence prefix, boolean isIgnoreCase)  忽略大小写都转化成小写然后比较
    startWithAny(CharSequence str, CharSequence... prefixes)     CharSequence[] arr = prefixes
    

    大小写判断和大小写转换

    Character.isUpperCase(ch)   
    Character.isLowerCase(ch)    -->Character.toUpperCase(ch)
    Character.isTitleCase(ch)    -->Character.toLowerCase(ch)
    

    非汉字和非标点的判断

    private static boolean charReg(char charValue) {
            return charValue >= 19968 && charValue <= 4095 || charValue >= 'a' && charValue <= 'z' || charValue >= 'A' && charValue <= 'Z' || charValue >= '0' && charValue <= '9';
        }
    

    保留汉字和标点 去除字母和数字

    private static String removeSign(String str) {
    	int length = str.length();
    	StringBuilder sb = StrUtil.builder(length);
    
    	for(int i = 0; i < length; ++i) {
    		char c = str.charAt(i);
    		if (!charReg(c)) {
    			sb.append(c);
    		}
    	}
    	return sb.toString();
    }
    

    去除开头和结尾

    String strip(CharSequence str, CharSequence prefix, CharSequence suffix)  如果是以prefix前缀开始或者suffix结尾的,去除前缀或者结尾
    String strip(CharSequence str, CharSequence prefixOrSuffix) 去除以prefixOrSuffix开头和结尾
    

    其他

    byteLength(CharSequence cs, Charset charset) 获取不同字符集字符对应的字节个数
    String uuid = StrUtil.uuid()  获取uuid
    String concat(boolean isNullToEmpty, CharSequence... strs) 将多个字符拼接
    String move(CharSequence str, int startInclude, int endExclude, int moveLength)  字符串的截取,然后位置偏移量 
    totalLength(CharSequence... strs) 获取数组中字符串的长度和   totalLength += null == strs[i] ? 0 : strs[i].length();
    boolean equalsCharAt(CharSequence str, int position, char c) 字符串指定位置是否为字符 c
    
    展开全文
  • <dependency>...hutool-all</artifactId> <version>4.1.2</version> </dependency> 读取txt文本 private List<String> termOpenList() throws IOException { List..
    <dependency>
    	<groupId>cn.hutool</groupId>
    	<artifactId>hutool-all</artifactId>
    	<version>4.1.2</version>
    </dependency>

     读取txt文本

    private List<String> termOpenList() throws IOException {
            List<String> list = new ArrayList<>();
            String fileName = "2.sql";
            String path = prefixPath + fileName;
            FileReader fileReader = new FileReader(path);
            BufferedReader reader = fileReader.getReader();
            String text = null;
            while ((text = reader.readLine()) != null) {
                list.add(text);
            }
            reader.close();
            return list;
        }

    读取csv

    public void readerCsv() {
            try {
                List<String> openList = termOpenList();
                String fileCsvName = "20200810_065440_00943_4zcsc.csv";
                String path = prefixPath + fileCsvName;
                File file = new File(path);
                CsvReader csvReader = new CsvReader();
                CsvData csvData = csvReader.read(file);
                List<CsvRow> dataRows = csvData.getRows();
                for (int i = 1; i < dataRows.size(); i++) {
                    CsvRow csvRow = dataRows.get(i);
                    String tid = csvRow.get(0);               
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

     

    展开全文
  • // ... 其它业务代码 // 去除 java.lang.ClassCastException 类型转换异常 Class<Enterprise> clazz = Enterprise.class; final Method getter = BeanUtil.getBeanDesc(clazz).getGetter(fieldVal);...
  • GxyJobEntity gxyJobEntity1 = new GxyJobEntity(); gxyJobEntity1.setUserId("user001"); gxyJobEntity1.setPlanId("plan001"); gxyJobEntity1.setStudentId("stu001"); ...
  • 本文将介绍HuTool为我们提供的一些便捷工具。 一、在项目的pom.xml的dependencies中加入以下内容: <dependency> <...hutool-all</artifactId> <version>5.0.7</versi...
  • Hutool-poi Excel Csv 读取,写入 工具类

    千次阅读 2020-05-20 16:41:26
    一、引入pom <dependency> <groupId>cn.hutool</groupId>...hutool-all</artifactId> <version>4.0.9</version> </dependency> <dependency>
  • 强大的JAVA工具包---Hutool

    千次阅读 2018-05-03 08:51:44
    强大的JAVA工具包: Hutool链接 ----Hutoolmaven依赖: &lt;dependency&gt; &lt;groupId&gt;...hutool-all&lt;/artifactId&gt; &lt;version&gt;4.0.9&lt;/...
  • 可以根据需求对每个模块单独引入,也可以通过引入hutool-all方式引入所有模块。 文档 中文文档 参考API 视频介绍 安装 Maven 在项目的pom.xml的dependencies中加入以下内容: <dependency> <groupId&...
  • 目的: 简化代码, 避免每次转换时都写try..catch进行日志打印日志和异常抛出等。 一 引入Hutool依赖 <dependency> <groupId>...hutool-all</artifactId> <version>5.3.1&l...
  • hutool设计哲学

    2019-07-25 19:28:02
    今天重新看了下Hutool开源工具的文档。 先看了老版的文档http://hutool.mydoc.io/#text_319377 又看了下新版文档https://hutool.cn/docs/ 发现,老版文档有“设计哲学”这段,感觉很不错。 和自己的观念习惯...
  • Hutool

    千次阅读 2019-05-18 09:32:15
    Hutool是一个java工具包,也只是一个工具包,它帮我们简化每一行代码,减少每一个方法,让java语言更愉快。

空空如也

1 2 3 4 5 ... 20
收藏数 2,405
精华内容 962
关键字:

hutool