苍穹外卖V2

821 字
4 分钟
苍穹外卖V2

Spring-Cache#

Spring 封装 redis 的配置。

Spring-cache常用注解
Spring-cache常用注解

cacheput注解#

语法格式

// 基本语法示例(会在cachename后面加上'::')
@Cacheput(cacheNames = "userCache",key=
匹配名字:"#name.id"
固定result:#result.id"
index底标:#a0.id/#p0.id
#root.args[0].id(麻烦)

cacheable 注解#

语法格式

// 基本语法示例(会在cachename后面加上'::')
@Cacheput(cacheNames = "userCache",key= "#id")//key的生成

作用:调用方法前查看是否缓存,若有直接返回缓存

CacheEvict#

语法格式

// 基本语法示例
1、(同able)
2、(……,allentries=true)//cachename的全删

微信支付逻辑(跳过)#

语法格式

// 基本语法示例

示例

// 代码示例

Spring-Task#

概念:spring 提供的定时任务 语法格式

// 基本语法示例
cron表达:( 0 0 9 12 10 ? 2022)
对应(秒分时 日月 周 年)

注解:

  • @EnableScheduling
  • @Scheduled (cron = “0 * * * * ?”)

Websocket#

概念:一次链接就可以全双工通信的 TCP 工具 作用:实时更新 特点: 工作流:websocket 前端代码——导入依赖——导入组件——配置类编写——配合定时任务执行

poi#

概念:excel 创建 示例

// 代码示例
public static void write() throws Exception {
// 1. 创建工作簿、工作表
XSSFWorkbook excel = new XSSFWorkbook();
XSSFSheet sheet = excel.createSheet("info");
// 2. 表头行(第1行,下标1)
XSSFRow row1 = sheet.createRow(1);
row1.createCell(1).setCellValue("姓名");
row1.createCell(2).setCellValue("城市");
// 3. 数据行
XSSFRow row2 = sheet.createRow(2);
row2.createCell(1).setCellValue("张三");
row2.createCell(2).setCellValue("北京");
XSSFRow row3 = sheet.createRow(3);
row3.createCell(1).setCellValue("李四");
row3.createCell(2).setCellValue("南京");
// 4. 输出到文件
FileOutputStream out = new FileOutputStream(new File("D:\\info.xlsx"));
excel.write(out); // 原代码缺失此行,必报错!
out.close();
excel.close();
}

读取的示例:

public static void read() throws Exception {
// 1. 读取文件流、工作簿、工作表
FileInputStream in = new FileInputStream(new File("D:\\info.xlsx"));
XSSFWorkbook excel = new XSSFWorkbook(in);
XSSFSheet sheet = excel.getSheetAt(0);
// 2. 遍历所有行
int lastRow = sheet.getLastRowNum();
for (int i = 1; i <= lastRow; i++) {
XSSFRow row = sheet.getRow(i);
String name = row.getCell(1).getStringCellValue();
String city = row.getCell(2).getStringCellValue();
System.out.println(name + " " + city);
}
// 3. 关闭资源
in.close();
excel.close();
}

拓展

// ========== 拓展1:Sheet工作表高频操作 ==========
public static void sheetOperateDemo(XSSFWorkbook excel) {
// 根据表名获取sheet
XSSFSheet sheet = excel.getSheet("info");
// 获取真实有数据总行数
int realRowCount = sheet.getPhysicalNumberOfRows();
// 设置固定列宽 / 自动适配列宽
sheet.setColumnWidth(1, 15 * 256);
sheet.autoSizeColumn(2);
// 删除指定行
XSSFRow delRow = sheet.getRow(2);
sheet.removeRow(delRow);
}
// ========== 拓展2:Row行高频操作 ==========
public static void rowOperateDemo(XSSFSheet sheet) {
XSSFRow row = sheet.getRow(2);
// 获取当前行最后一列下标
int lastCellIndex = row.getLastCellNum();
// 获取当前行有效单元格数量
int realCellCount = row.getPhysicalNumberOfCells();
// 动态遍历本行所有单元格
for (int c = 0; c < lastCellIndex; c++) {
XSSFCell cell = row.getCell(c);
}
}
// ========== 拓展3:Cell单元格通用工具(解决类型转换报错) ==========
public static String getCellValue(XSSFCell cell) {
if (cell == null) return "";
return switch (cell.getCellType()) {
case STRING -> cell.getStringCellValue();
case NUMERIC -> String.valueOf(cell.getNumericCellValue());
case BOOLEAN -> String.valueOf(cell.getBooleanCellValue());
case FORMULA -> cell.getCellFormula();
default -> "";
};
}
// 单元格写入数字/布尔/公式示例
public static void cellWriteDemo(XSSFRow row) {
XSSFCell cell = row.createCell(3);
cell.setCellValue(99.9);
cell.setCellValue(true);
cell.setCellFormula("SUM(B2:B10)");
}
// ========== 拓展4:单元格样式、字体设置 ==========
public static void cellStyleDemo(XSSFWorkbook excel, XSSFRow row) {
// 创建字体
XSSFFont font = excel.createFont();
font.setBold(true);
font.setFontHeightInPoints(12);
font.setColor(IndexedColors.RED.getIndex());
// 创建样式
XSSFCellStyle style = excel.createCellStyle();
style.setFont(font);
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
// 绑定样式到单元格
XSSFCell cell = row.createCell(1);
cell.setCellValue("带样式表头");
cell.setCellStyle(style);
}
// ========== 拓展5:try-with-resources 自动关闭流(无手动close) ==========
public static void autoCloseResourceDemo() throws Exception {
try (FileOutputStream out = new FileOutputStream("D:\\info.xlsx");
XSSFWorkbook excel = new XSSFWorkbook()) {
XSSFSheet sheet = excel.createSheet("info");
sheet.createRow(0).createCell(0).setCellValue("测试自动关闭流");
excel.write(out);
}
}

八股:#


  • LocalDate = 纯日期(2026-07-02)
  • LocalDateTime = 日期 + 时刻(2026-07-02 14:30:22)

支持与分享

如果这篇文章对你有帮助,欢迎分享给更多人或赞助支持!

赞助
苍穹外卖V2
https://firefly.cuteleaf.cn/posts/编程学习/后端项目/苍穹外卖v2/
作者
伊月酱
发布于
2026-06-18
许可协议
CC BY-NC-SA 4.0
Profile Image of the Author
Firefly
Hello, I'm Firefly.
公告
欢迎来到我的博客!这是一则示例公告。
音乐
封面

音乐

暂未播放

0:00 0:00
暂无歌词
分类
标签
站点统计
文章
28
分类
10
标签
49
总字数
28,946
运行时长
0
最后活动
0 天前

文章目录