首页
关于
留言
归档
更多
邻居
Search
1
宝塔面板出现乱码
6,734 阅读
2
小浣熊CMS5.0漫画系统安装教程和采集教程
3,986 阅读
3
vfed 大橙子模板使用教程
3,580 阅读
4
YGbook 搭建完首页 不显示小说
2,841 阅读
5
Linux 搬瓦工 VPS一键安装桌面环境和RDP远程桌面连接
2,553 阅读
技术文章
网站源码
网站模板
资源分享
主机测评
登录
Search
标签搜索
苹果
Nginx
搜狗图床
小浣熊CMS
面板
狂雨cms采集规则
Ubuntu
Mysql8.0
百度文库
Java
word导出
jeecg-boot
苹果cms
excel 样式
美团对接
文言一心
阿里
Typecho
累计撰写
46
篇文章
累计收到
13
条评论
首页
栏目
技术文章
网站源码
网站模板
资源分享
主机测评
页面
关于
留言
归档
邻居
搜索到
33
篇与
的结果
2023-04-25
Java 微信公众号网页开发相关 code登录 获取用户信息 openId
Java 微信公众号网页开发相关用户关注公众号点击链接 后端根据code换取asstoken 需要公众号后台配置配置域名https://open.weixin.qq.com/connect/oauth2/authorize?appid= APPID &redirect_uri= URL 打开的页面 &response_type=code&scope=snsapi_userinfo&state=2#wechat_redirect 后台需要get接口 获取code 进行操作 获取asstoken public JSONObject getToken(String code) { // 使用前端code获取手机号码 参数为json格式 String url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid="+appid+"&secret="+secret+"&code=" + code+"&grant_type=authorization_code"; Map<String, String> paramMap = new HashMap<>(); ResponseEntity<String> response = restTemplate.getForEntity(url, String.class, paramMap); System.out.println("response"+response); log.info("response={}",response); JSONObject object=JSONObject.parseObject(response.getBody()); return object; }...根据accessToken 换取用户头像和昵称 获取用户信息 public JSONObject getWxUserInfo(String openId,String accessToken) { String url = "https://api.weixin.qq.com/sns/userinfo?access_token="+accessToken+"&openid="+openId+"&lang=zh_CN"; Map<String, String> paramMap = new HashMap<>(); restTemplate.getMessageConverters().set(1,new StringHttpMessageConverter(StandardCharsets.UTF_8)); ResponseEntity<String> response = restTemplate.getForEntity(url, String.class, paramMap); System.out.println("response"+response); log.info("response={}",response); JSONObject object=JSONObject.parseObject(response.getBody()); return object; }...
2023年04月25日
132 阅读
0 评论
0 点赞
2023-03-10
美团北极星 洗涤行业对接
美团北极星 洗涤行业对接美团洗衣行业对接 java代码签名不一致 sign值不一致中文乱码导致的 本地测试没问题 线上tomcat有问题需要先去下载java SDK SDK 版本: public static String generateSign(GenerateSignRequest generateSignRequest) { if (generateSignRequest == null) { throw new IllegalArgumentException("generateSign generateSignRequest is null"); } else { Map<String, String> params = generateSignRequest.getParams(); AssertUtils.checkArgument(params != null && !params.isEmpty(), "generateSign apiRequest is null,generateSignRequest:" + generateSignRequest); List<String> keys = new ArrayList(); Iterator var3 = params.entrySet().iterator(); while(var3.hasNext()) { Map.Entry<String, String> entry = (Map.Entry)var3.next(); if (org.apache.commons.lang.StringUtils.isNotEmpty((String)entry.getValue())) { keys.add(entry.getKey()); } } Collections.sort(keys); StringBuilder sb = new StringBuilder(); if (org.apache.commons.lang.StringUtils.isNotEmpty(generateSignRequest.getAppSecret())) { sb.append(generateSignRequest.getAppSecret()); } Iterator var8 = keys.iterator(); String sign; while(var8.hasNext()) { sign = (String)var8.next(); sb.append(sign).append(((String)params.get(sign)).trim()); } if (org.apache.commons.lang.StringUtils.isNotEmpty(generateSignRequest.getAppSecret())) { sb.append(generateSignRequest.getAppSecret()); } String encryptionKey = sb.toString().trim(); if (generateSignRequest.getSignMethod().equals(SignMethodEnum.MD5.getType())) { try { sign =genMd5(encryptionKey); return sign; } catch (Exception var6) { throw new RuntimeException(var6.getMessage()); } } else { return ""; } } } public static String genMd5(String info) throws NoSuchAlgorithmException, UnsupportedEncodingException { MessageDigest md5 = MessageDigest.getInstance("MD5"); byte[] infoBytes = info.getBytes("UTF-8"); md5.update(infoBytes); byte[] sign = md5.digest(); return byteArrayToHex(sign); } public static String byteArrayToHex(byte[] bytes) { StringBuilder sign = new StringBuilder(); for(int i = 0; i < bytes.length; ++i) { String hex = Integer.toHexString(bytes[i] & 255); if (hex.length() == 1) { sign.append("0"); } sign.append(hex.toLowerCase()); } return sign.toString(); } java代码public static String generateSign(Map<String, String> params, String appSecret, String signMethod) { // 第一步:参数排序 List<String> keys = Lists.newArrayList(); for (Map.Entry<String, String> entry : params.entrySet()) { if (StringUtils.isNotEmpty(entry.getValue())) { keys.add(entry.getKey()); } } Collections.sort(keys); // 第二步:把所有参数名和参数值串在一起 StringBuilder sb = new StringBuilder(); if (StringUtils.isNotEmpty(appSecret)) { sb.append(appSecret); } for (String key : keys) { sb.append(key).append(params.get(key).trim()); } if (StringUtils.isNotEmpty(appSecret)) { sb.append(appSecret); } String encryptionKey = sb.toString().trim(); // 第三步:加签 if (signMethod.equals("MD5")) { try { String sign = genMd5(encryptionKey); return sign; } catch (Exception e) { throw new RuntimeException(e.getMessage()); } }else{ //开发者暂不需支持,支持MD5即可 return ""; }}public static String genMd5(String info) throws NoSuchAlgorithmException, UnsupportedEncodingException {MessageDigest md5 = MessageDigest.getInstance("MD5"); byte[] infoBytes = info.getBytes(); md5.update(infoBytes); byte[] sign = md5.digest(); return byteArrayToHex(sign);}public static String byteArrayToHex(byte[] bytes) {StringBuilder sign = new StringBuilder(); for (int i = 0; i < bytes.length; i++) { String hex = Integer.toHexString(bytes[i] & 0xFF); if (hex.length() == 1) { sign.append("0"); } sign.append(hex.toLowerCase()); } return sign.toString();}
2023年03月10日
157 阅读
1 评论
0 点赞
2022-12-28
Hutool操作excel 样式
导出excelhutool-excel-并设置单元格格式为文本/**方法描述: 设置基础字体样式字体 这里保留最基础的样式使用*@param workbook 工作簿@param bold 是否粗体@param fontName 字体名称@param fontSize 字体大小@return org.apache.poi.ss.usermodel.Font@author wqf@date 2021/5/19 15:58*/public static Font setBaseFont(Workbook workbook, boolean bold, boolean italic, String fontName, int fontSize) {Font font = workbook.createFont();//设置字体名称 宋体 / 微软雅黑 /等font.setFontName(fontName);//设置是否斜体font.setItalic(italic);//设置字体高度//font.setFontHeight((short) fontHeight);//设置字体大小 以磅为单位font.setFontHeightInPoints((short) fontSize);//设置是否加粗font.setBold(bold);//默认字体颜色// font.setColor(Font.COLOR_NORMAL);//红色//font.setColor(Font.COLOR_RED);//设置下划线样式//font.setUnderline(Font.ANSI_CHARSET);//设定文字删除线//font.setStrikeout(true);return font;}全局样式设置private static StyleSet GlobalStyleSet(ExcelWriter writer, Workbook workbook,Font font) {//全局样式设置StyleSet styleSet = writer.getStyleSet();CellStyle cellStyle = styleSet.getCellStyle();//设置全局文本居中styleSet.setAlign(HorizontalAlignment.CENTER, VerticalAlignment.CENTER);//设置全局字体样式styleSet.setFont(font);//设置背景颜色 第二个参数表示是否将样式应用到头部styleSet.setBackgroundColor(IndexedColors.WHITE, true);//设置自动换行 当文本长于单元格宽度是否换行styleSet.setWrapText();// 设置全局边框样式styleSet.setBorder(BorderStyle.THIN, IndexedColors.BLACK);return styleSet;}头部标题样式//设置全局样式StyleSet styleSet = GlobalStyleSet(writer, workbook);//设置头部标题样式CellStyle headCellStyle = styleSet.getHeadCellStyle();//水平居中headCellStyle.setAlignment(HorizontalAlignment.CENTER);//垂直居中headCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);//设置字体样式headCellStyle.setFont(setBaseFont(workbook, true, false, "宋体", 12));writer.setStyleSet(styleSet);数字保留小数例:保留两位小数CellStyle cellStyleForNumber = styleSet.getCellStyleForNumber();cellStyleForNumber.setDataFormat((short)2);5.时间格式化例如格式为:YYYY/MM/dd 格式CellStyle cellStyleForDate = styleSet.getCellStyleForDate();//14 代表的时间格式是 yyyy/MM/ddcellStyleForDate.setDataFormat((short)14);时间格式占时只看到这一种格式常见些,像yyyy-MM-dd 格式都没找到,就只有在写入数据写先处理下时间格式了。行(Row)样式//获取输出构造器 设置工作簿名称ExcelWriter writer = ExcelUtil.getWriterWithSheet(sheetName);Workbook workbook = writer.getWorkbook();Sheet sheet = writer.getSheet();Row row = sheet.getRow(rowIndex);if(sheet.getRow(rowIndex )==null){//rowIndex 表示的是第几行,例:创建第二行,rowIndex=1sheet.createRow(rowIndex );}//创建样式CellStyle cellStyle = workbook.createCellStyle();cellStyle .setVerticalAlignment(VerticalAlignment.CENTER);cellStyle .setAlignment(HorizontalAlignment.LEFT);cellStyle .setFont(setBaseFont(workbook, true, false, "宋体", 12));cellStyle .setBorderBottom(BorderStyle.THIN);cellStyle .setBorderLeft(BorderStyle.THIN);cellStyle .setBorderRight(BorderStyle.THIN);cellStyle .setBorderTop(BorderStyle.THIN);//应用样式到某一行(row .setRowStyle(cellStyle );//应用样式到某一行 (或者这样写) rowIndex 表示的是第几行//writer.setRowStyle(rowIndex ,cellStyle );单元格(Cell)样式Row row = sheet.getRow(rowIndex);if(sheet.getRow(rowIndex )==null){//rowIndex 表示的是第几行,例:创建第二行,rowIndex=1sheet.createRow(rowIndex );}//创建本行的第几个单元格 cellIndex=0 表示第一个if(row.get(cellIndex)==null){row .createCell(cellIndex);}//创建样式CellStyle cellStyle = workbook.createCellStyle();cellStyle .setVerticalAlignment(VerticalAlignment.CENTER);cellStyle .setAlignment(HorizontalAlignment.LEFT);cellStyle .setFont(setBaseFont(workbook, true, false, "宋体", 12));cellStyle .setBorderBottom(BorderStyle.THIN);cellStyle .setBorderLeft(BorderStyle.THIN);cellStyle .setBorderRight(BorderStyle.THIN);cellStyle .setBorderTop(BorderStyle.THIN);//应用样式到某一行(row .setRowStyle(cellStyle );//应用样式到某一行 (或者这样写) rowIndex 表示的是第几行//writer.setRowStyle(rowIndex ,cellStyle );合并单元格//处理标题行 合并某行的单元格,并写入对象到单元格,如果写到单元格中的内容非null,行号自动+1,否则当前行号不变//主要有两种方式writer.merge(cellIndex, content, true);表示当前行 合并从第一个单元到cellIndex+1个单元,并填充内容content,第三个参数表示是否将头部标题样式应用到这里。或者2.writer.merge(startRowIndex,endRowIndex, startCellIndex, endCellIndex, content, false);表示和并第startRowIndex+1行到endRowIndex+1行 ,并合并从第endCellIndex+1个单元到endCellIndex+1个单元格,并填充content内容,最后一个字段表示是否将头部标题样式应用到这里。列表别名//LinkedHashMap 中的数据是根据put先后顺序来的,HashMap数据时无序的。//使用方法 writer.setHeaderAlias(headerAlias); 时如果使用HashMap 可能展示的数//据顺序会错乱Map<String, String> headerAlias = new LinkedHashMap<>();headerAlias.put(字段名1, 列名1);headerAlias.put(字段名2, 列名2);headerAlias.put(字段名3, 列名3);headerAlias.put(字段名4, 列名4);headerAlias.put(字段名5, 列名5);writer.setHeaderAlias(headerAlias);//或者一项一项设置列的别名 列别名顺序会跟代码中addHeaderAlias顺序一致writer.addHeaderAlias(字段名1,列名1);writer.addHeaderAlias(字段名2,列名2);列宽问题8.1 自动列宽 百度查到一个方法有用 ,但实际好像还是会有点问题,大家可以先试试博客链接 :https://blog.csdn.net/kongbai953/article/details/110382544/**自适应宽度(中文支持)@param sheet@param size 因为for循环从0开始,size值为 列数-1*/public static void setSizeColumn(Sheet sheet, int size) {for (int columnNum = 0; columnNum <= size; columnNum++) {int columnWidth = sheet.getColumnWidth(columnNum) / 256;for (int rowNum = 0; rowNum <= sheet.getLastRowNum(); rowNum++) {Row currentRow;//当前行未被使用过if (sheet.getRow(rowNum) == null) {currentRow = sheet.createRow(rowNum);} else {currentRow = sheet.getRow(rowNum);}if (currentRow.getCell(columnNum) != null) {Cell currentCell = currentRow.getCell(columnNum);if (currentCell.getCellType() == XSSFCell.CELL_TYPE_STRING) {int length = currentCell.getStringCellValue().getBytes().length;if (columnWidth < length) {columnWidth = length;}}}}sheet.setColumnWidth(columnNum, columnWidth * 256);}}8.2 手动列宽设置//表示 第一列的列宽是15writer.setColumnWidth(0, 15);另外常用方法//跳过当前行 即当前行不写内容writer.passCurrentRow();//定位到最后一行,常用于在末尾追加数据writer.setCurrentRowToEnd();10 . 下载excel代码 在数据都填充完成后,调用该方法即可/**方法描述: 下载excel文件*@param response 响应@param fileName 文件名称@param writer writer@return void@author wqf@date 2021/5/24 16:20*/private static void downloadExcel(HttpServletResponse response, String fileName, ExcelWriter writer) {response.setContentType("application/vnd.ms-excel;charset=utf-8");// test.xls是弹出下载对话框的文件名,不能为中文,中文请自行编码ServletOutputStream out = null;try {// 设置请求头属性response.setHeader("Content-Disposition", "attachment;filename=" + new String((fileName + ".xlsx").getBytes(), StandardCharsets.ISO_8859_1));out = response.getOutputStream();// 写出到文件writer.flush(out, true);// 关闭writer,释放内存writer.close();// 此处记得关闭输出Servlet流IoUtil.close(out);} catch (IOException e) {log.error(e.getMessage());e.printStackTrace();}}excel 添加下拉框CellRangeAddressList addressList = new CellRangeAddressList(2, 2, 5, 5);DataValidationHelper helper = sheet.getDataValidationHelper();// 设置下拉框数据String[] str = new String[]{"男", "女","阴阳人"};DataValidationConstraint constraint = helper.createExplicitListConstraint(str);DataValidation dataValidation = helper.createValidation(constraint, addressList);writer.addValidationData(dataValidation);12.背景色填充//示例:将单元格背景填充为黄色short index = IndexedColors.YELLOW.index;cellStyle.setFillForegroundColor(index);cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);总结 : 整合了一个工具类,仅作参考/**@Author: wqf@Date: 2021/05/28@Description: hutool 工具导出excel(非填充模板,手工画)*/@Slf4jpublic class HutoolExcelUtil {/**YYYY/MM/dd 时间格式*/private static final short LOCAL_DATE_FORMAT_SLASH = 14;/**方法描述: 创建excel*@param isXlsx excel文件类型 true-xlsx/false-xls@return cn.hutool.poi.excel.ExcelWriter@author wqf@date 2021/6/1 9:47*/public static ExcelWriter createExcel(boolean isXlsx) {return ExcelUtil.getWriter(isXlsx);}/**方法描述: 全局基础样式设置默认 全局水平居中+垂直居中默认 自动换行默认单元格边框颜色为黑色,细线条默认背景颜色为白色*@param writer writer@param font 字体样式@return cn.hutool.poi.excel.StyleSet@author wqf@date 2021/5/28 10:43*/public static StyleSet setBaseGlobalStyle(ExcelWriter writer, Font font) {//全局样式设置StyleSet styleSet = writer.getStyleSet();//设置全局文本居中styleSet.setAlign(HorizontalAlignment.CENTER, VerticalAlignment.CENTER);//设置全局字体样式styleSet.setFont(font, true);//设置背景颜色 第二个参数表示是否将样式应用到头部styleSet.setBackgroundColor(IndexedColors.WHITE, true);//设置自动换行 当文本长于单元格宽度是否换行//styleSet.setWrapText();// 设置全局边框样式styleSet.setBorder(BorderStyle.THIN, IndexedColors.BLACK);return styleSet;}/**方法描述: 设置标题的基础样式*@param styleSet StyleSet@param font 字体样式@param horizontalAlignment 水平排列方式@param verticalAlignment 垂直排列方式@return org.apache.poi.ss.usermodel.CellStyle@author wqf@date 2021/5/28 10:16*/public static CellStyle createHeadCellStyle(StyleSet styleSet, Font font,HorizontalAlignment horizontalAlignment,VerticalAlignment verticalAlignment) {CellStyle headCellStyle = styleSet.getHeadCellStyle();headCellStyle.setAlignment(horizontalAlignment);headCellStyle.setVerticalAlignment(verticalAlignment);headCellStyle.setFont(font);return headCellStyle;}/**方法描述: 设置基础字体样式字体 这里保留最基础的样式使用*@param bold 是否粗体@param fontName 字体名称@param fontSize 字体大小@return org.apache.poi.ss.usermodel.Font@author wqf@date 2021/5/19 15:58*/public static Font createFont(ExcelWriter writer, boolean bold, boolean italic, String fontName, int fontSize) {Font font = writer.getWorkbook().createFont();//设置字体名称 宋体 / 微软雅黑 /等font.setFontName(fontName);//设置是否斜体font.setItalic(italic);//设置字体大小 以磅为单位font.setFontHeightInPoints((short) fontSize);//设置是否加粗font.setBold(bold);return font;}/**方法描述: 设置行或单元格基本样式*@param writer writer@param font 字体样式@param verticalAlignment 垂直居中@param horizontalAlignment 水平居中@return void@author wqf@date 2021/5/28 10:28*/public static CellStyle createCellStyle(ExcelWriter writer, Font font, boolean wrapText,VerticalAlignment verticalAlignment,HorizontalAlignment horizontalAlignment) {CellStyle cellStyle = writer.getWorkbook().createCellStyle();cellStyle.setVerticalAlignment(verticalAlignment);cellStyle.setAlignment(horizontalAlignment);cellStyle.setWrapText(wrapText);cellStyle.setFont(font);return cellStyle;
2022年12月28日
661 阅读
0 评论
0 点赞
2022-08-11
读取 resources 目录下的文件路径
/**根据文件路径读取文件内容 *@param fileInPath@throws IOException */public static void getFileContent(Object fileInPath) throws IOException {BufferedReader br = null; if (fileInPath == null) { return; } if (fileInPath instanceof String) { br = new BufferedReader(new FileReader(new File((String) fileInPath))); } else if (fileInPath instanceof InputStream) { br = new BufferedReader(new InputStreamReader((InputStream) fileInPath)); } String line; while ((line = br.readLine()) != null) { System.out.println(line); } br.close();}方式一主要核心方法是使用getResource和getPath方法,这里的getResource("")里面是空字符串public void function1(String fileName) throws IOException {String path = this.getClass().getClassLoader().getResource("").getPath();//注意getResource("")里面是空字符串 System.out.println(path); String filePath = path + fileName; System.out.println(filePath); getFileContent(filePath);}方式二主要核心方法是使用getResource和getPath方法,直接通过getResource(fileName)方法获取文件路径,注意如果是路径中带有中文一定要使用URLDecoder.decode解码。/**直接通过文件名getPath来获取路径 *@param fileName@throws IOException */public void function2(String fileName) throws IOException {String path = this.getClass().getClassLoader().getResource(fileName).getPath();//注意getResource("")里面是空字符串 System.out.println(path); String filePath = URLDecoder.decode(path, "UTF-8");//如果路径中带有中文会被URLEncoder,因此这里需要解码 System.out.println(filePath); getFileContent(filePath);}方式三直接通过文件名+getFile()来获取文件。如果是文件路径的话getFile和getPath效果是一样的,如果是URL路径的话getPath是带有参数的路径。如下所示:url.getFile()=/pub/files/foobar.txt?id=123456url.getPath()=/pub/files/foobar.txt使用getFile()方式获取文件的代码如下:/**直接通过文件名+getFile()来获取 *@param fileName@throws IOException */public void function3(String fileName) throws IOException {String path = this.getClass().getClassLoader().getResource(fileName).getFile();//注意getResource("")里面是空字符串 System.out.println(path); String filePath = URLDecoder.decode(path, "UTF-8");//如果路径中带有中文会被URLEncoder,因此这里需要解码 System.out.println(filePath); getFileContent(filePath);}方式四(重要)直接使用getResourceAsStream方法获取流,上面的几种方式都需要获取文件路径,但是在SpringBoot中所有文件都在jar包中,没有一个实际的路径,因此可以使用以下方式。/**直接使用getResourceAsStream方法获取流springboot项目中需要使用此种方法,因为jar包中没有一个实际的路径存放文件 *@param fileName@throws IOException */public void function4(String fileName) throws IOException {InputStream in = this.getClass().getClassLoader().getResourceAsStream(fileName); getFileContent(in);}方式五(重要)主要也是使用getResourceAsStream方法获取流,不使用getClassLoader可以使用getResourceAsStream("/配置测试.txt")直接从resources根路径下获取,SpringBoot中所有文件都在jar包中,没有一个实际的路径,因此可以使用以下方式。/**直接使用getResourceAsStream方法获取流如果不使用getClassLoader,可以使用getResourceAsStream("/配置测试.txt")直接从resources根路径下获取 *@param fileName@throws IOException */public void function5(String fileName) throws IOException {InputStream in = this.getClass().getResourceAsStream("/" + fileName); getFileContent(in);}方式六(重要)通过ClassPathResource类获取文件流,SpringBoot中所有文件都在jar包中,没有一个实际的路径,因此可以使用以下方式。/**通过ClassPathResource类获取,建议SpringBoot中使用springboot项目中需要使用此种方法,因为jar包中没有一个实际的路径存放文件 *@param fileName@throws IOException */public void function6(String fileName) throws IOException {ClassPathResource classPathResource = new ClassPathResource(fileName); InputStream inputStream = classPathResource.getInputStream(); getFileContent(inputStream);}方式七通过绝对路径获取项目中文件的位置,只是本地绝对路径,不能用于服务器获取。/**通过绝对路径获取项目中文件的位置(不能用于服务器)@param fileName@throws IOException */public void function7(String fileName) throws IOException {String rootPath = System.getProperty("user.dir");//E:\WorkSpace\Git\spring-framework-learning-example String filePath = rootPath + "\\chapter-2-springmvc-quickstart\\src\\main\\resources\\"+fileName; getFileContent(filePath);}方式八通过new File("")获取当前的绝对路径,只是本地绝对路径,不能用于服务器获取。/**通过绝对路径获取项目中文件的位置(不能用于服务器)@param fileName@throws IOException */public void function8(String fileName) throws IOException {//参数为空 File directory = new File(""); //规范路径:getCanonicalPath() 方法返回绝对路径,会把 ..\ 、.\ 这样的符号解析掉 String rootCanonicalPath = directory.getCanonicalPath(); //绝对路径:getAbsolutePath() 方法返回文件的绝对路径,如果构造的时候是全路径就直接返回全路径,如果构造时是相对路径,就返回当前目录的路径 + 构造 File 对象时的路径 String rootAbsolutePath =directory.getAbsolutePath(); System.out.println(rootCanonicalPath); System.out.println(rootAbsolutePath); String filePath = rootCanonicalPath + "\\chapter-2-springmvc-quickstart\\src\\main\\resources\\"+fileName; getFileContent(filePath);}方式九主要是通过设置环境变量,将文件放在环境变量中,原理也是通过绝对路径获取。示例中我设置了一个环境变量:TEST_ROOT=E:\WorkSpace\Git\spring-framework-learning-exampleSystem.getenv("TEST_ROOT"); System.getProperty("TEST_ROOT")通过设置环境变量的方式,然后通过绝对路径获取文件/**通过绝对路径获取项目中文件的位置 *@param fileName@throws IOException */public void function9(String fileName) throws IOException {System.setProperty("TEST_ROOT","E:\\WorkSpace\\Git\\spring-framework-learning-example"); //参数为空 String rootPath = System.getProperty("TEST_ROOT"); System.out.println(rootPath); String filePath = rootPath + "\\chapter-2-springmvc-quickstart\\src\\main\\resources\\"+fileName; getFileContent(filePath);}
2022年08月11日
566 阅读
0 评论
0 点赞
2022-03-23
jeecg boot 乐观锁使用
mybatis-plus 乐观锁 当要更新一条记录的时候,希望这条记录没有被别人更新spring boot 注解方式import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor; import org.mybatis.spring.annotation.MapperScan; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; /** * @author Administrator */ @Configuration @MapperScan(value={"org.jeecg.modules.**.mapper*"}) public class MybatisPlusConfig { /** * 新版 */ @Bean public MybatisPlusInterceptor mybatisPlusOptimisticLocking() { MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor(); mybatisPlusInterceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor()); return mybatisPlusInterceptor; } } 在实体类的字段上加上@Version注解@Version private Integer version; 测试: @PostMapping(value = "/getCarouselList11") public Result<?> getCarouselList12() { CompletableFuture<String> a = asyncService.doSomething("我是改的第一个"); CompletableFuture<String> b = asyncService.doSomething("我是改的第二个"); String result=null; CompletableFuture.allOf(a, b).join(); try { result = a.get() + b.get(); } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); } return Result.OK("获取成功",result); }
2022年03月23日
943 阅读
0 评论
0 点赞
1
2
...
7