乐于分享
好东西不私藏

Spring AI Alibaba 教程:集成阿里云大模型服务实战

Spring AI Alibaba 教程:集成阿里云大模型服务实战

01

AI 技术正以前所未有的速度重塑软件开发行业。作为 Java 开发者,该如何快速搭上这波 AI 发展的快车?今天就给大家分享一套能让 AI 能力落地的实战方案 ——Spring AI Alibaba,它能帮我们把阿里云大模型服务轻松集成到 Spring Boot 应用中。

02

为什么选择 Spring AI Alibaba?

在集成 AI 能力的过程中,开发者往往会遇到这些痛点:

学习成本高:不同 AI 服务商的 API 接口差异极大,需要花费大量时间适配;集成复杂:要手动处理认证、重试、错误捕获等繁琐的底层逻辑;维护困难:各类 API 版本迭代频繁,适配代码需反复调整;缺乏标准化:没有统一的使用范式,团队协作成本高。

Spring AI Alibaba恰好能解决这些问题,它核心优势体现在:

  • • 提供统一的 API 接口,屏蔽不同模型的调用差异;
  • • 极简的配置方式,几行代码就能完成集成;
  • • 内置完善的错误处理机制,降低异常处理成本;
  • • 具备企业级的可靠性保障,适应生产环境要求。

03

核心技术架构

先来看下 Spring AI Alibaba 的整体技术架构,主要分为三层:

03.1 配置层

配置层的核心是初始化阿里云大模型的连接信息和调用参数,以下是完整可运行的配置代码:

java

运行

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.alibaba.cloud.ai.credentials.Credential;
import com.alibaba.cloud.ai.credentials.StaticCredentialProvider;
import com.alibaba.cloud.ai.model.AlibabaChatModel;
import com.alibaba.cloud.ai.model.AlibabaChatOptions;
import com.alibaba.cloud.ai.model.AlibabaModel;
import com.alibaba.dashscope.async.AsyncClient;

/**
 * 阿里云AI模型配置类
 * 负责初始化大模型连接凭证和默认调用参数
 */
@Configuration
public class AlibabaAiConfig {

    // 阿里云AccessKey ID(建议从配置文件/环境变量读取)
    private String accessKeyId = "${your-access-key-id}";
    // 阿里云AccessKey Secret(建议从配置文件/环境变量读取)
    private String accessKeySecret = "${your-access-key-secret}";

    /**
     * 创建阿里云凭证提供者
     * 用于鉴权访问阿里云大模型服务
     */
    @Bean
    public StaticCredentialProvider credentialProvider() {
        // 构建鉴权凭证
        Credential credential = Credential.builder()
                .accessKeyId(accessKeyId)
                .accessKeySecret(accessKeySecret)
                .build();
        // 返回静态凭证提供者(生产环境可替换为动态凭证)
        return StaticCredentialProvider.create(credential);
    }

    /**
     * 初始化阿里云聊天模型实例
     * @param dashscopeClient 阿里云DashScope异步客户端(自动注入)
     * @return 配置好的聊天模型
     */
    @Bean
    public AlibabaChatModel alibabaChatModel(AsyncClient dashscopeClient) {
        // 构建模型调用参数
        AlibabaChatOptions options = AlibabaChatOptions.builder()
                .withModel(AlibabaModel.QWEN_PLUS) // 指定使用通义千问PLUS模型
                .withTemperature(0.7f) // 随机性:0-1之间,值越高回答越灵活
                .withMaxTokens(2000) // 最大生成token数,控制回答长度
                .build();
        // 返回配置好的聊天模型
        return new AlibabaChatModel(dashscopeClient, options);
    }
}

03.2 服务层

服务层封装 AI 模型的调用逻辑,对外提供简洁的业务接口:

java

运行

import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.ai.chat.prompt.UserMessage;
import org.springframework.stereotype.Service;
import com.alibaba.cloud.ai.client.AlibabaChatClient;
import com.alibaba.cloud.ai.model.AlibabaChatResponse;

/**
 * 阿里云AI服务封装类
 * 提供基础的聊天和代码生成能力
 */
@Service
public class AlibabaAiService {

    // 注入阿里云聊天客户端(由Spring AI自动配置)
    private final AlibabaChatClient chatClient;

    // 构造函数注入依赖
    public AlibabaAiService(AlibabaChatClient chatClient) {
        this.chatClient = chatClient;
    }

    /**
     * 基础聊天接口
     * @param userInput 用户输入的问题/指令
     * @return AI生成的回答
     */
    public String chat(String userInput) {
        // 构建用户提示词
        Prompt prompt = new Prompt(new UserMessage(userInput));
        // 调用AI模型获取响应
        AlibabaChatResponse response = chatClient.call(prompt);
        // 提取并返回回答文本
        return response.getResult().getOutput().getText();
    }

    /**
     * 代码生成专用接口
     * @param requirement 用户的代码开发需求
     * @return 符合规范的Java代码
     */
    public String generateCode(String requirement) {
        // 系统提示词:定义AI的角色和输出规范
        String systemPrompt = """
                你是一个专业的Java开发助手。请根据用户需求生成高质量的Java代码。
                要求:
                1. 代码要符合Java最佳实践
                2. 包含必要的注释说明
                3. 使用Spring Boot框架
                """;
        // 组合系统提示词和用户需求调用AI
        return chatWithSystemPrompt(requirement, systemPrompt);
    }

    /**
     * 带系统提示词的聊天方法(私有辅助方法)
     * @param userInput 用户输入
     * @param systemPrompt 系统提示词(定义AI行为)
     * @return AI生成的回答
     */
    private String chatWithSystemPrompt(String userInput, String systemPrompt) {
        Prompt prompt = new Prompt(
                new org.springframework.ai.chat.prompt.SystemMessage(systemPrompt),
                new UserMessage(userInput)
        );
        AlibabaChatResponse response = chatClient.call(prompt);
        return response.getResult().getOutput().getText();
    }
}

03.3 控制器层

控制器层对外暴露 HTTP 接口,接收前端请求并调用服务层:

java

运行

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;

/**
 * AI功能接口控制器
 * 提供聊天和代码生成的HTTP接口
 */
@RestController
@RequestMapping("/api/ai")
public class AlibabaAiController {

    // 注入AI服务
    private final AlibabaAiService aiService;

    // 构造函数注入
    public AlibabaAiController(AlibabaAiService aiService) {
        this.aiService = aiService;
    }

    /**
     * 聊天接口
     * @param request 前端传入的聊天请求(包含message字段)
     * @return 包含AI回答的响应
     */
    @PostMapping("/chat")
    public Map<String, Object> chat(@RequestBody ChatRequest request) {
        String response = aiService.chat(request.getMessage());
        // 返回JSON格式的响应
        return Map.of("response", response);
    }

    /**
     * 代码生成接口
     * @param request 前端传入的代码生成请求(包含requirement字段)
     * @return 包含生成代码的响应
     */
    @PostMapping("/code")
    public Map<String, Object> generateCode(@RequestBody CodeRequest request) {
        String code = aiService.generateCode(request.getRequirement());
        return Map.of("generatedCode", code);
    }

    // 内部静态类:接收聊天请求参数
    public static class ChatRequest {
        private String message;

        // getter和setter
        public String getMessage() {
            return message;
        }

        public void setMessage(String message) {
            this.message = message;
        }
    }

    // 内部静态类:接收代码生成请求参数
    public static class CodeRequest {
        private String requirement;

        // getter和setter
        public String getRequirement() {
            return requirement;
        }

        public void setRequirement(String requirement) {
            this.requirement = requirement;
        }
    }
}

04

实战案例演示

下面通过 3 个真实业务场景,展示 Spring AI Alibaba 的落地用法:

04.1 案例 1:智能客服系统

适用于电商、金融等行业的智能客服场景,结合用户历史对话精准回答问题:

java

运行

import org.springframework.stereotype.Service;
import java.util.Map;

/**
 * 智能客服AI服务
 * 结合用户历史对话生成精准回答
 */
@Service
public class CustomerServiceAi {

    private final AlibabaAiService aiService;

    public CustomerServiceAi(AlibabaAiService aiService) {
        this.aiService = aiService;
    }

    /**
     * 处理客户咨询
     * @param query 客户当前问题
     * @param customerHistory 客户历史对话记录
     * @return 专业、友好的回答
     */
    public String handleCustomerQuery(String query, String customerHistory) {
        // 提示词模板:通过占位符注入变量
        String promptTemplate = """
                基于以下客户历史信息,回答客户问题:
                客户历史:
                {history}
                客户问题:
                {query}
                要求:
                1. 回答要专业、友好
                2. 如果问题涉及具体产品,请提供详细信息
                3. 必要时提供解决方案建议
                """;
        // 组装模板变量
        Map<String, Object> variables = Map.of(
                "history", customerHistory,
                "query", query
        );
        // 调用模板化聊天方法
        return aiService.chatWithTemplate(promptTemplate, variables);
    }
}

04.2 案例 2:代码审查助手

自动审查代码质量,给出优化建议,提升研发效率:

java

运行

import org.springframework.stereotype.Service;

/**
 * 代码审查服务
 * 自动分析代码并给出改进建议
 */
@Service
public class CodeReviewService {

    private final AlibabaAiService aiService;

    public CodeReviewService(AlibabaAiService aiService) {
        this.aiService = aiService;
    }

    /**
     * 审查指定语言的代码
     * @param code 待审查的代码文本
     * @param language 代码语言(如Java、Python)
     * @return 详细的审查报告和改进建议
     */
    public String reviewCode(String code, String language) {
        // 构造代码审查提示词
        String prompt = String.format("""
                请审查以下%s代码,提供改进建议:
                代码内容:
                %s
                审查要点:
                1. 代码质量和最佳实践
                2. 性能优化建议
                3. 安全性考虑
                4. 可维护性评估
                """, language, code);
        // 调用AI聊天接口获取审查结果
        return aiService.chat(prompt);
    }
}

04.3 案例 3:智能文档处理

自动提取文档关键信息、生成摘要、分析情感,适用于办公自动化场景:

java

运行

import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;

/**
 * 智能文档处理服务
 * 提取文档关键信息、生成摘要、分析情感倾向
 */
@Service
public class DocumentProcessingService {

    private final AlibabaAiService aiService;

    public DocumentProcessingService(AlibabaAiService aiService) {
        this.aiService = aiService;
    }

    /**
     * 处理文档并生成结构化摘要
     * @param documentContent 原始文档内容
     * @return 包含摘要、关键点、情感等的结构化对象
     */
    public DocumentSummary processDocument(String documentContent) {
        // 1. 提取文档关键信息
        String keyPoints = extractKeyPoints(documentContent);
        // 2. 生成文档摘要
        String summary = summarizeDocument(documentContent);
        // 3. 分析文档情感倾向
        String sentiment = analyzeSentiment(documentContent);
        // 4. 提取文档关键词
        List<String> keywords = extractKeywords(documentContent);

        // 组装结构化摘要并返回
        return DocumentSummary.builder()
                .originalContent(documentContent)
                .summary(summary)
                .keyPoints(keyPoints)
                .sentiment(sentiment)
                .keywords(keywords)
                .build();
    }

    /**
     * 提取文档关键要点
     * @param content 文档内容
     * @return 5个核心关键点
     */
    private String extractKeyPoints(String content) {
        String prompt = """
                从以下文档中提取5个最重要的关键点:
                {content}
                """;
        return aiService.chatWithTemplate(prompt, Map.of("content", content));
    }

    /**
     * 生成文档摘要
     * @param content 文档内容
     * @return 简洁的文档摘要
     */
    private String summarizeDocument(String content) {
        String prompt = "请用100字以内总结以下文档核心内容:" + content;
        return aiService.chat(prompt);
    }

    /**
     * 分析文档情感倾向
     * @param content 文档内容
     * @return 情感标签(正面/中性/负面)
     */
    private String analyzeSentiment(String content) {
        String prompt = "分析以下文档的情感倾向,仅返回:正面、中性、负面其中一个:" + content;
        return aiService.chat(prompt);
    }

    /**
     * 提取文档关键词
     * @param content 文档内容
     * @return 关键词列表
     */
    private List<String> extractKeywords(String content) {
        String prompt = "从以下文档中提取10个核心关键词,用逗号分隔:" + content;
        String keywordsStr = aiService.chat(prompt);
        return List.of(keywordsStr.split(","));
    }

    /**
     * 文档摘要实体类
     * 用于封装文档处理结果
     */
    public static class DocumentSummary {
        private String originalContent; // 原始内容
        private String summary; // 文档摘要
        private String keyPoints; // 关键要点
        private String sentiment; // 情感倾向
        private List<String> keywords; // 关键词

        // 建造者模式
        public static DocumentSummaryBuilder builder() {
            return new DocumentSummaryBuilder();
        }

        public static class DocumentSummaryBuilder {
            private DocumentSummary summary;

            public DocumentSummaryBuilder() {
                summary = new DocumentSummary();
            }

            public DocumentSummaryBuilder originalContent(String originalContent) {
                summary.originalContent = originalContent;
                return this;
            }

            public DocumentSummaryBuilder summary(String summary) {
                summary.summary = summary;
                return this;
            }

            public DocumentSummaryBuilder keyPoints(String keyPoints) {
                summary.keyPoints = keyPoints;
                return this;
            }

            public DocumentSummaryBuilder sentiment(String sentiment) {
                summary.sentiment = sentiment;
                return this;
            }

            public DocumentSummaryBuilder keywords(List<String> keywords) {
                summary.keywords = keywords;
                return this;
            }

            public DocumentSummary build() {
                return summary;
            }
        }

        // getter和setter省略
    }
}

05

高级功能实现

掌握基础用法后,我们可以实现更复杂的高级功能:

05.1 多模型切换

根据业务场景切换不同性能的模型(极速 / 平衡 / 高质量),兼顾效率和成本:

java

运行

import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;
import com.alibaba.cloud.ai.model.AlibabaChatModel;
import com.alibaba.cloud.ai.model.AlibabaChatOptions;
import com.alibaba.cloud.ai.model.AlibabaModel;
import com.alibaba.dashscope.async.AsyncClient;

/**
 * 多模型AI服务
 * 支持根据业务需求切换不同性能的阿里云大模型
 */
@Service
public class MultiModelAiService {

    // 注入阿里云异步客户端
    private final AsyncClient dashscopeClient;
    // 存储不同类型的模型实例
    private final Map<String, AlibabaChatModel> chatModels = new HashMap<>();

    public MultiModelAiService(AsyncClient dashscopeClient) {
        this.dashscopeClient = dashscopeClient;
    }

    /**
     * 初始化多模型实例(项目启动时执行)
     */
    @PostConstruct
    public void initializeModels() {
        // 极速模型:响应快,适合简单问答
        chatModels.put("fast", createModel(AlibabaModel.QWEN_TURBO, 0.5f));
        // 平衡模型:兼顾速度和质量,适合通用场景
        chatModels.put("balanced", createModel(AlibabaModel.QWEN_PLUS, 0.7f));
        // 高质量模型:回答精准,适合复杂任务
        chatModels.put("high-quality", createModel(AlibabaModel.QWEN_MAX, 0.9f));
    }

    /**
     * 指定模型进行聊天
     * @param message 用户输入
     * @param modelType 模型类型(fast/balanced/high-quality)
     * @return AI生成的回答
     */
    public String chatWithModel(String message, String modelType) {
        // 获取指定类型的模型
        AlibabaChatModel model = chatModels.get(modelType);
        if (model == null) {
            throw new IllegalArgumentException("不支持的模型类型: " + modelType);
        }
        // 构建提示词并调用模型
        Prompt prompt = new Prompt(new UserMessage(message));
        AlibabaChatClient chatClient = new AlibabaChatClient(model, null);
        AlibabaChatResponse response = chatClient.call(prompt);
        return response.getResult().getOutput().getText();
    }

    /**
     * 创建指定配置的模型实例(私有辅助方法)
     * @param modelType 模型类型
     * @param temperature 随机性参数
     * @return 配置好的模型实例
     */
    private AlibabaChatModel createModel(AlibabaModel modelType, float temperature) {
        AlibabaChatOptions options = AlibabaChatOptions.builder()
                .withModel(modelType) // 指定模型
                .withTemperature(temperature) // 调整随机性
                .withMaxTokens(2000) // 最大生成长度
                .build();
        return new AlibabaChatModel(dashscopeClient, options);
    }
}

05.2 对话状态管理

维护用户会话上下文,实现多轮连续对话,提升交互体验:

java

运行

import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import com.alibaba.cloud.ai.client.AlibabaChatClient;
import com.alibaba.cloud.ai.model.AlibabaChatResponse;
import org.springframework.ai.chat.message.AssistantMessage;
import org.springframework.ai.chat.message.Message;
import org.springframework.ai.chat.message.UserMessage;
import org.springframework.ai.chat.prompt.Prompt;

/**
 * 会话管理服务
 * 维护用户多轮对话上下文,支持连续交互
 */
@Service
public class ConversationService {

    private final AlibabaChatClient chatClient;
    // 存储会话历史:key=会话ID,value=消息列表
    private final Map<String, List<Message>> conversationHistories = new ConcurrentHashMap<>();

    public ConversationService(AlibabaChatClient chatClient) {
        this.chatClient = chatClient;
    }

    /**
     * 继续会话(多轮对话)
     * @param sessionId 会话ID(区分不同用户)
     * @param userInput 用户当前输入
     * @return AI的连续回答
     */
    public String continueConversation(String sessionId, String userInput) {
        // 获取/初始化会话历史
        List<Message> history = conversationHistories.computeIfAbsent(
                sessionId, k -> new ArrayList<>()
        );

        // 1. 添加用户最新消息到历史
        history.add(new UserMessage(userInput));

        // 2. 构建包含历史的提示词,调用AI
        Prompt prompt = new Prompt(history);
        AlibabaChatResponse response = chatClient.call(prompt);
        AssistantMessage assistantMessage = response.getResult().getOutput();

        // 3. 将AI回答添加到会话历史
        history.add(assistantMessage);

        // 4. 限制历史长度(避免token超限),只保留最近10轮
        if (history.size() > 20) { // 每轮包含用户+AI两条消息
            history.subList(0, 10).clear(); // 删除前10条(最早的5轮)
        }

        // 5. 返回AI回答
        return assistantMessage.getText();
    }

    /**
     * 清空指定会话的历史记录
     * @param sessionId 会话ID
     */
    public void clearConversation(String sessionId) {
        conversationHistories.remove(sessionId);
    }
}

05.3 嵌入式搜索

基于语义相似度的文档检索,实现 “AI + 知识库” 的智能搜索:

java

运行

import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 语义搜索服务
 * 基于文本嵌入(Embedding)实现相似度检索
 */
@Service
public class SemanticSearchService {

    private final AlibabaAiService aiService;
    // 文档仓库:存储文档内容和对应的嵌入向量
    private final List<Document> documentRepository = new ArrayList<>();

    public SemanticSearchService(AlibabaAiService aiService) {
        this.aiService = aiService;
    }

    /**
     * 索引文档(将文档存入知识库)
     * @param content 文档内容
     * @param metadata 文档元数据(如标题、分类)
     */
    public void indexDocument(String content, String metadata) {
        // 1. 生成文档的嵌入向量(语义特征)
        List<Double> embedding = aiService.getEmbedding(content);
        // 2. 存储文档和嵌入向量
        documentRepository.add(new Document(content, embedding, metadata));
    }

    /**
     * 语义搜索(根据查询词找最相似的文档)
     * @param query 用户查询词
     * @param topK 返回前K个最相似的结果
     * @return 相似度排序的搜索结果
     */
    public List<SearchResult> search(String query, int topK) {
        // 1. 生成查询词的嵌入向量
        List<Double> queryEmbedding = aiService.getEmbedding(query);

        // 2. 计算查询词与所有文档的相似度,排序后返回前K个
        return documentRepository.stream()
                .map(doc -> new SearchResult(
                        doc,
                        calculateCosineSimilarity(queryEmbedding, doc.getEmbedding())
                ))
                .sorted(Comparator.comparing(SearchResult::getSimilarity).reversed()) // 相似度降序
                .limit(topK)
                .collect(Collectors.toList());
    }

    /**
     * 计算余弦相似度(衡量两个向量的相似程度)
     * @param a 向量A
     * @param b 向量B
     * @return 相似度值(0-1之间,值越高越相似)
     */
    private double calculateCosineSimilarity(List<Double> a, List<Double> b) {
        double dotProduct = 0.0; // 点积
        double normA = 0.0; // 向量A的模长
        double normB = 0.0; // 向量B的模长

        // 遍历向量计算点积和模长
        for (int i = 0; i < a.size(); i++) {
            dotProduct += a.get(i) * b.get(i);
            normA += Math.pow(a.get(i), 2);
            normB += Math.pow(b.get(i), 2);
        }

        // 余弦相似度公式:点积 / (模长A * 模长B)
        return dotProduct / (Math.sqrt(normA) * Math.sqrt(normB));
    }

    /**
     * 文档实体类
     * 存储文档内容、嵌入向量和元数据
     */
    public static class Document {
        private String content; // 文档内容
        private List<Double> embedding; // 嵌入向量
        private String metadata; // 元数据

        public Document(String content, List<Double> embedding, String metadata) {
            this.content = content;
            this.embedding = embedding;
            this.metadata = metadata;
        }

        // getter和setter
        public String getContent() {
            return content;
        }

        public List<Double> getEmbedding() {
            return embedding;
        }

        public String getMetadata() {
            return metadata;
        }
    }

    /**
     * 搜索结果实体类
     * 包含文档和对应的相似度
     */
    public static class SearchResult {
        private Document document; // 匹配的文档
        private double similarity; // 相似度值

        public SearchResult(Document document, double similarity) {
            this.document = document;
            this.similarity = similarity;
        }

        // getter和setter
        public Document getDocument() {
            return document;
        }

        public double getSimilarity() {
            return similarity;
        }
    }
}

06

生产环境最佳实践

在生产环境中使用 Spring AI Alibaba,需要关注配置、监控和安全:

06.1 配置管理

生产环境建议通过环境变量管理敏感配置,避免硬编码:

yaml

# application.yml(生产环境配置)
spring:
  ai:
    alibaba:
      # 敏感信息从环境变量读取,避免硬编码
      access-key-id: ${ALIBABA_CLOUD_ACCESS_KEY_ID}
      access-key-secret: ${ALIBABA_CLOUD_ACCESS_KEY_SECRET}
      dashscope:
        api-key: ${ALIBABA_DASHSCOPE_API_KEY}
      # 聊天模型基础配置
      chat:
        model: qwen-plus # 默认使用平衡模型
        temperature: 0.7 # 适中的随机性
        max-tokens: 1500 # 限制回答长度,控制成本
        timeout: 30s # 请求超时时间
      # 重试配置:网络异常时自动重试
      retry:
        max-attempts: 3 # 最大重试次数
        backoff:
          initial-interval: 1000ms # 初始重试间隔
          multiplier: 2.0 # 间隔倍增系数(1s→2s→4s)
          max-interval: 10000ms # 最大重试间隔

06.2 监控告警

监控 AI 接口调用情况,及时发现异常并告警:

java

运行

import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Timer;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

/**
 * AI调用监控服务
 * 记录API调用指标,异常时触发告警
 */
@Component
public class AiMonitoringService {

    private final MeterRegistry meterRegistry; // 指标注册器(Spring Boot Actuator)
    private final AlertService alertService; // 告警服务(需自行实现)

    public AiMonitoringService(MeterRegistry meterRegistry, AlertService alertService) {
        this.meterRegistry = meterRegistry;
        this.alertService = alertService;
    }

    /**
     * 监听AI调用事件(自定义事件,需在调用AI前发布)
     * @param event AI调用事件
     */
    @EventListener
    public void handleAiCall(AiCallEvent event) {
        // 开始计时:记录API调用耗时
        Timer.Sample sample = Timer.start(meterRegistry);

        try {
            // 执行实际的AI调用逻辑
            String result = performAiCall(event);

            // 记录成功调用指标:标签包含模型、操作类型、是否成功
            sample.stop(Timer.builder("ai.api.calls")
                    .tag("model", event.getModel())
                    .tag("operation", event.getOperation())
                    .tag("success", "true")
                    .register(meterRegistry));
        } catch (Exception e) {
            // 记录失败调用指标
            sample.stop(Timer.builder("ai.api.calls")
                    .tag("model", event.getModel())
                    .tag("operation", event.getOperation())
                    .tag("success", "false")
                    .register(meterRegistry));

            // 触发告警:短信/邮件/钉钉通知
            alertService.sendAiFailureAlert(event, e);
        }
    }

    /**
     * 执行AI调用(实际业务逻辑)
     * @param event 调用事件
     * @return AI返回结果
     */
    private String performAiCall(AiCallEvent event) {
        // 此处为示例,实际需调用对应的AI服务
        return "AI response";
    }

    /**
     * 自定义AI调用事件
     * 传递调用相关的上下文信息
     */
    public static class AiCallEvent {
        private String model; // 调用的模型
        private String operation; // 操作类型(chat/code/review)

        // 构造函数、getter和setter
        public AiCallEvent(String model, String operation) {
            this.model = model;
            this.operation = operation;
        }

        public String getModel() {
            return model;
        }

        public String getOperation() {
            return operation;
        }
    }

    /**
     * 告警服务接口(示例)
     */
    public interface AlertService {
        void sendAiFailureAlert(AiCallEvent event, Exception e);
    }
}

06.3 安全防护

防止 API 滥用、内容违规,保障 AI 服务安全:

java

运行

import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;

/**
 * AI安全防护服务
 * 验证请求合法性,防止滥用和违规
 */
@Component
public class AiSecurityService {

    /**
     * 验证AI请求的合法性
     * @param apiKey 调用方的API密钥
     * @param requestId 请求唯一标识
     * @return true=合法,false=非法
     */
    public boolean validateAiRequest(String apiKey, String requestId) {
        // 1. 验证API密钥是否有效
        if (!isValidApiKey(apiKey)) {
            return false;
        }

        // 2. 检查请求频率是否超限(防止滥用)
        if (isRateLimited(requestId)) {
            return false;
        }

        // 3. 检查请求内容是否包含敏感信息(防止违规)
        if (containsSensitiveContent(requestId)) {
            return false;
        }

        // 所有检查通过
        return true;
    }

    /**
     * 验证API密钥有效性
     * @param apiKey 调用方密钥
     * @return true=有效
     */
    private boolean isValidApiKey(String apiKey) {
        // 实际业务中:从数据库/配置中心查询合法密钥列表
        return "valid-api-key".equals(apiKey);
    }

    /**
     * 检查请求频率是否超限(缓存结果,避免重复计算)
     * @param requestId 请求唯一标识(如用户ID+时间戳)
     * @return true=超限
     */
    @Cacheable(value = "ai-ratelimit", key = "#requestId")
    public boolean isRateLimited(String requestId) {
        // 示例逻辑:模拟每小时最多100次请求
        // 实际业务中:可使用Redis实现分布式限流
        long currentHour = System.currentTimeMillis() / 3600000;
        long requestCount = getRequestCount(requestId, currentHour);
        return requestCount > 100;
    }

    /**
     * 检查请求内容是否包含敏感信息
     * @param requestId 请求ID(关联请求内容)
     * @return true=包含敏感内容
     */
    private boolean containsSensitiveContent(String requestId) {
        // 实际业务中:调用内容安全接口检测敏感词
        String requestContent = getRequestContent(requestId);
        return requestContent.contains("敏感信息");
    }

    /**
     * 清除指定请求的限流缓存
     * @param requestId 请求ID
     */
    @CacheEvict(value = "ai-ratelimit", key = "#requestId")
    public void clearRateLimitCache(String requestId) {
        // 空方法,仅用于触发缓存清除
    }

    // 以下为示例辅助方法(实际需根据业务实现)
    private long getRequestCount(String requestId, long currentHour) {
        return 0;
    }

    private String getRequestContent(String requestId) {
        return "";
    }
}

07

成本优化策略

合理使用 AI 服务,在保证效果的前提下降低成本:

07.1 模型选择策略

根据请求内容长度和业务优先级,自动选择性价比最高的模型:

java

运行

import org.springframework.stereotype.Service;

/**
 * 成本优化服务
 * 根据业务场景自动选择最优的AI模型,平衡成本和效果
 */
@Service
public class CostOptimizationService {

    /**
     * 选择最优模型
     * @param request 用户请求内容
     * @param priority 优先级(speed=速度优先/cost=成本优先/quality=质量优先)
     * @return 推荐的模型名称
     */
    public String selectOptimalModel(String request, String priority) {
        // 获取请求内容长度
        int requestLength = request.length();

        // 根据优先级和长度选择模型
        switch (priority) {
            case "speed":
                // 速度优先:短请求用极速模型,长请求用平衡模型
                return requestLength < 1000 ? "qwen-turbo" : "qwen-plus";
            case "cost":
                // 成本优先:按长度阶梯选择模型
                if (requestLength < 500) {
                    return "qwen-turbo"; // 最便宜的极速模型
                } else if (requestLength < 2000) {
                    return "qwen-plus"; // 平衡模型
                } else {
                    return "qwen-max"; // 高质量模型(仅长请求使用)
                }
            case "quality":
                // 质量优先:固定使用最高质量模型
                return "qwen-max";
            default:
                // 默认使用平衡模型
                return "qwen-plus";
        }
    }
}

07.2 缓存策略

缓存高频请求的 AI 回答,避免重复调用,降低成本:

java

运行

import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

/**
 * 缓存型AI服务
 * 缓存高频请求的响应,减少重复调用,降低成本
 */
@Service
public class CachedAiService {

    private final AlibabaAiService aiService;

    public CachedAiService(AlibabaAiService aiService) {
        this.aiService = aiService;
    }

    /**
     * 获取AI响应(带缓存)
     * @param request 用户请求内容(作为缓存Key)
     * @return AI响应(优先从缓存获取)
     */
    @Cacheable(value = "ai-responses", key = "#request")
    public String getAiResponse(String request) {
        // 缓存未命中时,调用实际的AI服务
        return aiService.chat(request);
    }

    /**
     * 清除指定请求的缓存
     * @param request 请求内容
     */
    @CacheEvict(value = "ai-responses", key = "#request")
    public void evictCachedResponse(String request) {
        // 空方法,仅用于触发缓存清除
    }

    /**
     * 定时清除所有缓存(每小时执行一次)
     * 避免缓存数据过期,保证回答时效性
     */
    @Scheduled(fixedRate = 3600000) // 3600000ms = 1小时
    @CacheEvict(value = "ai-responses", allEntries = true)
    public void evictAllCachedResponses() {
        // 空方法,仅用于定时清除缓存
    }
}

08

总结

Spring AI Alibaba为 Java 开发者打通了接入阿里云大模型的便捷通道,核心价值体现在:

快速集成:仅需几行配置和代码,就能将强大的 AI 能力接入 Spring Boot 应用;灵活使用:支持聊天、代码生成、文档处理等多场景,适配不同业务需求;企业级保障:内置错误处理、重试、监控机制,满足生产环境的稳定性要求;成本可控:通

过多模型切换、缓存策略等手段,有效控制 AI 使用成本;持续演进:紧跟阿里云大模型的更新节奏,持续适配新功能。

随着 AI 技术的普及,掌握Spring AI Alibaba这类集成工具,已经成为 Java 开发者的核心竞争力之一。它不仅能提升开发效率,更能帮助我们把 AI 能力真正落地到业务中,打造智能化的应用系统。

如果大家对某个功能点想深入探讨,欢迎在评论区留言交流。记住,技术的价值不在于复杂度,而在于能否解决实际问题 ——Spring AI Alibaba正是这样一款能让 AI 技术服务于业务的实用工具

基本 文件 流程 错误 SQL 调试
  1. 请求信息 : 2026-06-29 17:04:01 HTTP/1.1 GET : https://www.yeyulingfeng.com/a/813987.html
  2. 运行时间 : 0.099331s [ 吞吐率:10.07req/s ] 内存消耗:4,871.41kb 文件加载:145
  3. 缓存信息 : 0 reads,0 writes
  4. 会话信息 : SESSION_ID=1e4a41f143c372c19e41de030e09ba08
  1. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/public/index.php ( 0.79 KB )
  2. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/autoload.php ( 0.17 KB )
  3. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/composer/autoload_real.php ( 2.49 KB )
  4. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/composer/platform_check.php ( 0.90 KB )
  5. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/composer/ClassLoader.php ( 14.03 KB )
  6. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/composer/autoload_static.php ( 6.05 KB )
  7. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-helper/src/helper.php ( 8.34 KB )
  8. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-validate/src/helper.php ( 2.19 KB )
  9. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/ralouphie/getallheaders/src/getallheaders.php ( 1.60 KB )
  10. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/helper.php ( 1.47 KB )
  11. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/stubs/load_stubs.php ( 0.16 KB )
  12. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Exception.php ( 1.69 KB )
  13. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-container/src/Facade.php ( 2.71 KB )
  14. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/symfony/deprecation-contracts/function.php ( 0.99 KB )
  15. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/symfony/polyfill-mbstring/bootstrap.php ( 8.26 KB )
  16. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/symfony/polyfill-mbstring/bootstrap80.php ( 9.78 KB )
  17. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/symfony/var-dumper/Resources/functions/dump.php ( 1.49 KB )
  18. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-dumper/src/helper.php ( 0.18 KB )
  19. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/symfony/var-dumper/VarDumper.php ( 4.30 KB )
  20. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/guzzlehttp/guzzle/src/functions_include.php ( 0.16 KB )
  21. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/guzzlehttp/guzzle/src/functions.php ( 5.54 KB )
  22. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/App.php ( 15.30 KB )
  23. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-container/src/Container.php ( 15.76 KB )
  24. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/psr/container/src/ContainerInterface.php ( 1.02 KB )
  25. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/app/provider.php ( 0.19 KB )
  26. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Http.php ( 6.04 KB )
  27. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-helper/src/helper/Str.php ( 7.29 KB )
  28. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Env.php ( 4.68 KB )
  29. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/app/common.php ( 0.03 KB )
  30. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/helper.php ( 18.78 KB )
  31. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Config.php ( 5.54 KB )
  32. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/alipay.php ( 3.59 KB )
  33. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/facade/Env.php ( 1.67 KB )
  34. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/app.php ( 0.95 KB )
  35. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/cache.php ( 0.78 KB )
  36. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/console.php ( 0.23 KB )
  37. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/cookie.php ( 0.56 KB )
  38. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/database.php ( 2.48 KB )
  39. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/filesystem.php ( 0.61 KB )
  40. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/lang.php ( 0.91 KB )
  41. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/log.php ( 1.35 KB )
  42. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/middleware.php ( 0.19 KB )
  43. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/route.php ( 1.89 KB )
  44. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/session.php ( 0.57 KB )
  45. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/trace.php ( 0.34 KB )
  46. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/config/view.php ( 0.82 KB )
  47. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/app/event.php ( 0.25 KB )
  48. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Event.php ( 7.67 KB )
  49. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/app/service.php ( 0.13 KB )
  50. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/app/AppService.php ( 0.26 KB )
  51. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Service.php ( 1.64 KB )
  52. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Lang.php ( 7.35 KB )
  53. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/lang/zh-cn.php ( 13.70 KB )
  54. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/initializer/Error.php ( 3.31 KB )
  55. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/initializer/RegisterService.php ( 1.33 KB )
  56. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/services.php ( 0.14 KB )
  57. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/service/PaginatorService.php ( 1.52 KB )
  58. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/service/ValidateService.php ( 0.99 KB )
  59. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/service/ModelService.php ( 2.04 KB )
  60. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-trace/src/Service.php ( 0.77 KB )
  61. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Middleware.php ( 6.72 KB )
  62. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/initializer/BootService.php ( 0.77 KB )
  63. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/Paginator.php ( 11.86 KB )
  64. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-validate/src/Validate.php ( 63.20 KB )
  65. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/Model.php ( 23.55 KB )
  66. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/model/concern/Attribute.php ( 21.05 KB )
  67. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/model/concern/AutoWriteData.php ( 4.21 KB )
  68. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/model/concern/Conversion.php ( 6.44 KB )
  69. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/model/concern/DbConnect.php ( 5.16 KB )
  70. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/model/concern/ModelEvent.php ( 2.33 KB )
  71. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/model/concern/RelationShip.php ( 28.29 KB )
  72. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-helper/src/contract/Arrayable.php ( 0.09 KB )
  73. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-helper/src/contract/Jsonable.php ( 0.13 KB )
  74. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/model/contract/Modelable.php ( 0.09 KB )
  75. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Db.php ( 2.88 KB )
  76. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/DbManager.php ( 8.52 KB )
  77. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Log.php ( 6.28 KB )
  78. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Manager.php ( 3.92 KB )
  79. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/psr/log/src/LoggerTrait.php ( 2.69 KB )
  80. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/psr/log/src/LoggerInterface.php ( 2.71 KB )
  81. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Cache.php ( 4.92 KB )
  82. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/psr/simple-cache/src/CacheInterface.php ( 4.71 KB )
  83. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-helper/src/helper/Arr.php ( 16.63 KB )
  84. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/cache/driver/File.php ( 7.84 KB )
  85. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/cache/Driver.php ( 9.03 KB )
  86. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/contract/CacheHandlerInterface.php ( 1.99 KB )
  87. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/app/Request.php ( 0.09 KB )
  88. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Request.php ( 55.78 KB )
  89. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/app/middleware.php ( 0.25 KB )
  90. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Pipeline.php ( 2.61 KB )
  91. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-trace/src/TraceDebug.php ( 3.40 KB )
  92. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/middleware/SessionInit.php ( 1.94 KB )
  93. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Session.php ( 1.80 KB )
  94. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/session/driver/File.php ( 6.27 KB )
  95. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/contract/SessionHandlerInterface.php ( 0.87 KB )
  96. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/session/Store.php ( 7.12 KB )
  97. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Route.php ( 23.73 KB )
  98. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/route/RuleName.php ( 5.75 KB )
  99. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/route/Domain.php ( 2.53 KB )
  100. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/route/RuleGroup.php ( 22.43 KB )
  101. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/route/Rule.php ( 26.95 KB )
  102. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/route/RuleItem.php ( 9.78 KB )
  103. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/route/app.php ( 3.94 KB )
  104. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/facade/Route.php ( 4.70 KB )
  105. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/route/dispatch/Controller.php ( 4.74 KB )
  106. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/route/Dispatch.php ( 10.44 KB )
  107. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/app/controller/Index.php ( 9.87 KB )
  108. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/app/BaseController.php ( 2.05 KB )
  109. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/facade/Db.php ( 0.93 KB )
  110. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/connector/Mysql.php ( 5.44 KB )
  111. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/PDOConnection.php ( 52.47 KB )
  112. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/Connection.php ( 8.39 KB )
  113. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/ConnectionInterface.php ( 4.57 KB )
  114. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/builder/Mysql.php ( 16.58 KB )
  115. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/Builder.php ( 24.06 KB )
  116. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/BaseBuilder.php ( 27.50 KB )
  117. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/Query.php ( 15.71 KB )
  118. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/BaseQuery.php ( 45.13 KB )
  119. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/concern/TimeFieldQuery.php ( 7.43 KB )
  120. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/concern/AggregateQuery.php ( 3.26 KB )
  121. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/concern/ModelRelationQuery.php ( 20.07 KB )
  122. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/concern/ParamsBind.php ( 3.66 KB )
  123. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/concern/ResultOperation.php ( 7.01 KB )
  124. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/concern/WhereQuery.php ( 19.37 KB )
  125. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/concern/JoinAndViewQuery.php ( 7.11 KB )
  126. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/concern/TableFieldInfo.php ( 2.63 KB )
  127. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-orm/src/db/concern/Transaction.php ( 2.77 KB )
  128. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/log/driver/File.php ( 5.96 KB )
  129. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/contract/LogHandlerInterface.php ( 0.86 KB )
  130. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/log/Channel.php ( 3.89 KB )
  131. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/event/LogRecord.php ( 1.02 KB )
  132. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-helper/src/Collection.php ( 16.47 KB )
  133. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/facade/View.php ( 1.70 KB )
  134. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/View.php ( 4.39 KB )
  135. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/app/controller/Es.php ( 3.30 KB )
  136. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Response.php ( 8.81 KB )
  137. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/response/View.php ( 3.29 KB )
  138. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/Cookie.php ( 6.06 KB )
  139. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-view/src/Think.php ( 8.38 KB )
  140. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/framework/src/think/contract/TemplateHandlerInterface.php ( 1.60 KB )
  141. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-template/src/Template.php ( 46.61 KB )
  142. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-template/src/template/driver/File.php ( 2.41 KB )
  143. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-template/src/template/contract/DriverInterface.php ( 0.86 KB )
  144. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/runtime/temp/c935550e3e8a3a4c27dd94e439343fdf.php ( 31.50 KB )
  145. /yingpanguazai/ssd/ssd1/www/wwww.yeyulingfeng.com/vendor/topthink/think-trace/src/Html.php ( 4.42 KB )
  1. CONNECT:[ UseTime:0.000484s ] mysql:host=127.0.0.1;port=3306;dbname=wenku;charset=utf8mb4
  2. SHOW FULL COLUMNS FROM `fenlei` [ RunTime:0.000864s ]
  3. SELECT * FROM `fenlei` WHERE `fid` = 0 [ RunTime:0.000346s ]
  4. SELECT * FROM `fenlei` WHERE `fid` = 63 [ RunTime:0.000271s ]
  5. SHOW FULL COLUMNS FROM `set` [ RunTime:0.000611s ]
  6. SELECT * FROM `set` [ RunTime:0.000260s ]
  7. SHOW FULL COLUMNS FROM `article` [ RunTime:0.000763s ]
  8. SELECT * FROM `article` WHERE `id` = 813987 LIMIT 1 [ RunTime:0.000608s ]
  9. UPDATE `article` SET `lasttime` = 1782723841 WHERE `id` = 813987 [ RunTime:0.007330s ]
  10. SELECT * FROM `fenlei` WHERE `id` = 64 LIMIT 1 [ RunTime:0.000323s ]
  11. SELECT * FROM `article` WHERE `id` < 813987 ORDER BY `id` DESC LIMIT 1 [ RunTime:0.000541s ]
  12. SELECT * FROM `article` WHERE `id` > 813987 ORDER BY `id` ASC LIMIT 1 [ RunTime:0.000436s ]
  13. SELECT * FROM `article` WHERE `id` < 813987 ORDER BY `id` DESC LIMIT 10 [ RunTime:0.003077s ]
  14. SELECT * FROM `article` WHERE `id` < 813987 ORDER BY `id` DESC LIMIT 10,10 [ RunTime:0.002854s ]
  15. SELECT * FROM `article` WHERE `id` < 813987 ORDER BY `id` DESC LIMIT 20,10 [ RunTime:0.000709s ]
0.101004s