用来查数据的网站怎么建设最新网页版传奇游戏

news/2025/10/2 19:49:44/文章来源:
用来查数据的网站怎么建设,最新网页版传奇游戏,做网站费用上海,报班学网站开发价格一、axios 简介 axios 是一个基于 Promise 的 HTTP 客户端#xff0c;可用于浏览器和 Node.js 环境#xff0c;支持以下特性#xff1a; 发送 HTTP 请求#xff08;GET/POST/PUT/DELETE 等#xff09; 拦截请求和响应 自动转换 JSON 数据 取消请求 并发请求处理 二…一、axios 简介 axios 是一个基于 Promise 的 HTTP 客户端可用于浏览器和 Node.js 环境支持以下特性 发送 HTTP 请求GET/POST/PUT/DELETE 等 拦截请求和响应 自动转换 JSON 数据 取消请求 并发请求处理 二、安装 1. 使用 npm/yarn npm install axios# 或yarn add axios 2. 浏览器直接引入 script srchttps://cdn.jsdelivr.net/npm/axios/dist/axios.min.js/script 三、基本用法 1. 发送 GET 请求 axios.get(https://api.example.com/data)  .then(response  {    console.log(response.data); // 响应数据  })  .catch(error  {    console.error(请求失败:, error);  }); 2. 发送 POST 请求​​​​​​​ axios.post(https://api.example.com/data, {    name: John,    age: 30  })  .then(response  {    console.log(response.data);  }); 3. 使用 async/await​​​​​​​ async function fetchData() {  try {    const response  await axios.get(https://api.example.com/data);    console.log(response.data);  } catch (error) {    console.error(error);  }} 四、请求配置 1. 全局默认配置​​​​​​​ axios.defaults.baseURL  https://api.example.com;axios.defaults.headers.common[Authorization]  Bearer token123;axios.defaults.timeout  5000; // 超时时间 2. 单个请求配置​​​​​​​ axios.get(/data, {  params: { id: 1 }, // 查询参数  headers: { X-Custom-Header: value }}); 五、响应结构 响应对象包含以下字段​​​​​​​ {  data: {},       // 服务器返回的数据  status: 200,    // HTTP 状态码  statusText: OK,  headers: {},     // 响应头  config: {},      // 请求配置  request: {}      // 原始的 XMLHttpRequest 对象浏览器} 六、错误处理 1. 通用错误捕获​​​​​​​ axios.get(/data)  .catch(error  {    if (error.response) {      // 服务器返回了非 2xx 状态码      console.log(error.response.status);      console.log(error.response.data);    } else if (error.request) {      // 请求已发送但无响应      console.log(No response received);    } else {      // 请求配置错误      console.log(Error:, error.message);    }  }); 2. 全局错误拦截​​​​​​​ axios.interceptors.response.use(  response  response,  error  {    // 统一处理错误    return Promise.reject(error);  }); 七、高级功能 1. 并发请求​​​​​​​ const request1 axios.get(/data1);const request2 axios.get(/data2);axios.all([request1, request2])  .then(axios.spread((res1, res2) {    console.log(res1.data, res2.data);  })); 2. 取消请求​​​​​​​ const source axios.CancelToken.source();axios.get(/data, {  cancelToken: source.token}).catch(thrown  {  if (axios.isCancel(thrown)) {    console.log(请求被取消:, thrown.message);  }});// 取消请求source.cancel(用户取消操作); 3. 请求拦截器​​​​​​​ axios.interceptors.request.use(  config  {    // 在发送请求前做些什么如添加 token    config.headers.Authorization  Bearer token;    return config;  },  error  {    return Promise.reject(error);  }); 八、常见场景示例 1. 上传文件​​​​​​​ const formData  new FormData();formData.append(file, fileInput.files[0]);axios.post(/upload, formData, {  headers: { Content-Type: multipart/form-data }}); 2. 下载文件​​​​​​​ axios.get(/download, { responseType: blob })  .then(response  {    const url  window.URL.createObjectURL(new Blob([response.data]));    const link  document.createElement(a);    link.href  url;    link.setAttribute(download, file.pdf);    document.body.appendChild(link);    link.click();  }); 九、最佳实践 封装 axios创建 api.js 统一管理接口 环境区分通过 .env 文件配置不同环境的 baseURL 安全防护结合 CSRF Token 或 JWT 进行身份验证 性能优化合理设置超时时间使用缓存策略 示例: 以下是使用 Axios 和 Spring Boot 实现前后端分离的登录功能的步骤详解 1. 后端实现Spring Boot 1.1 添加依赖 在 pom.xml 中添加必要依赖​​​​​​​ !-- Spring Web --dependency    groupIdorg.springframework.boot/groupId    artifactIdspring-boot-starter-web/artifactId/dependency!-- 数据库以 JPA H2 为例 --dependency    groupIdorg.springframework.boot/groupId    artifactIdspring-boot-starter-data-jpa/artifactId/dependencydependency    groupIdcom.h2database/groupId    artifactIdh2/artifactId    scoperuntime/scope/dependency!-- 密码加密 --dependency    groupIdorg.springframework.security/groupId    artifactIdspring-security-crypto/artifactId/dependency 1.2 配置数据库和加密 在 application.properties 中配置​​​​​​​ spring.datasource.urljdbc:h2:mem:testdbspring.datasource.driverClassNameorg.h2.Driverspring.h2.console.enabledtruespring.jpa.hibernate.ddl-autoupdate 1.3 创建用户实体类​​​​​​​ Entitypublic class User {    Id    GeneratedValue(strategy GenerationType.IDENTITY)    private Long id;    Column(unique true)    private String username;    private String password;    // Getters and Setters} 1.4 创建 Repository​​​​​​​ public interface UserRepository extends JpaRepositoryUser, Long {    User findByUsername(String username);} 1.5 创建 Service 层​​​​​​​ Servicepublic class AuthService {    Autowired    private UserRepository userRepository;    Autowired    private BCryptPasswordEncoder passwordEncoder;    public boolean authenticate(String username, String password) {        User user userRepository.findByUsername(username);        return user ! null  passwordEncoder.matches(password, user.getPassword());    }} 1.6 创建 Controller​​​​​​​ RestControllerRequestMapping(/api/auth)CrossOrigin(origins  http://localhost:3000) // 允许前端跨域请求public class AuthController {    Autowired    private AuthService authService;    PostMapping(/login)    public ResponseEntity? login(RequestBody LoginRequest loginRequest) {        boolean isValid authService.authenticate(            loginRequest.getUsername(),            loginRequest.getPassword()        );        if (isValid) {            return ResponseEntity.ok().body(登录成功);        } else {            return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(用户名或密码错误);        }    }}// 登录请求DTOpublic class LoginRequest {    private String username;    private String password;    // Getters and Setters} 2. 前端实现使用 Axios 2.1 安装 Axios npm install axios 2.2 登录组件示例React​​​​​​​ import React, { useState } from react;import axios from axios;const LoginForm  () {    const [username, setUsername]  useState();    const [password, setPassword]  useState();    const [error, setError]  useState();    const handleSubmit  async (e) {        e.preventDefault();        try {            const response  await axios.post(                http://localhost:8080/api/auth/login,                { username, password },                { headers: { Content-Type: application/json } }            );            if (response.status  200) {                alert(登录成功);                // 跳转到主页或处理登录状态            }        } catch (err) {            if (err.response  err.response.status  401) {                setError(用户名或密码错误);            } else {                setError(登录失败请重试);            }        }    };    return (        form onSubmit{handleSubmit}            input                typetext                value{username}                onChange{(e)  setUsername(e.target.value)}                placeholder用户名            /            input                typepassword                value{password}                onChange{(e)  setPassword(e.target.value)}                placeholder密码            /            {error  div classNameerror{error}/div}            button typesubmit登录/button        /form    );};export default LoginForm; 3. 测试流程 启动 Spring Boot 应用 mvn spring-boot:run 启动前端应用 npm start 在登录页面输入用户名和密码验证是否返回正确响应。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/925248.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

2025 年脱硫剂厂家 TOP 企业品牌推荐排行榜,氧化铁,羟基氧化铁,常温氧化铁,沼气,天然气,煤气,煤层气,液化气,二氧化碳,氨气脱硫剂公司推荐

在当前工业快速发展的背景下,气体脱硫成为保障生产安全、减少环境污染的关键环节。无论是天然气、沼气行业,还是甲醇、化肥生产领域,都对脱硫剂的性能有着极高要求。优质的脱硫剂不仅需要具备高脱硫精度,还要有稳定…

网站内部优化是什么创建网站有免费的吗

3月29日,以“新零售、新流量、新风口”为主题的2024喜尔康浙江省经销商培训会在喜尔康总部正式开始举办。活动旨在智能新时代赋能经销商伙伴,通过抓住行业智能化风口,实现喜尔康与经销商的共赢,决胜未来新零售商机。 喜尔康始终致…

2025雨棚生产厂家 TOP 企业品牌推荐排行榜,西安,陕西,西北推拉雨棚,推拉,移动,活动,户外,电动伸缩雨棚推荐这十家公司!

引言在遮阳遮雨行业快速发展的当下,雨棚作为工业、商业、体育休闲等多个领域的重要设施,市场需求持续增长。然而,当前雨棚生产厂家数量众多,行业整体呈现出良莠不齐的态势。部分厂家缺乏核心技术,生产的雨棚在结构…

百度找不到我的网站了品牌网站建设渠道

在Spring Boot项目中预防CSRF攻击通常涉及利用Spring Security框架提供的内置支持。Spring Security已经为CSRF提供了默认的防护措施,但根据应用的特定需求,可能需要进行一些配置调整或扩展。下面是一系列步骤和建议,用于在Spring Boot项目中…

建设银行辽宁招聘网站新公司怎么建立自己的网站

+我V hezkz17进数字音频系统研究开发交流答疑群(课题组) 一 音频4A算法是? 音频4A算法是指自动增益控制(Automatic Gain Control, AGC)、自动噪声抑制(Automatic Noise Suppression, ANS)和自动回声消除(Automatic Echo Cancellation, AEC),主动降噪ANC(Active Noi…

2025 年木工机械设备厂家 TOP 企业品牌推荐排行榜,深度剖析木工机械设备推荐这十家公司!

引言在木工行业蓬勃发展的当下,木工机械设备的质量与性能对生产效率和产品质量起着决定性作用。随着市场需求的日益多元化和精细化,木工企业对机械设备的要求也水涨船高,不仅期望设备具备高精度、高稳定性,还希望其…

python语言语音控制科学计算器程序代码3QZQ

import tkinter as tkfrom tkinter import scrolledtext, messagebox, filedialog, ttkimport pyaudioimport threadingfrom vosk import Model, KaldiRecognizerimport osimport jsonfrom pygame import mixerimport …

Python语言自动玩游戏的消消乐游戏程序代码3QZQ

import pygameimport sysimport randomimport timeimport mathfrom pygame.locals import * # 初始化pygamepygame.init() # 游戏常量SCREEN_WIDTH = 900SCREEN_HEIGHT = 700GRID_SIZE = 8CELL_SIZE = 60MARGIN = 50FP…

希爱力双效片副作用seo做的最好的十个网站

<!DOCTYPE html> <html><head><meta charset"UTF-8"><title>音频引入</title></head><body><!--audio:在网页中引入音频IE8以及之前版本不支持属性名和属性值一样&#xff0c;可以只写属性名src属性:指定音频文件…

python语言手势控制音乐播放器代码QZQ

# pip install opencv-python mediapipe pygame numpy pillow# pip install pyinstaller# pyinstaller --onefile --icon=1.ico main.py import cv2import mediapipe as mpimport pygameimport osimport numpy as npim…

地方门户网站建设方案秦皇岛市海港区建设局网站

文章目录 1、什么是DES2、DES的基本概念3、DES的加密流程4、DES算法步骤详解4.1 初始置换(Initial Permutation&#xff0c;IP置换)4.2 加密轮次4.3 F轮函数4.3.1 拓展R到48位4.3.2 子密钥K的生成4.3.3 当前轮次的子密钥与拓展的48位R进行异或运算4.3.4 S盒替换&#xff08;Sub…

做网站关键词加到什么位置企业网企业网站制作

夏天天气炎热&#xff0c;电脑机箱内温度也较高&#xff0c;温度过高会影响电脑性能出现死机等问题&#xff0c;甚至影响硬件寿命。所以给机箱装风扇来散热是非常重要的。那么&#xff0c;机箱风扇怎么装合理呢?机箱风扇的电源线怎么接呢?下面分享一下机箱风...夏天天气炎热&…

新服务器做网站如何配置聊天直播软件开发

简介上篇文章我们介绍了Spring boot的fat jar/war包&#xff0c;jar/war包都可以使用 java -jar 命令来运行&#xff0c;而maven也提供了mvn spring-boot:run 命令来运行应用程序&#xff0c;下面我们看看两者有什么不同。Spring Boot Maven Plugin上篇文章我们提到了Spring Bo…

Python语言自动玩游戏的数字拼图游戏程序代码ZXQMQZQ

import pygameimport sysimport randomimport timefrom queue import PriorityQueuefrom pygame.locals import * # 初始化pygamepygame.init() # 游戏常量WIDTH, HEIGHT = 400, 500GRID_SIZE = 3TILE_SIZE = 100MARGI…

如何找出集合的两个子集使得和相等?

给定一个大小为 \(n\) 的整数集合 \(S\subseteq [0,V]\),找出他的两个子集 \(s_1,s_2\) 使得其元素的和相等,或报告无解。对于所有的 \(T\subseteq S\),\(T\) 中元素的和满足 \(0\le \sum_{x\in T} x\le V|T|\)。 所…

Python语言自动玩游戏的俄罗斯方块游戏程序代码QZQ

import randomimport mathimport sysimport numpy as npimport pygame # -------------------- 常量 --------------------CELL = 30 # 像素COLS, ROWS = 10, 20SCREEN_W, SCREEN_H = 20 * CELL, ROWS * CELLFPS = 60…

Spring AI(七)Spring AI 的RAG搭建集合火山向量模型+阿里云Tair(企业版)

Spring AI(七)Spring AI 的RAG搭建集合火山向量模型+阿里云Tair(企业版)pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-fami…

sw网站建设合肥网站seo服务

前言-什么是数据幻觉&#xff1f;它到底有什么危害呢 我们直接来举例&#xff1a; 我是金银花一区的&#xff0c;附近有什么小学&#xff1f; 此时RAG带出如下信息&#xff1a; 金银花小区一区、二区、三区附近教育资源有&#xff1a;银树大学、建设小学金银花校区、金树高…

Python语言自动玩游戏的数字拼图游戏程序代码QZQ

import sysimport randomimport pygame # 初始化pygamepygame.init() # 游戏常量SIZE = 3 # 3x3 拼图CELL = 120 # 每个格子的像素大小WIDTH = CELL * SIZEHEIGHT = CELL * SIZEEMPTY = SIZE * SIZE # 空格的表示值…

温州网站开发培训北京网站制作外包

http://blog.csdn.net/dandelion_gong/article/details/51673085 Unix下可用的I/O模型一共有五种&#xff1a;阻塞I/O 、非阻塞I/O 、I/O复用 、信号驱动I/O 、异步I/O。此处我们主要介绍第三种I/O符复用。 I/O复用的功能&#xff1a;如果一个或多个I/O条件满足&#xff08;输…