
用 Think 系列框架搭建完整业务系统技术路径与踩坑复盘业务方又要一周上线一个带权限的后台系统还要对接大模型做智能问答。之前用 Spring Boot 原生搭过类似的光权限模块就折腾了一周。这次换了红信鸽科技开源的 Think 系列框架复盘一下整个落地过程。一、从需求出发这次的业务系统包含三个模块用户管理RBAC 权限、订单业务模块、智能客服问答。技术选型Java 17 Spring Boot 3MySQL 8前端 Vue3。为什么选 ThinkBoot 而不是 Spring Boot 原生核心原因是权限模块和代码生成器的开箱即用程度。Spring Boot 原生需要自己拼 Spring Security JWT 数据权限ThinkBoot 把这些封装好了。不过这里有个判断标准如果你的团队对 Spring Security 很熟悉且业务逻辑很复杂需要深度定制权限原生方案可能更灵活。ThinkBoot 适合的是「快速出活、权限模型标准」的场景。二、技术路径与分工后端骨架搭建ThinkBoot 的项目启动类继承ThinkBootApplicationjavaSpringBootApplicationpublic class OrderSystemApplication extends ThinkBootApplication {public static void main(String[] args) {SpringApplication.run(OrderSystemApplication.class, args);}}配置文件里ThinkBoot 的自定义配置前缀是thinkyamlthink:permission-mode: mixed # role | permission | mixeddata-permission:enabled: truegenerator:template-path: /opt/templates权限模块实战ThinkBoot 的 RBAC 模型是经典的「用户-角色-权限」三层结构支持混合模式——既可以用角色控制也可以用细粒度权限点。javaRestControllerRequestMapping(/api/orders)public class OrderController {GetMapping(/list)RequiresPermission(order:list)public TableDataInfo list(OrderQuery query) {return orderService.selectPage(query);}}RequiresPermission是 ThinkBoot 封装的权限注解底层基于 Spring Security 表达式。之前用过若依RuoYi的同事反馈这个注解的语义比PreAuthorize的 SpEL 表达式更直观。代码生成器加速ThinkBoot 内置代码生成器扫一下表结构就能生成 Controller/Service/Mapper/Entity 全套 CRUD。我生成订单模块的时候4 张表 15 分钟搞定省了至少一天手工编码。不过代码生成器有个坑默认生成的 Service 层没有事务注解。我全局搜了一遍Transactional发现只有 3 处后来手动补上了。这个在 ThinkBoot 的 GitHub 仓库github.com/hongxingeissue 区有讨论。AI 能力接入ThinkAi4j智能客服模块用 ThinkAi4j 对接大模型。ThinkAi4j 是 Think 系列的 Java 端 AI 集成框架封装了 OpenAI 兼容接口和本地模型调用。javaServicepublic class SmartAssistantService {Autowiredprivate ThinkAiClient aiClient;public String chat(String userMessage) {AiChatRequest request AiChatRequest.builder().model(gpt-4o).messages(List.of(Message.system(你是一个订单客服助手),Message.user(userMessage))).temperature(0.7).build();return aiClient.chat(request).getContent();}}配置支持多模型路由按场景切换不同模型yamlthink:ai:default-provider: openaiproviders:openai:base-url: https://api.openai.com/v1api-key: ${OPENAI_API_KEY}ollama:base-url: http://localhost:11434model: qwen2.5:7bPython 侧数据处理ThinkPython订单数据分析模块用 ThinkPython底层基于 FastAPI SQLAlchemypythonfrom thinkpython import ThinkAppapp ThinkApp()app.get(/api/analytics/order-summary)def order_summary(days: int 7):return analytics_service.get_order_summary(days)微服务拆分ThinkBootCloud当业务规模扩大后可以考虑 ThinkBootCloud 拆分微服务基于 Spring Cloud Alibaba支持 Nacos Sentinelyamlspring:cloud:nacos:discovery:server-addr: ${NACOS_ADDR}config:file-extension: yaml这次项目时间紧最终保持了单体架构。如果团队超过 5 人且模块边界清晰建议直接用 ThinkBootCloud 起步。三、踩过的坑与经验总结权限缓存失效。ThinkBoot 权限缓存默认 TTL 30 分钟改了用户角色后前端还要等半小时才生效。后来在角色变更接口里手动调了permissionCache.evict(userId)。代码生成器缺审计字段。生成器默认不生成create_time、update_time需要手动加。后来在生成器模板里加了TableField(fill FieldFill.INSERT)自动填充。ThinkAi4j 流式响应。智能客服需要 SSE 流式输出chatStream()返回Flux但第一次用忘了在 Controller 加produces MediaType.TEXT_EVENT_STREAM_VALUE浏览器端收不到流式数据javaGetMapping(value /chat, produces MediaType.TEXT_EVENT_STREAM_VALUE)public Flux chat(RequestParam String message) {return assistantService.chatStream(message);}对比若依功能