ai-engineering-init 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/agents/code-reviewer.md +139 -0
- package/.claude/agents/project-manager.md +159 -0
- package/.claude/audio/completed.wav +0 -0
- package/.claude/commands/add-todo.md +255 -0
- package/.claude/commands/check.md +210 -0
- package/.claude/commands/crud.md +454 -0
- package/.claude/commands/dev.md +503 -0
- package/.claude/commands/init-docs.md +681 -0
- package/.claude/commands/next.md +251 -0
- package/.claude/commands/progress.md +242 -0
- package/.claude/commands/start.md +199 -0
- package/.claude/commands/sync.md +307 -0
- package/.claude/commands/update-status.md +428 -0
- package/.claude/docs/Mixin/344/275/277/347/224/250/346/214/207/345/215/227.md +299 -0
- package/.claude/docs/README.md +167 -0
- package/.claude/docs//345/211/215/347/253/257/345/274/200/345/217/221/346/214/207/345/215/227.md +599 -0
- package/.claude/docs//345/220/216/347/253/257/345/274/200/345/217/221/346/214/207/345/215/227.md +726 -0
- package/.claude/docs//345/267/245/344/275/234/346/265/201/345/274/200/345/217/221/346/214/207/345/215/227.md +714 -0
- package/.claude/docs//345/267/245/345/205/267/347/261/273/344/275/277/347/224/250/346/214/207/345/215/227.md +463 -0
- package/.claude/docs//346/225/260/346/215/256/345/272/223/350/256/276/350/256/241/350/247/204/350/214/203.md +390 -0
- package/.claude/docs//346/226/260/345/212/237/350/203/275/345/274/200/345/217/221/346/265/201/347/250/213/350/247/204/350/214/203.md +688 -0
- package/.claude/docs//346/226/260/351/241/271/347/233/256/345/274/200/345/217/221/346/265/201/347/250/213.md +365 -0
- package/.claude/docs//346/241/206/346/236/266/350/257/264/346/230/216.md +393 -0
- package/.claude/docs//350/267/257/347/224/261/351/205/215/347/275/256/346/214/207/345/215/227.md +246 -0
- package/.claude/framework-config.json +73 -0
- package/.claude/hooks/pre-tool-use.js +117 -0
- package/.claude/hooks/skill-forced-eval.js +167 -0
- package/.claude/hooks/stop.js +58 -0
- package/.claude/settings.json +41 -0
- package/.claude/skills/add-skill/SKILL.md +352 -0
- package/.claude/skills/api-development/SKILL.md +560 -0
- package/.claude/skills/architecture-design/SKILL.md +756 -0
- package/.claude/skills/backend-annotations/SKILL.md +674 -0
- package/.claude/skills/banana-image/CHANGELOG.md +37 -0
- package/.claude/skills/banana-image/README.md +146 -0
- package/.claude/skills/banana-image/SKILL.md +164 -0
- package/.claude/skills/banana-image/assets/logo.png +0 -0
- package/.claude/skills/banana-image/references/advanced-usage.md +189 -0
- package/.claude/skills/banana-image/scripts/apply_template.py +125 -0
- package/.claude/skills/banana-image/scripts/banana_image_exec.ts +412 -0
- package/.claude/skills/banana-image/scripts/batch_prep.py +82 -0
- package/.claude/skills/banana-image/scripts/package-lock.json +1437 -0
- package/.claude/skills/banana-image/scripts/package.json +18 -0
- package/.claude/skills/banana-image/scripts/requirements.txt +10 -0
- package/.claude/skills/banana-image/templates/poster.json +22 -0
- package/.claude/skills/banana-image/templates/product.json +17 -0
- package/.claude/skills/banana-image/templates/social.json +22 -0
- package/.claude/skills/banana-image/templates/thumbnail.json +17 -0
- package/.claude/skills/brainstorm/SKILL.md +648 -0
- package/.claude/skills/bug-detective/SKILL.md +1206 -0
- package/.claude/skills/code-patterns/SKILL.md +590 -0
- package/.claude/skills/collaborating-with-codex/SKILL.md +174 -0
- package/.claude/skills/collaborating-with-codex/scripts/codex_bridge.py +275 -0
- package/.claude/skills/collaborating-with-gemini/SKILL.md +194 -0
- package/.claude/skills/collaborating-with-gemini/scripts/gemini_bridge.py +275 -0
- package/.claude/skills/crud-development/SKILL.md +649 -0
- package/.claude/skills/data-permission/SKILL.md +599 -0
- package/.claude/skills/database-ops/SKILL.md +407 -0
- package/.claude/skills/error-handler/SKILL.md +371 -0
- package/.claude/skills/file-oss-management/SKILL.md +863 -0
- package/.claude/skills/git-workflow/SKILL.md +375 -0
- package/.claude/skills/json-serialization/SKILL.md +357 -0
- package/.claude/skills/leniu-api-development/SKILL.md +803 -0
- package/.claude/skills/leniu-architecture-design/SKILL.md +598 -0
- package/.claude/skills/leniu-backend-annotations/SKILL.md +664 -0
- package/.claude/skills/leniu-code-patterns/SKILL.md +365 -0
- package/.claude/skills/leniu-crud-development/SKILL.md +1110 -0
- package/.claude/skills/leniu-data-permission/SKILL.md +256 -0
- package/.claude/skills/leniu-database-ops/SKILL.md +426 -0
- package/.claude/skills/leniu-error-handler/SKILL.md +462 -0
- package/.claude/skills/leniu-java-amount-handling/SKILL.md +461 -0
- package/.claude/skills/leniu-java-code-style/SKILL.md +510 -0
- package/.claude/skills/leniu-java-concurrent/SKILL.md +400 -0
- package/.claude/skills/leniu-java-entity/SKILL.md +751 -0
- package/.claude/skills/leniu-java-export/SKILL.md +560 -0
- package/.claude/skills/leniu-java-logging/SKILL.md +832 -0
- package/.claude/skills/leniu-java-mq/SKILL.md +338 -0
- package/.claude/skills/leniu-java-mybatis/SKILL.md +640 -0
- package/.claude/skills/leniu-java-report-query-param/SKILL.md +291 -0
- package/.claude/skills/leniu-java-task/SKILL.md +367 -0
- package/.claude/skills/leniu-java-total-line/SKILL.md +195 -0
- package/.claude/skills/leniu-marketing-price-rule-customizer/SKILL.md +301 -0
- package/.claude/skills/leniu-marketing-recharge-rule-customizer/SKILL.md +285 -0
- package/.claude/skills/leniu-mealtime/SKILL.md +215 -0
- package/.claude/skills/leniu-redis-cache/SKILL.md +316 -0
- package/.claude/skills/leniu-security-guard/SKILL.md +520 -0
- package/.claude/skills/leniu-utils-toolkit/SKILL.md +380 -0
- package/.claude/skills/openspec-apply-change/SKILL.md +156 -0
- package/.claude/skills/openspec-archive-change/SKILL.md +114 -0
- package/.claude/skills/openspec-bulk-archive-change/SKILL.md +246 -0
- package/.claude/skills/openspec-continue-change/SKILL.md +118 -0
- package/.claude/skills/openspec-explore/SKILL.md +290 -0
- package/.claude/skills/openspec-ff-change/SKILL.md +101 -0
- package/.claude/skills/openspec-new-change/SKILL.md +74 -0
- package/.claude/skills/openspec-onboard/SKILL.md +529 -0
- package/.claude/skills/openspec-sync-specs/SKILL.md +138 -0
- package/.claude/skills/openspec-verify-change/SKILL.md +168 -0
- package/.claude/skills/performance-doctor/SKILL.md +627 -0
- package/.claude/skills/project-navigator/SKILL.md +305 -0
- package/.claude/skills/redis-cache/SKILL.md +839 -0
- package/.claude/skills/scheduled-jobs/SKILL.md +633 -0
- package/.claude/skills/security-guard/SKILL.md +748 -0
- package/.claude/skills/sms-mail/SKILL.md +766 -0
- package/.claude/skills/social-login/SKILL.md +668 -0
- package/.claude/skills/store-pc/SKILL.md +366 -0
- package/.claude/skills/task-tracker/SKILL.md +307 -0
- package/.claude/skills/tech-decision/SKILL.md +393 -0
- package/.claude/skills/tenant-management/SKILL.md +603 -0
- package/.claude/skills/test-development/SKILL.md +755 -0
- package/.claude/skills/ui-pc/SKILL.md +438 -0
- package/.claude/skills/utils-toolkit/SKILL.md +615 -0
- package/.claude/skills/websocket-sse/SKILL.md +716 -0
- package/.claude/skills/workflow-engine/SKILL.md +676 -0
- package/.claude/templates//345/276/205/345/212/236/346/270/205/345/215/225/346/250/241/346/235/277.md +56 -0
- package/.claude/templates//351/234/200/346/261/202/346/226/207/346/241/243/346/250/241/346/235/277.md +85 -0
- package/.claude/templates//351/241/271/347/233/256/347/212/266/346/200/201/346/250/241/346/235/277.md +43 -0
- package/.codex/skills/add-skill/SKILL.md +352 -0
- package/.codex/skills/add-todo/SKILL.md +269 -0
- package/.codex/skills/api-development/SKILL.md +693 -0
- package/.codex/skills/architecture-design/SKILL.md +628 -0
- package/.codex/skills/backend-annotations/SKILL.md +664 -0
- package/.codex/skills/banana-image/CHANGELOG.md +37 -0
- package/.codex/skills/banana-image/README.md +146 -0
- package/.codex/skills/banana-image/SKILL.md +164 -0
- package/.codex/skills/banana-image/assets/logo.png +0 -0
- package/.codex/skills/banana-image/references/advanced-usage.md +189 -0
- package/.codex/skills/banana-image/scripts/apply_template.py +125 -0
- package/.codex/skills/banana-image/scripts/banana_image_exec.ts +412 -0
- package/.codex/skills/banana-image/scripts/batch_prep.py +82 -0
- package/.codex/skills/banana-image/scripts/package-lock.json +1437 -0
- package/.codex/skills/banana-image/scripts/package.json +18 -0
- package/.codex/skills/banana-image/scripts/requirements.txt +10 -0
- package/.codex/skills/banana-image/templates/poster.json +22 -0
- package/.codex/skills/banana-image/templates/product.json +17 -0
- package/.codex/skills/banana-image/templates/social.json +22 -0
- package/.codex/skills/banana-image/templates/thumbnail.json +17 -0
- package/.codex/skills/brainstorm/SKILL.md +648 -0
- package/.codex/skills/bug-detective/SKILL.md +1206 -0
- package/.codex/skills/check/SKILL.md +367 -0
- package/.codex/skills/code-patterns/SKILL.md +442 -0
- package/.codex/skills/collaborating-with-codex/SKILL.md +174 -0
- package/.codex/skills/collaborating-with-codex/scripts/codex_bridge.py +275 -0
- package/.codex/skills/collaborating-with-gemini/SKILL.md +194 -0
- package/.codex/skills/collaborating-with-gemini/scripts/gemini_bridge.py +275 -0
- package/.codex/skills/crud/SKILL.md +265 -0
- package/.codex/skills/crud-development/SKILL.md +637 -0
- package/.codex/skills/data-permission/SKILL.md +591 -0
- package/.codex/skills/database-ops/SKILL.md +553 -0
- package/.codex/skills/dev/SKILL.md +187 -0
- package/.codex/skills/error-handler/SKILL.md +361 -0
- package/.codex/skills/file-oss-management/SKILL.md +863 -0
- package/.codex/skills/git-workflow/SKILL.md +375 -0
- package/.codex/skills/init-docs/SKILL.md +194 -0
- package/.codex/skills/json-serialization/SKILL.md +357 -0
- package/.codex/skills/leniu-api-development/SKILL.md +803 -0
- package/.codex/skills/leniu-architecture-design/SKILL.md +594 -0
- package/.codex/skills/leniu-backend-annotations/SKILL.md +662 -0
- package/.codex/skills/leniu-code-patterns/SKILL.md +365 -0
- package/.codex/skills/leniu-crud-development/SKILL.md +1110 -0
- package/.codex/skills/leniu-data-permission/SKILL.md +256 -0
- package/.codex/skills/leniu-database-ops/SKILL.md +426 -0
- package/.codex/skills/leniu-error-handler/SKILL.md +462 -0
- package/.codex/skills/leniu-java-amount-handling/SKILL.md +461 -0
- package/.codex/skills/leniu-java-code-style/SKILL.md +510 -0
- package/.codex/skills/leniu-java-concurrent/SKILL.md +400 -0
- package/.codex/skills/leniu-java-entity/SKILL.md +751 -0
- package/.codex/skills/leniu-java-export/SKILL.md +560 -0
- package/.codex/skills/leniu-java-logging/SKILL.md +832 -0
- package/.codex/skills/leniu-java-mq/SKILL.md +338 -0
- package/.codex/skills/leniu-java-mybatis/SKILL.md +640 -0
- package/.codex/skills/leniu-java-report-query-param/SKILL.md +291 -0
- package/.codex/skills/leniu-java-task/SKILL.md +367 -0
- package/.codex/skills/leniu-java-total-line/SKILL.md +195 -0
- package/.codex/skills/leniu-marketing-price-rule-customizer/SKILL.md +301 -0
- package/.codex/skills/leniu-marketing-recharge-rule-customizer/SKILL.md +285 -0
- package/.codex/skills/leniu-mealtime/SKILL.md +215 -0
- package/.codex/skills/leniu-redis-cache/SKILL.md +316 -0
- package/.codex/skills/leniu-security-guard/SKILL.md +520 -0
- package/.codex/skills/leniu-utils-toolkit/SKILL.md +378 -0
- package/.codex/skills/next/SKILL.md +137 -0
- package/.codex/skills/openspec-apply-change/SKILL.md +156 -0
- package/.codex/skills/openspec-archive-change/SKILL.md +114 -0
- package/.codex/skills/openspec-bulk-archive-change/SKILL.md +246 -0
- package/.codex/skills/openspec-continue-change/SKILL.md +118 -0
- package/.codex/skills/openspec-explore/SKILL.md +290 -0
- package/.codex/skills/openspec-ff-change/SKILL.md +101 -0
- package/.codex/skills/openspec-new-change/SKILL.md +74 -0
- package/.codex/skills/openspec-onboard/SKILL.md +529 -0
- package/.codex/skills/openspec-sync-specs/SKILL.md +138 -0
- package/.codex/skills/openspec-verify-change/SKILL.md +168 -0
- package/.codex/skills/performance-doctor/SKILL.md +627 -0
- package/.codex/skills/progress/SKILL.md +193 -0
- package/.codex/skills/project-navigator/SKILL.md +286 -0
- package/.codex/skills/redis-cache/SKILL.md +829 -0
- package/.codex/skills/scheduled-jobs/SKILL.md +633 -0
- package/.codex/skills/security-guard/SKILL.md +739 -0
- package/.codex/skills/sms-mail/SKILL.md +766 -0
- package/.codex/skills/social-login/SKILL.md +668 -0
- package/.codex/skills/start/SKILL.md +154 -0
- package/.codex/skills/store-pc/SKILL.md +491 -0
- package/.codex/skills/sync/SKILL.md +149 -0
- package/.codex/skills/task-tracker/SKILL.md +307 -0
- package/.codex/skills/tech-decision/SKILL.md +393 -0
- package/.codex/skills/tenant-management/SKILL.md +603 -0
- package/.codex/skills/test-development/SKILL.md +755 -0
- package/.codex/skills/ui-pc/SKILL.md +475 -0
- package/.codex/skills/update-status/SKILL.md +159 -0
- package/.codex/skills/utils-toolkit/SKILL.md +593 -0
- package/.codex/skills/websocket-sse/SKILL.md +716 -0
- package/.codex/skills/workflow-engine/SKILL.md +676 -0
- package/.cursor/agents/code-reviewer.md +139 -0
- package/.cursor/agents/project-manager.md +159 -0
- package/.cursor/commands/opsx-apply.md +152 -0
- package/.cursor/commands/opsx-archive.md +157 -0
- package/.cursor/commands/opsx-bulk-archive.md +242 -0
- package/.cursor/commands/opsx-continue.md +114 -0
- package/.cursor/commands/opsx-explore.md +174 -0
- package/.cursor/commands/opsx-ff.md +94 -0
- package/.cursor/commands/opsx-new.md +69 -0
- package/.cursor/commands/opsx-onboard.md +525 -0
- package/.cursor/commands/opsx-sync.md +134 -0
- package/.cursor/commands/opsx-verify.md +164 -0
- package/.cursor/mcp.json +22 -0
- package/.cursor/skills/add-skill/SKILL.md +352 -0
- package/.cursor/skills/api-development/SKILL.md +560 -0
- package/.cursor/skills/architecture-design/SKILL.md +756 -0
- package/.cursor/skills/backend-annotations/SKILL.md +674 -0
- package/.cursor/skills/banana-image/CHANGELOG.md +37 -0
- package/.cursor/skills/banana-image/README.md +146 -0
- package/.cursor/skills/banana-image/SKILL.md +164 -0
- package/.cursor/skills/banana-image/assets/logo.png +0 -0
- package/.cursor/skills/banana-image/references/advanced-usage.md +189 -0
- package/.cursor/skills/banana-image/scripts/apply_template.py +125 -0
- package/.cursor/skills/banana-image/scripts/banana_image_exec.ts +412 -0
- package/.cursor/skills/banana-image/scripts/batch_prep.py +82 -0
- package/.cursor/skills/banana-image/scripts/package-lock.json +1437 -0
- package/.cursor/skills/banana-image/scripts/package.json +18 -0
- package/.cursor/skills/banana-image/scripts/requirements.txt +10 -0
- package/.cursor/skills/banana-image/templates/poster.json +22 -0
- package/.cursor/skills/banana-image/templates/product.json +17 -0
- package/.cursor/skills/banana-image/templates/social.json +22 -0
- package/.cursor/skills/banana-image/templates/thumbnail.json +17 -0
- package/.cursor/skills/brainstorm/SKILL.md +648 -0
- package/.cursor/skills/bug-detective/SKILL.md +1206 -0
- package/.cursor/skills/code-patterns/SKILL.md +590 -0
- package/.cursor/skills/collaborating-with-codex/SKILL.md +174 -0
- package/.cursor/skills/collaborating-with-codex/scripts/codex_bridge.py +275 -0
- package/.cursor/skills/collaborating-with-gemini/SKILL.md +194 -0
- package/.cursor/skills/collaborating-with-gemini/scripts/gemini_bridge.py +275 -0
- package/.cursor/skills/crud-development/SKILL.md +649 -0
- package/.cursor/skills/data-permission/SKILL.md +599 -0
- package/.cursor/skills/database-ops/SKILL.md +407 -0
- package/.cursor/skills/error-handler/SKILL.md +371 -0
- package/.cursor/skills/file-oss-management/SKILL.md +863 -0
- package/.cursor/skills/git-workflow/SKILL.md +375 -0
- package/.cursor/skills/json-serialization/SKILL.md +357 -0
- package/.cursor/skills/leniu-api-development/SKILL.md +803 -0
- package/.cursor/skills/leniu-architecture-design/SKILL.md +598 -0
- package/.cursor/skills/leniu-backend-annotations/SKILL.md +664 -0
- package/.cursor/skills/leniu-code-patterns/SKILL.md +365 -0
- package/.cursor/skills/leniu-crud-development/SKILL.md +1110 -0
- package/.cursor/skills/leniu-data-permission/SKILL.md +256 -0
- package/.cursor/skills/leniu-database-ops/SKILL.md +426 -0
- package/.cursor/skills/leniu-error-handler/SKILL.md +462 -0
- package/.cursor/skills/leniu-java-amount-handling/SKILL.md +461 -0
- package/.cursor/skills/leniu-java-code-style/SKILL.md +510 -0
- package/.cursor/skills/leniu-java-concurrent/SKILL.md +400 -0
- package/.cursor/skills/leniu-java-entity/SKILL.md +751 -0
- package/.cursor/skills/leniu-java-export/SKILL.md +560 -0
- package/.cursor/skills/leniu-java-logging/SKILL.md +832 -0
- package/.cursor/skills/leniu-java-mq/SKILL.md +338 -0
- package/.cursor/skills/leniu-java-mybatis/SKILL.md +640 -0
- package/.cursor/skills/leniu-java-report-query-param/SKILL.md +291 -0
- package/.cursor/skills/leniu-java-task/SKILL.md +367 -0
- package/.cursor/skills/leniu-java-total-line/SKILL.md +195 -0
- package/.cursor/skills/leniu-marketing-price-rule-customizer/SKILL.md +301 -0
- package/.cursor/skills/leniu-marketing-recharge-rule-customizer/SKILL.md +285 -0
- package/.cursor/skills/leniu-mealtime/SKILL.md +215 -0
- package/.cursor/skills/leniu-redis-cache/SKILL.md +316 -0
- package/.cursor/skills/leniu-security-guard/SKILL.md +520 -0
- package/.cursor/skills/leniu-utils-toolkit/SKILL.md +380 -0
- package/.cursor/skills/openspec-apply-change/SKILL.md +156 -0
- package/.cursor/skills/openspec-archive-change/SKILL.md +114 -0
- package/.cursor/skills/openspec-bulk-archive-change/SKILL.md +246 -0
- package/.cursor/skills/openspec-continue-change/SKILL.md +118 -0
- package/.cursor/skills/openspec-explore/SKILL.md +290 -0
- package/.cursor/skills/openspec-ff-change/SKILL.md +101 -0
- package/.cursor/skills/openspec-new-change/SKILL.md +74 -0
- package/.cursor/skills/openspec-onboard/SKILL.md +529 -0
- package/.cursor/skills/openspec-sync-specs/SKILL.md +138 -0
- package/.cursor/skills/openspec-verify-change/SKILL.md +168 -0
- package/.cursor/skills/performance-doctor/SKILL.md +627 -0
- package/.cursor/skills/project-navigator/SKILL.md +305 -0
- package/.cursor/skills/redis-cache/SKILL.md +839 -0
- package/.cursor/skills/scheduled-jobs/SKILL.md +633 -0
- package/.cursor/skills/security-guard/SKILL.md +748 -0
- package/.cursor/skills/sms-mail/SKILL.md +766 -0
- package/.cursor/skills/social-login/SKILL.md +668 -0
- package/.cursor/skills/store-pc/SKILL.md +366 -0
- package/.cursor/skills/task-tracker/SKILL.md +307 -0
- package/.cursor/skills/tech-decision/SKILL.md +393 -0
- package/.cursor/skills/tenant-management/SKILL.md +603 -0
- package/.cursor/skills/test-development/SKILL.md +755 -0
- package/.cursor/skills/ui-pc/SKILL.md +438 -0
- package/.cursor/skills/utils-toolkit/SKILL.md +615 -0
- package/.cursor/skills/websocket-sse/SKILL.md +716 -0
- package/.cursor/skills/workflow-engine/SKILL.md +676 -0
- package/AGENTS.md +669 -0
- package/CLAUDE.md +205 -0
- package/README.md +205 -0
- package/bin/index.js +179 -0
- package/init.sh +178 -0
- package/package.json +27 -0
|
@@ -0,0 +1,593 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: utils-toolkit
|
|
3
|
+
description: |
|
|
4
|
+
后端工具类使用指南。包含 MapstructUtils、StringUtils、StreamUtils、TreeBuildUtils、DateUtils、RedisUtils 等核心工具类。
|
|
5
|
+
|
|
6
|
+
触发场景:
|
|
7
|
+
- 对象转换(BO/VO/Entity)
|
|
8
|
+
- 字符串处理
|
|
9
|
+
- 集合流操作
|
|
10
|
+
- 树结构构建
|
|
11
|
+
- 日期时间处理
|
|
12
|
+
- Redis 缓存操作
|
|
13
|
+
- Excel 导入导出
|
|
14
|
+
- JSON 序列化
|
|
15
|
+
|
|
16
|
+
触发词:工具类、MapstructUtils、StringUtils、StreamUtils、TreeBuildUtils、DateUtils、RedisUtils、ExcelUtil、JsonUtils、LoginHelper、CollUtil、ObjectUtil、IdUtil、convert、对象转换、集合操作、树结构、缓存
|
|
17
|
+
|
|
18
|
+
注意:
|
|
19
|
+
- 对象转换必须使用 MapstructUtils.convert(),禁止使用 BeanUtils。
|
|
20
|
+
- 本项目是纯后端项目,无前端工具类。
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
# 后端工具类大全
|
|
24
|
+
|
|
25
|
+
> 本项目是纯后端项目,本文档专注于 Java 后端工具类。
|
|
26
|
+
|
|
27
|
+
## 快速索引
|
|
28
|
+
|
|
29
|
+
| 功能 | 工具类 | 包路径 | 常用方法 |
|
|
30
|
+
|------|--------|--------|---------|
|
|
31
|
+
| **对象转换** | `MapstructUtils` | `o.d.common.core.utils` | `convert()` |
|
|
32
|
+
| 字符串 | `StringUtils` | `o.d.common.core.utils` | `isBlank()`, `format()` |
|
|
33
|
+
| 集合/流 | `StreamUtils` | `o.d.common.core.utils` | `filter()`, `toList()`, `toMap()` |
|
|
34
|
+
| 树结构 | `TreeBuildUtils` | `o.d.common.core.utils` | `build()` |
|
|
35
|
+
| 日期时间 | `DateUtils` | `o.d.common.core.utils` | `getTime()`, `formatDateTime()` |
|
|
36
|
+
| 参数校验 | `ValidatorUtils` | `o.d.common.core.utils` | `validate()` |
|
|
37
|
+
| Redis缓存 | `RedisUtils` | `o.d.common.redis.utils` | `setCacheObject()`, `getCacheObject()` |
|
|
38
|
+
| Excel导出 | `ExcelUtil` | `o.d.common.excel.utils` | `exportExcel()` |
|
|
39
|
+
| JSON | `JsonUtils` | `o.d.common.json.utils` | `toJsonString()`, `parseObject()` |
|
|
40
|
+
| 登录用户 | `LoginHelper` | `o.d.common.satoken.utils` | `getUserId()`, `getUsername()` |
|
|
41
|
+
| 业务异常 | `ServiceException` | `o.d.common.core.exception` | `throw new ServiceException()` |
|
|
42
|
+
| Spring容器 | `SpringUtils` | `o.d.common.core.utils` | `getBean()` |
|
|
43
|
+
| Hutool集合 | `CollUtil` | `cn.hutool.core.collection` | `isEmpty()`, `newArrayList()` |
|
|
44
|
+
| Hutool对象 | `ObjectUtil` | `cn.hutool.core.util` | `isNull()`, `isEmpty()` |
|
|
45
|
+
| ID生成 | `IdUtil` | `cn.hutool.core.util` | `getSnowflakeNextId()` |
|
|
46
|
+
|
|
47
|
+
> **包路径说明**: `o.d` = `org.dromara`
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## 1. 对象转换 - MapstructUtils(必须使用!)
|
|
52
|
+
|
|
53
|
+
> ⚠️ **强制规范**: 禁止使用 `BeanUtils.copyProperties()`,必须使用 `MapstructUtils.convert()`
|
|
54
|
+
|
|
55
|
+
```java
|
|
56
|
+
import org.dromara.common.core.utils.MapstructUtils;
|
|
57
|
+
|
|
58
|
+
// ✅ 单个对象转换
|
|
59
|
+
XxxVo vo = MapstructUtils.convert(entity, XxxVo.class);
|
|
60
|
+
Xxx entity = MapstructUtils.convert(bo, Xxx.class);
|
|
61
|
+
|
|
62
|
+
// ✅ 集合转换
|
|
63
|
+
List<XxxVo> voList = MapstructUtils.convert(entityList, XxxVo.class);
|
|
64
|
+
|
|
65
|
+
// ✅ 转换到已有对象(合并属性)
|
|
66
|
+
XxxVo vo = MapstructUtils.convert(source, existingVo);
|
|
67
|
+
|
|
68
|
+
// ✅ Map 转 Bean
|
|
69
|
+
Xxx entity = MapstructUtils.convert(map, Xxx.class);
|
|
70
|
+
|
|
71
|
+
// ❌ 禁止使用 BeanUtils
|
|
72
|
+
// BeanUtils.copyProperties(source, target); // 禁止!
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
**配合 @AutoMapper 注解**:
|
|
76
|
+
|
|
77
|
+
```java
|
|
78
|
+
// 在 BO 类上声明映射关系
|
|
79
|
+
@AutoMapper(target = Xxx.class, reverseConvertGenerate = false)
|
|
80
|
+
public class XxxBo extends BaseEntity {
|
|
81
|
+
// ...
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// 在 VO 类上声明映射关系
|
|
85
|
+
@AutoMapper(target = Xxx.class)
|
|
86
|
+
public class XxxVo implements Serializable {
|
|
87
|
+
// ...
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## 2. 字符串操作 - StringUtils
|
|
94
|
+
|
|
95
|
+
```java
|
|
96
|
+
import org.dromara.common.core.utils.StringUtils;
|
|
97
|
+
|
|
98
|
+
// 判空(推荐)
|
|
99
|
+
StringUtils.isBlank(str); // null / "" / 空白 都返回 true
|
|
100
|
+
StringUtils.isNotBlank(str);
|
|
101
|
+
StringUtils.isEmpty(str); // null / "" 返回 true
|
|
102
|
+
StringUtils.isNotEmpty(str);
|
|
103
|
+
|
|
104
|
+
// 格式化(占位符 {})
|
|
105
|
+
StringUtils.format("用户 {} 不存在", userId);
|
|
106
|
+
// 输出: "用户 123 不存在"
|
|
107
|
+
|
|
108
|
+
// 字符串分割
|
|
109
|
+
List<String> list = StringUtils.splitList("1,2,3"); // ["1", "2", "3"]
|
|
110
|
+
List<String> list = StringUtils.splitList("1|2|3", "|"); // 自定义分隔符
|
|
111
|
+
List<Long> ids = StringUtils.splitTo("1,2,3", Convert::toLong); // 转换类型
|
|
112
|
+
|
|
113
|
+
// 字符串拼接
|
|
114
|
+
String str = StringUtils.joinComma(list); // "1,2,3"
|
|
115
|
+
String str = StringUtils.joinComma(array); // 数组版本
|
|
116
|
+
|
|
117
|
+
// 驼峰转换
|
|
118
|
+
StringUtils.toCamelCase("user_name"); // "userName"
|
|
119
|
+
StringUtils.toUnderScoreCase("userName"); // "user_name"
|
|
120
|
+
StringUtils.convertToCamelCase("user_name"); // "UserName" (首字母大写)
|
|
121
|
+
|
|
122
|
+
// 截取
|
|
123
|
+
StringUtils.substring(str, 0, 10);
|
|
124
|
+
|
|
125
|
+
// 路径匹配(Ant 风格)
|
|
126
|
+
StringUtils.isMatch("/api/**", "/api/user/list"); // true
|
|
127
|
+
StringUtils.matches("/api/user", Arrays.asList("/api/**", "/admin/**"));
|
|
128
|
+
|
|
129
|
+
// 左补零
|
|
130
|
+
StringUtils.padl(5, 3); // "005"
|
|
131
|
+
StringUtils.padl("ab", 5, '0'); // "000ab"
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
## 3. 集合与流操作 - StreamUtils
|
|
137
|
+
|
|
138
|
+
```java
|
|
139
|
+
import org.dromara.common.core.utils.StreamUtils;
|
|
140
|
+
|
|
141
|
+
// 过滤
|
|
142
|
+
List<User> activeUsers = StreamUtils.filter(users, u -> "1".equals(u.getStatus()));
|
|
143
|
+
|
|
144
|
+
// 查找第一个
|
|
145
|
+
Optional<User> user = StreamUtils.findFirst(users, u -> u.getId().equals(id));
|
|
146
|
+
User user = StreamUtils.findFirstValue(users, u -> u.getId().equals(id)); // 返回 null 而非 Optional
|
|
147
|
+
|
|
148
|
+
// 提取属性为 List
|
|
149
|
+
List<Long> ids = StreamUtils.toList(users, User::getId);
|
|
150
|
+
|
|
151
|
+
// 提取属性为 Set
|
|
152
|
+
Set<Long> deptIds = StreamUtils.toSet(users, User::getDeptId);
|
|
153
|
+
|
|
154
|
+
// 转为 Map(value 是元素本身)
|
|
155
|
+
Map<Long, User> userMap = StreamUtils.toIdentityMap(users, User::getId);
|
|
156
|
+
|
|
157
|
+
// 转为 Map(自定义 key 和 value)
|
|
158
|
+
Map<Long, String> nameMap = StreamUtils.toMap(users, User::getId, User::getName);
|
|
159
|
+
|
|
160
|
+
// 分组
|
|
161
|
+
Map<Long, List<User>> deptUserMap = StreamUtils.groupByKey(users, User::getDeptId);
|
|
162
|
+
|
|
163
|
+
// 双层分组
|
|
164
|
+
Map<Long, Map<String, List<User>>> map = StreamUtils.groupBy2Key(
|
|
165
|
+
users, User::getDeptId, User::getStatus
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
// 拼接字符串
|
|
169
|
+
String names = StreamUtils.join(users, User::getName); // "张三,李四,王五"
|
|
170
|
+
String names = StreamUtils.join(users, User::getName, "|"); // "张三|李四|王五"
|
|
171
|
+
|
|
172
|
+
// 排序
|
|
173
|
+
List<User> sorted = StreamUtils.sorted(users, Comparator.comparing(User::getCreateTime));
|
|
174
|
+
|
|
175
|
+
// 合并两个 Map
|
|
176
|
+
Map<Long, String> merged = StreamUtils.merge(map1, map2, (v1, v2) -> v1 + v2);
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
---
|
|
180
|
+
|
|
181
|
+
## 4. 树结构构建 - TreeBuildUtils
|
|
182
|
+
|
|
183
|
+
```java
|
|
184
|
+
import org.dromara.common.core.utils.TreeBuildUtils;
|
|
185
|
+
import cn.hutool.core.lang.tree.Tree;
|
|
186
|
+
|
|
187
|
+
// 构建树(自动检测根节点)
|
|
188
|
+
List<Tree<Long>> tree = TreeBuildUtils.build(list, (node, item) -> {
|
|
189
|
+
node.setId(item.getId());
|
|
190
|
+
node.setParentId(item.getParentId());
|
|
191
|
+
node.setName(item.getName());
|
|
192
|
+
node.setWeight(item.getOrderNum()); // 排序
|
|
193
|
+
// 扩展属性
|
|
194
|
+
node.putExtra("icon", item.getIcon());
|
|
195
|
+
node.putExtra("path", item.getPath());
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
// 指定根节点 ID
|
|
199
|
+
List<Tree<Long>> tree = TreeBuildUtils.build(list, 0L, (node, item) -> {
|
|
200
|
+
// ...
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
// 多根节点树
|
|
204
|
+
List<Tree<Long>> tree = TreeBuildUtils.buildMultiRoot(
|
|
205
|
+
list,
|
|
206
|
+
Item::getId,
|
|
207
|
+
Item::getParentId,
|
|
208
|
+
(node, item) -> {
|
|
209
|
+
node.setId(item.getId());
|
|
210
|
+
node.setParentId(item.getParentId());
|
|
211
|
+
node.setName(item.getName());
|
|
212
|
+
}
|
|
213
|
+
);
|
|
214
|
+
|
|
215
|
+
// 获取叶子节点
|
|
216
|
+
List<Tree<Long>> leaves = TreeBuildUtils.getLeafNodes(tree);
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
---
|
|
220
|
+
|
|
221
|
+
## 5. 日期时间 - DateUtils
|
|
222
|
+
|
|
223
|
+
```java
|
|
224
|
+
import org.dromara.common.core.utils.DateUtils;
|
|
225
|
+
import org.dromara.common.core.enums.FormatsType;
|
|
226
|
+
|
|
227
|
+
// 获取当前时间
|
|
228
|
+
Date now = DateUtils.getNowDate();
|
|
229
|
+
String date = DateUtils.getDate(); // "2026-01-24"
|
|
230
|
+
String time = DateUtils.getTime(); // "2026-01-24 15:30:00"
|
|
231
|
+
|
|
232
|
+
// 格式化
|
|
233
|
+
DateUtils.formatDate(date); // "2026-01-24"
|
|
234
|
+
DateUtils.formatDateTime(date); // "2026-01-24 15:30:00"
|
|
235
|
+
DateUtils.parseDateToStr(FormatsType.YYYY_MM_DD_HH_MM, date);
|
|
236
|
+
|
|
237
|
+
// 解析
|
|
238
|
+
Date date = DateUtils.parseDate("2026-01-24");
|
|
239
|
+
Date date = DateUtils.parseDateTime(FormatsType.YYYY_MM_DD_HH_MM_SS, "2026-01-24 15:30:00");
|
|
240
|
+
|
|
241
|
+
// 时间差
|
|
242
|
+
long days = DateUtils.difference(start, end, TimeUnit.DAYS);
|
|
243
|
+
String diff = DateUtils.getDatePoor(endDate, startDate); // "3天 2小时 30分钟"
|
|
244
|
+
String diff = DateUtils.getTimeDifference(endDate, startDate); // 智能省略0值
|
|
245
|
+
|
|
246
|
+
// 日期范围校验
|
|
247
|
+
DateUtils.validateDateRange(startDate, endDate, 30, TimeUnit.DAYS); // 最大30天
|
|
248
|
+
|
|
249
|
+
// 友好时间(仿微信)
|
|
250
|
+
DateUtils.formatFriendlyTime(date); // "刚刚" / "5分钟前" / "昨天 14:30" / "周三 10:00"
|
|
251
|
+
|
|
252
|
+
// 时间段
|
|
253
|
+
DateUtils.getTodayHour(date); // "凌晨" / "上午" / "中午" / "下午" / "晚上"
|
|
254
|
+
|
|
255
|
+
// 类型转换
|
|
256
|
+
Date date = DateUtils.toDate(localDateTime);
|
|
257
|
+
Date date = DateUtils.toDate(localDate);
|
|
258
|
+
|
|
259
|
+
// 路径格式
|
|
260
|
+
DateUtils.datePath(); // "2026/01/24"
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
**FormatsType 枚举**:
|
|
264
|
+
|
|
265
|
+
| 枚举值 | 格式 |
|
|
266
|
+
|-------|------|
|
|
267
|
+
| `YYYY_MM_DD` | yyyy-MM-dd |
|
|
268
|
+
| `YYYY_MM_DD_HH_MM_SS` | yyyy-MM-dd HH:mm:ss |
|
|
269
|
+
| `YYYY_MM_DD_HH_MM` | yyyy-MM-dd HH:mm |
|
|
270
|
+
| `YYYYMMDD` | yyyyMMdd |
|
|
271
|
+
| `YYYYMMDDHHMMSS` | yyyyMMddHHmmss |
|
|
272
|
+
| `HH_MM_SS` | HH:mm:ss |
|
|
273
|
+
|
|
274
|
+
---
|
|
275
|
+
|
|
276
|
+
## 6. 参数校验 - ValidatorUtils
|
|
277
|
+
|
|
278
|
+
```java
|
|
279
|
+
import org.dromara.common.core.utils.ValidatorUtils;
|
|
280
|
+
import org.dromara.common.core.validate.AddGroup;
|
|
281
|
+
import org.dromara.common.core.validate.EditGroup;
|
|
282
|
+
|
|
283
|
+
// 手动校验(在 Service 层使用)
|
|
284
|
+
ValidatorUtils.validate(bo, AddGroup.class);
|
|
285
|
+
ValidatorUtils.validate(bo, EditGroup.class);
|
|
286
|
+
|
|
287
|
+
// Controller 层使用 @Validated(推荐)
|
|
288
|
+
@PostMapping
|
|
289
|
+
public R<Void> add(@Validated(AddGroup.class) @RequestBody XxxBo bo) {
|
|
290
|
+
// ...
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
@PutMapping
|
|
294
|
+
public R<Void> edit(@Validated(EditGroup.class) @RequestBody XxxBo bo) {
|
|
295
|
+
// ...
|
|
296
|
+
}
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
**BO 类校验注解**:
|
|
300
|
+
|
|
301
|
+
```java
|
|
302
|
+
public class XxxBo extends BaseEntity {
|
|
303
|
+
|
|
304
|
+
@NotNull(message = "ID不能为空", groups = { EditGroup.class })
|
|
305
|
+
private Long id;
|
|
306
|
+
|
|
307
|
+
@NotBlank(message = "名称不能为空", groups = { AddGroup.class, EditGroup.class })
|
|
308
|
+
@Size(max = 100, message = "名称长度不能超过100个字符")
|
|
309
|
+
private String name;
|
|
310
|
+
|
|
311
|
+
@Email(message = "邮箱格式不正确")
|
|
312
|
+
private String email;
|
|
313
|
+
|
|
314
|
+
@Pattern(regexp = "^1[3-9]\\d{9}$", message = "手机号格式不正确")
|
|
315
|
+
private String phone;
|
|
316
|
+
|
|
317
|
+
@Min(value = 0, message = "数量不能小于0")
|
|
318
|
+
@Max(value = 9999, message = "数量不能大于9999")
|
|
319
|
+
private Integer count;
|
|
320
|
+
}
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
---
|
|
324
|
+
|
|
325
|
+
## 7. Redis 缓存 - RedisUtils
|
|
326
|
+
|
|
327
|
+
```java
|
|
328
|
+
import org.dromara.common.redis.utils.RedisUtils;
|
|
329
|
+
import java.time.Duration;
|
|
330
|
+
|
|
331
|
+
// 基本操作
|
|
332
|
+
RedisUtils.setCacheObject("key", value); // 永久
|
|
333
|
+
RedisUtils.setCacheObject("key", value, Duration.ofMinutes(30)); // 30分钟过期
|
|
334
|
+
RedisUtils.getCacheObject("key");
|
|
335
|
+
RedisUtils.deleteObject("key");
|
|
336
|
+
RedisUtils.hasKey("key");
|
|
337
|
+
RedisUtils.expire("key", 3600); // 设置过期时间(秒)
|
|
338
|
+
|
|
339
|
+
// 条件设置
|
|
340
|
+
RedisUtils.setObjectIfAbsent("key", value, Duration.ofMinutes(5)); // 不存在才设置
|
|
341
|
+
RedisUtils.setObjectIfExists("key", value, Duration.ofMinutes(5)); // 存在才设置
|
|
342
|
+
|
|
343
|
+
// List 操作
|
|
344
|
+
RedisUtils.setCacheList("listKey", dataList);
|
|
345
|
+
RedisUtils.addCacheList("listKey", item);
|
|
346
|
+
List<T> list = RedisUtils.getCacheList("listKey");
|
|
347
|
+
List<T> range = RedisUtils.getCacheListRange("listKey", 0, 10);
|
|
348
|
+
|
|
349
|
+
// Set 操作
|
|
350
|
+
RedisUtils.setCacheSet("setKey", dataSet);
|
|
351
|
+
RedisUtils.addCacheSet("setKey", item);
|
|
352
|
+
Set<T> set = RedisUtils.getCacheSet("setKey");
|
|
353
|
+
|
|
354
|
+
// Map/Hash 操作
|
|
355
|
+
RedisUtils.setCacheMap("mapKey", dataMap);
|
|
356
|
+
RedisUtils.setCacheMapValue("mapKey", "field", value);
|
|
357
|
+
T value = RedisUtils.getCacheMapValue("mapKey", "field");
|
|
358
|
+
Map<String, T> map = RedisUtils.getCacheMap("mapKey");
|
|
359
|
+
RedisUtils.delCacheMapValue("mapKey", "field");
|
|
360
|
+
|
|
361
|
+
// 原子操作
|
|
362
|
+
RedisUtils.setAtomicValue("counter", 0);
|
|
363
|
+
long val = RedisUtils.incrAtomicValue("counter"); // +1
|
|
364
|
+
long val = RedisUtils.decrAtomicValue("counter"); // -1
|
|
365
|
+
long val = RedisUtils.getAtomicValue("counter");
|
|
366
|
+
|
|
367
|
+
// 批量操作
|
|
368
|
+
Collection<String> keys = RedisUtils.keys("user:*");
|
|
369
|
+
RedisUtils.deleteKeys("temp:*");
|
|
370
|
+
|
|
371
|
+
// 发布订阅
|
|
372
|
+
RedisUtils.publish("channel", message);
|
|
373
|
+
RedisUtils.subscribe("channel", Message.class, msg -> {
|
|
374
|
+
// 处理消息
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
// 限流
|
|
378
|
+
long remaining = RedisUtils.rateLimiter("api:user:list", RateType.OVERALL, 100, 60);
|
|
379
|
+
// 每60秒最多100次,返回剩余次数,-1表示被限流
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
---
|
|
383
|
+
|
|
384
|
+
## 8. 登录用户 - LoginHelper
|
|
385
|
+
|
|
386
|
+
```java
|
|
387
|
+
import org.dromara.common.satoken.utils.LoginHelper;
|
|
388
|
+
|
|
389
|
+
// 获取当前登录用户信息
|
|
390
|
+
Long userId = LoginHelper.getUserId();
|
|
391
|
+
String username = LoginHelper.getUsername();
|
|
392
|
+
Long deptId = LoginHelper.getDeptId();
|
|
393
|
+
String tenantId = LoginHelper.getTenantId();
|
|
394
|
+
LoginUser loginUser = LoginHelper.getLoginUser();
|
|
395
|
+
|
|
396
|
+
// 判断登录状态
|
|
397
|
+
boolean isLogin = LoginHelper.isLogin();
|
|
398
|
+
|
|
399
|
+
// 判断是否超级管理员
|
|
400
|
+
boolean isSuperAdmin = LoginHelper.isSuperAdmin();
|
|
401
|
+
boolean isSuperAdmin = LoginHelper.isSuperAdmin(userId);
|
|
402
|
+
|
|
403
|
+
// 判断是否租户管理员
|
|
404
|
+
boolean isTenantAdmin = LoginHelper.isTenantAdmin();
|
|
405
|
+
boolean isTenantAdmin = LoginHelper.isTenantAdmin(rolePermission);
|
|
406
|
+
```
|
|
407
|
+
|
|
408
|
+
---
|
|
409
|
+
|
|
410
|
+
## 9. 业务异常 - ServiceException
|
|
411
|
+
|
|
412
|
+
```java
|
|
413
|
+
import org.dromara.common.core.exception.ServiceException;
|
|
414
|
+
|
|
415
|
+
// 抛出业务异常
|
|
416
|
+
throw new ServiceException("用户不存在");
|
|
417
|
+
throw new ServiceException("用户 {} 不存在", userId);
|
|
418
|
+
|
|
419
|
+
// 条件判断
|
|
420
|
+
if (user == null) {
|
|
421
|
+
throw new ServiceException("用户不存在");
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
// 带错误码
|
|
425
|
+
throw new ServiceException("用户不存在", 500);
|
|
426
|
+
```
|
|
427
|
+
|
|
428
|
+
---
|
|
429
|
+
|
|
430
|
+
## 10. Excel 导出 - ExcelUtil
|
|
431
|
+
|
|
432
|
+
```java
|
|
433
|
+
import org.dromara.common.excel.utils.ExcelUtil;
|
|
434
|
+
|
|
435
|
+
// Controller 中导出
|
|
436
|
+
@PostMapping("/export")
|
|
437
|
+
public void export(XxxBo bo, HttpServletResponse response) {
|
|
438
|
+
List<XxxVo> list = xxxService.queryList(bo);
|
|
439
|
+
ExcelUtil.exportExcel(list, "数据导出", XxxVo.class, response);
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
// 导入
|
|
443
|
+
@PostMapping("/import")
|
|
444
|
+
public R<Void> importData(@RequestPart("file") MultipartFile file) throws Exception {
|
|
445
|
+
List<XxxVo> list = ExcelUtil.importExcel(file.getInputStream(), XxxVo.class);
|
|
446
|
+
// 处理导入数据
|
|
447
|
+
return R.ok();
|
|
448
|
+
}
|
|
449
|
+
```
|
|
450
|
+
|
|
451
|
+
**VO 类 Excel 注解**:
|
|
452
|
+
|
|
453
|
+
```java
|
|
454
|
+
public class XxxVo implements Serializable {
|
|
455
|
+
|
|
456
|
+
@ExcelProperty(value = "ID")
|
|
457
|
+
private Long id;
|
|
458
|
+
|
|
459
|
+
@ExcelProperty(value = "名称")
|
|
460
|
+
private String name;
|
|
461
|
+
|
|
462
|
+
@ExcelProperty(value = "状态", converter = ExcelDictConvert.class)
|
|
463
|
+
@ExcelDictFormat(dictType = "sys_normal_disable")
|
|
464
|
+
private String status;
|
|
465
|
+
|
|
466
|
+
@ExcelProperty(value = "创建时间")
|
|
467
|
+
private Date createTime;
|
|
468
|
+
}
|
|
469
|
+
```
|
|
470
|
+
|
|
471
|
+
---
|
|
472
|
+
|
|
473
|
+
## 11. JSON 操作 - JsonUtils
|
|
474
|
+
|
|
475
|
+
```java
|
|
476
|
+
import org.dromara.common.json.utils.JsonUtils;
|
|
477
|
+
|
|
478
|
+
// 对象转 JSON
|
|
479
|
+
String json = JsonUtils.toJsonString(obj);
|
|
480
|
+
|
|
481
|
+
// JSON 转对象
|
|
482
|
+
User user = JsonUtils.parseObject(json, User.class);
|
|
483
|
+
|
|
484
|
+
// JSON 转 List
|
|
485
|
+
List<User> list = JsonUtils.parseArray(json, User.class);
|
|
486
|
+
|
|
487
|
+
// JSON 转 Map
|
|
488
|
+
Map<String, Object> map = JsonUtils.parseMap(json);
|
|
489
|
+
```
|
|
490
|
+
|
|
491
|
+
---
|
|
492
|
+
|
|
493
|
+
## 12. Hutool 常用工具
|
|
494
|
+
|
|
495
|
+
```java
|
|
496
|
+
import cn.hutool.core.collection.CollUtil;
|
|
497
|
+
import cn.hutool.core.util.ObjectUtil;
|
|
498
|
+
import cn.hutool.core.util.StrUtil;
|
|
499
|
+
import cn.hutool.core.util.IdUtil;
|
|
500
|
+
import cn.hutool.crypto.SecureUtil;
|
|
501
|
+
|
|
502
|
+
// 集合判空
|
|
503
|
+
CollUtil.isEmpty(list);
|
|
504
|
+
CollUtil.isNotEmpty(list);
|
|
505
|
+
CollUtil.newArrayList(1, 2, 3);
|
|
506
|
+
CollUtil.newHashSet("a", "b");
|
|
507
|
+
|
|
508
|
+
// 对象判空
|
|
509
|
+
ObjectUtil.isNull(obj);
|
|
510
|
+
ObjectUtil.isNotNull(obj);
|
|
511
|
+
ObjectUtil.isEmpty(obj); // null / 空字符串 / 空集合
|
|
512
|
+
ObjectUtil.defaultIfNull(obj, defaultValue);
|
|
513
|
+
|
|
514
|
+
// ID 生成
|
|
515
|
+
long snowflakeId = IdUtil.getSnowflakeNextId(); // 雪花ID(推荐)
|
|
516
|
+
String uuid = IdUtil.simpleUUID(); // 无横线 UUID
|
|
517
|
+
String uuid = IdUtil.randomUUID(); // 标准 UUID
|
|
518
|
+
String nanoId = IdUtil.nanoId(); // NanoID
|
|
519
|
+
|
|
520
|
+
// 加密
|
|
521
|
+
String md5 = SecureUtil.md5("password");
|
|
522
|
+
String sha256 = SecureUtil.sha256("password");
|
|
523
|
+
|
|
524
|
+
// Base64
|
|
525
|
+
import cn.hutool.core.codec.Base64;
|
|
526
|
+
String encoded = Base64.encode("data");
|
|
527
|
+
String decoded = Base64.decodeStr(encoded);
|
|
528
|
+
```
|
|
529
|
+
|
|
530
|
+
---
|
|
531
|
+
|
|
532
|
+
## 常用正则表达式
|
|
533
|
+
|
|
534
|
+
```java
|
|
535
|
+
// 手机号
|
|
536
|
+
String phoneReg = "^1[3-9]\\d{9}$";
|
|
537
|
+
|
|
538
|
+
// 邮箱
|
|
539
|
+
String emailReg = "^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+$";
|
|
540
|
+
|
|
541
|
+
// 身份证
|
|
542
|
+
String idCardReg = "^[1-9]\\d{5}(19|20)\\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\\d|3[01])\\d{3}[\\dXx]$";
|
|
543
|
+
|
|
544
|
+
// URL
|
|
545
|
+
String urlReg = "^https?://.+";
|
|
546
|
+
|
|
547
|
+
// 中文
|
|
548
|
+
String chineseReg = "^[\\u4e00-\\u9fa5]+$";
|
|
549
|
+
```
|
|
550
|
+
|
|
551
|
+
---
|
|
552
|
+
|
|
553
|
+
## 工具类选择速查
|
|
554
|
+
|
|
555
|
+
| 需求 | 推荐工具 | 说明 |
|
|
556
|
+
|------|---------|------|
|
|
557
|
+
| BO ↔ Entity ↔ VO 转换 | `MapstructUtils.convert()` | **必须使用** |
|
|
558
|
+
| 字符串判空 | `StringUtils.isBlank()` | 推荐项目工具类 |
|
|
559
|
+
| 集合判空 | `CollUtil.isEmpty()` | Hutool |
|
|
560
|
+
| 对象判空 | `ObjectUtil.isNull()` | Hutool |
|
|
561
|
+
| 提取集合属性 | `StreamUtils.toList()` | 项目工具类 |
|
|
562
|
+
| 集合转 Map | `StreamUtils.toIdentityMap()` | 项目工具类 |
|
|
563
|
+
| 分组 | `StreamUtils.groupByKey()` | 项目工具类 |
|
|
564
|
+
| 构建树 | `TreeBuildUtils.build()` | 项目工具类 |
|
|
565
|
+
| 日期格式化 | `DateUtils.formatDateTime()` | 项目工具类 |
|
|
566
|
+
| 抛业务异常 | `throw new ServiceException()` | 项目异常类 |
|
|
567
|
+
| 获取登录用户 | `LoginHelper.getUserId()` | 项目工具类 |
|
|
568
|
+
| Redis 缓存 | `RedisUtils.setCacheObject()` | 项目工具类 |
|
|
569
|
+
| Excel 导出 | `ExcelUtil.exportExcel()` | 项目工具类 |
|
|
570
|
+
| 生成 ID | `IdUtil.getSnowflakeNextId()` | Hutool |
|
|
571
|
+
| MD5/SHA | `SecureUtil.md5()` | Hutool |
|
|
572
|
+
|
|
573
|
+
---
|
|
574
|
+
|
|
575
|
+
## 禁止事项
|
|
576
|
+
|
|
577
|
+
```java
|
|
578
|
+
// ❌ 禁止使用 BeanUtils
|
|
579
|
+
BeanUtils.copyProperties(source, target); // 禁止!
|
|
580
|
+
|
|
581
|
+
// ❌ 禁止使用 Map 传递业务数据
|
|
582
|
+
public Map<String, Object> getXxx() { ... } // 禁止!
|
|
583
|
+
|
|
584
|
+
// ❌ 禁止手写 stream 转换(应使用 StreamUtils)
|
|
585
|
+
list.stream().map(User::getId).collect(Collectors.toList()); // 不推荐
|
|
586
|
+
StreamUtils.toList(list, User::getId); // ✅ 推荐
|
|
587
|
+
|
|
588
|
+
// ❌ 禁止使用完整类型引用
|
|
589
|
+
public org.dromara.common.core.domain.R<XxxVo> getXxx() // 禁止!
|
|
590
|
+
// ✅ 正确:先 import,再使用短类名
|
|
591
|
+
import org.dromara.common.core.domain.R;
|
|
592
|
+
public R<XxxVo> getXxx()
|
|
593
|
+
```
|