Vue的Ajax请求-axios、前后端分离练习

Vue的Ajax请求

axios简介

  • ​ Axios,是Web数据交互方式,是一个基于promise [5]的网络请求库,作用于node.js和浏览器中,它是 isomorphic 的(即同一套代码可以运行在浏览器和node.js中)。在服务端它使用原生node.js http模块, 而在客户端 (浏览端) 则使用XMLHttpRequest。 [2]
  • axios :不是vue的插件,可以在任何地方使用,推荐

axios的使用方式

1、使用npm安装

npm install axios

2、使用cdn链接axios

<script src="https://unpkg.com/axios/dist/axios.min.js"></script>

axios的语法

axios({
 // 请求方式
 method: 'post',
 url: 'api',
 // 传递参数
 data: obj,
 // 设置请求头信息
 headers: {
  key: value
 },
 responseType: 'json'
}).then(response => {
 // 请求成功
 let res = response.data;
 console.log(res);
}).catch(error => {
 // 请求失败,
 console.log(error);
});

axios案例

1、数据准备

  • Student.json
[
    {
        "sid":1,
        "name":"mary",
        "age":18,
        "gender":"女"
    },
    {
        "sid":2,
        "name":"lucy",
        "age":18,
        "gender":"女"
    },
    {
        "sid":3,
        "name":"tom",
        "age":19,
        "gender":"男"
    },
    {
        "sid":4,
        "name":"jack",
        "age":18,
        "gender":"男"
    }
]

2、初使用问题

  • VScode

在这里插入图片描述

  • 解决办法

在这里插入图片描述

在这里插入图片描述

3、axios 发送get请求

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="js/vue.global.js"></script>
    <script src="js/axios.min.js"></script>
</head>
<body>
    <div id="app">
        <table cellspacing="0" cellpadding="0" border="1" width="500" align="center">
            <tr>
                <th>学号</th>
                <th>姓名</th>
                <th>年龄</th>
                <th>性别</th>
            </tr>
            <tr v-for="stu in stus">
                <td>{{stu.sid}}</td>
                <td>{{stu.name}}</td>
                <td>{{stu.age}}</td>
                <td>{{stu.gender}}</td>
            </tr>
        </table>
    </div>
    <script>
        const vueApp = Vue.createApp({
            data:function(){
                return {
                    stus:""
                }
            },
            created:function(){
                //发送ajax请求,将得到的数据赋值给stus
                axios({
                    method:"get",
                    url:"json/students.json"
                }).then(resp => {
                    this.stus = resp.data;
                });
            }
        });

        vueApp.mount("#app");
    </script>
</body>
</html>
  • 或者
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="js/vue.global.js"></script>
    <script src="js/axios.min.js"></script>
</head>
<body>
    <div id="app">
        <table cellspacing="0" cellpadding="0" border="1" width="500" align="center">
            <tr>
                <th>学号</th>
                <th>姓名</th>
                <th>年龄</th>
                <th>性别</th>
            </tr>
            <tr v-for="stu in stus">
                <td>{{stu.sid}}</td>
                <td>{{stu.name}}</td>
                <td>{{stu.age}}</td>
                <td>{{stu.gender}}</td>
            </tr>
        </table>
    </div>
    <script>
        const vueApp = Vue.createApp({
            data:function(){
                return {
                    stus:""
                }
            },
            created:function(){
                //发送ajax请求,将得到的数据赋值给stus
                axios.get("json/students.json").then(resp => {
                    this.stus = resp.data;
                });
            }
        });

        vueApp.mount("#app");
    </script>
</body>
</html>

4、axios 发送post请求

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="js/vue.global.js"></script>
    <script src="js/axios.min.js"></script>
</head>
<body>
    <div id="app">
        <table cellspacing="0" cellpadding="0" border="1" width="500" align="center">
            <tr>
                <th>学号</th>
                <th>姓名</th>
                <th>年龄</th>
                <th>性别</th>
            </tr>
            <tr v-for="stu in stus">
                <td>{{stu.sid}}</td>
                <td>{{stu.name}}</td>
                <td>{{stu.age}}</td>
                <td>{{stu.gender}}</td>
            </tr>
        </table>
    </div>
    <script>
        const vueApp = Vue.createApp({
            data:function(){
                return {
                    stus:""
                }
            },
            created:function(){
                //发送ajax请求,将得到的数据赋值给stus
                axios({
                    method:"post",
                    url:"json/students.json"
                }).then(resp => {
                    this.stus = resp.data;
                });
            }
        });

        vueApp.mount("#app");
    </script>
</body>
</html>
  • 注意:绝大多数web服务器,都不允许静态文件响应POST请求,所以这里运行会报错哦。

5、补充

  • 为所有支持的请求方法提供了别名
  • axios.request(confifig)
  • axios.get(url[, confifig])
  • axios.delete(url[, confifig])
  • axios.head(url[, confifig])
  • axios.post(url[, data[, confifig]])
  • axios.put(url[, data[, confifig]])
  • axios.patch(url[, data[, confifig]])

请求后台数据

1.index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="js/vue.global.js"></script>
    <script src="js/axios.min.js"></script>
</head>
<body>
    <div id="app">
        <table cellspacing="0" cellpadding="0" border="1" width="500" align="center">
            <tr>
                <th>学号</th>
                <th>姓名</th>
                <th>年龄</th>
                <th>性别</th>
                <th>邮箱</th>
            </tr>
            <tr v-for="stu in stus">
                <td>{{stu.sid}}</td>
                <td>{{stu.sname}}</td>
                <td>{{stu.sage}}</td>
                <td>{{stu.sgender}}</td>
                <td>{{stu.semail}}</td>
            </tr>
        </table>
    </div>
    <script>
        const vueApp = Vue.createApp({
            data:function(){
                return {
                    stus:""
                }
            },
            created:function(){
                //发送ajax请求,将得到的数据赋值给stus
                axios.get("http://localhost:8888/day10_war_exploded/studentServlet?flag=getAllStudents").then(resp => {
                    this.stus = resp.data;
                });
            }
        });

        vueApp.mount("#app");
    </script>
</body>
</html>

2.StudentServlet.java

package com.etime.servlet;

import com.etime.entity.Student;
import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

@WebServlet("/studentServlet")
public class StudentServlet extends BaseServlet {

    protected void getAllStudents(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        List<Student> list = new ArrayList<>();
        Student student1 = new Student(1,"范冰冰","女",18,"fbb@qq.com");
        Student student2 = new Student(2,"刘德华","男",18,"ldh@qq.com");
        Student student3 = new Student(3,"孙红雷","男",18,"shl@qq.com");
        list.add(student1);
        list.add(student2);
        list.add(student3);
        ObjectMapper mapper = new ObjectMapper();
        String res = mapper.writeValueAsString(list);
        PrintWriter out = resp.getWriter();
        out.print(res);
        out.close();
    }
}

3.跨域问题

在这里插入图片描述

  • 指的是浏览器不能执行其他网站的脚本。它是由浏览器的同源策略造成的,是浏览器对javascript施加的安全限制。

  • 同源策略:是指协议,域名,端口都要相同,其中有一个不同都会产生跨域,在请求数据时,浏览器会在控制台中报一个异常,提示拒绝访问。

  • 跨域问题怎么出现的?

    • 开发一些前后端分离的项目,比如使用 Servlet + Vue 开发时,后台代码在一台服务器上启动,前台代码在另外一台电脑上启动,此时就会出现问题。
    • 比如:
      • 后台 地址为http://localhost:8080/
      • 前台 地址为 http://127.0.0.1:5500/
      • 此时端口号不一致, 不符合同源策略,造成跨域问题。
  • CorsFilter

package com.etime.filter;

import org.apache.commons.lang.StringUtils;
import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/*
  跨域请求
 */
@WebFilter("/*")
public class CorsFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletResponse response = (HttpServletResponse) servletResponse;
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        request.setCharacterEncoding("utf-8");
        // 不使用*,自动适配跨域域名,避免携带Cookie时失效
        String origin = request.getHeader("Origin");
        if(StringUtils.isNotBlank(origin)) {
            response.setHeader("Access-Control-Allow-Origin", origin);
        }
        // 自适应所有自定义头
        String headers = request.getHeader("Access-Control-Request-Headers");
        if(StringUtils.isNotBlank(headers)) {
            response.setHeader("Access-Control-Allow-Headers", headers);
            response.setHeader("Access-Control-Expose-Headers", headers);
        }
        // 允许跨域的请求方法类型
        response.setHeader("Access-Control-Allow-Methods", "*");
        // 预检命令(OPTIONS)缓存时间,单位:秒
        response.setHeader("Access-Control-Max-Age", "3600");
        // 明确许可客户端发送Cookie,不允许删除字段即可
        response.setHeader("Access-Control-Allow-Credentials", "true");
        filterChain.doFilter(request, response);
    }
    @Override
    public void destroy() {
    }
}

综合练习

1.register.html–注册功能

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册</title>
    <script src="js/vue.global.js"></script>
    <script src="js/axios.min.js"></script>
</head>
<body>
    <div id="app">
        <form>
            账号:<input type="text" v-model="username" @blur="checkUsername()">
            <span style="color:red">{{username_msg}}</span><br>
            密码:<input type="password" v-model="pwd" @blur="checkPwd()">
            <span style="color:red">{{pwd_msg}}</span><br>
            <input type="button" value="注册" @click="register()">
        </form>
    </div>
    <script>
        const vueApp = Vue.createApp({
            data:function(){
                return {
                    username:"",
                    pwd:"",
                    username_msg:"",
                    pwd_msg:"",
                    username_flag:false,
                    pwd_flag:false
                }
            },
            methods:{
                checkUsername:function(){
                    if (this.username == "") {
                        this.username_msg = "账号不能为空";
                        this.username_flag = false;
                    } else if (this.username.length < 6) {
                        this.username_msg = "账号至少6个字符";
                        this.username_flag = false;
                    } else {
                        //账号是否为已注册账号的判断
                        axios({
                            method:"get",
                            url:"http://localhost:8888/day10_war_exploded/managerServlet?flag=checkUsername&username="+this.username
                        }).then(resp => {
                            if (resp.data) {
                                this.username_msg = "";
                                this.username_flag = true;
                            } else {
                                this.username_msg = "账号已存在";
                                this.username_flag = false;
                            }
                        });
                    }
                },
                checkPwd:function(){
                    if (this.pwd == "") {
                        this.pwd_msg = "密码不能为空";
                        this.pwd_flag = false;
                    } else if (this.pwd.length < 8) {
                        this.pwd_msg = "密码至少8个字符";
                        this.pwd_flag = false;
                    } else {
                        this.pwd_msg = "";
                        this.pwd_flag = true;
                    }
                },
                register:function(){
                    if (this.username_flag && this.pwd_flag) {
                        //处理需要传递给后端的数据,使用这种方式处理数据时,method值必须是post
                        let params = new URLSearchParams();
                        params.append("flag","register");
                        params.append("username",this.username);
                        params.append("pwd",this.pwd);
                        //数据全部通过校验
                        axios({
                            method:"post",
                            url:"http://localhost:8888/day10_war_exploded/managerServlet",
                            data:params
                        }).then(resp => {
                            if (resp.data) {
                                alert("注册成功");
                                window.location.href = "login.html";
                            } else {
                                alert("注册失败,请稍后再试");
                            }
                        });
                    } else {
                        alert("请认真填写数据");
                    }
                }
            }
        });
        vueApp.mount("#app");
    </script>
</body>
</html>

2.login.html-登录功能

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录</title>
    <script src="js/vue.global.js"></script>
    <script src="js/axios.min.js"></script>
</head>
<body>
    <div id="app">
        <form>
            账号:<input type="text" v-model="username" @blur="checkUsername()">
            <span style="color:red">{{username_msg}}</span><br>
            密码:<input type="password" v-model="pwd" @blur="checkPwd()">
            <span style="color:red">{{pwd_msg}}</span><br>
            <input type="button" value="登录" @click="login()">
        </form>
    </div>
    <script>
        const vueApp = Vue.createApp({
            data(){
                return {
                    username:"",
                    pwd:"",
                    username_msg:"",
                    pwd_msg:"",
                    username_flag:false,
                    pwd_flag:false
                }
            },
            methods:{
                checkUsername(){
                    if (this.username == "") {
                        this.username_msg = "账号不能为空";
                        this.username_flag = false;
                    } else if (this.username.length < 6) {
                        this.username_msg = "账号至少6个字符";
                        this.username_flag = false;
                    } else {
                        axios({
                            method:"get",
                            url:"http://localhost:8888/day10_war_exploded/managerServlet?flag=checkUsername&username="+this.username
                        }).then(resp => {
                            if (resp.data) {
                                this.username_msg = "该账号未注册,请先注册";
                                this.username_flag = false;
                            } else {
                                this.username_msg = "";
                                this.username_flag = true;
                            }
                        });
                    }
                },
                checkPwd(){
                    if (this.pwd == "") {
                        this.pwd_msg = "密码不能为空";
                        this.pwd_flag = false;
                    } else if (this.pwd.length < 8) {
                        this.pwd_msg = "密码至少8个字符";
                        this.pwd_flag = false;
                    } else {
                        this.pwd_msg = "";
                        this.pwd_flag = true;
                    }
                },
                login(){
                    if (this.username_flag && this.pwd_flag) {
                        let params = new URLSearchParams();
                        params.append("flag","login");
                        params.append("username",this.username);
                        params.append("pwd",this.pwd);
                        axios({
                            method:"post",
                            url:"http://localhost:8888/day10_war_exploded/managerServlet",
                            data:params
                        }).then(resp => {
                            if (resp.data) {
                                alert("登录成功");
                                window.location.href = "index.html";
                            } else {
                                alert("密码有误,请查证后再登录");
                            }
                        });
                    } else {
                        alert("请认真填写数据");
                    }
                }
            }
        });
        vueApp.mount("#app");
    </script>
</body>
</html>

3.学生信息展示

(1) studentInfo.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="js/vue.global.js"></script>
    <script src="js/axios.min.js"></script>
</head>
<body>
    <div id="app">
        <table cellspacing="0" cellpadding="0" border="1" width="500" align="center">
            <tr>
                <th>学号</th>
                <th>姓名</th>
                <th>年龄</th>
                <th>性别</th>
                <th>邮箱</th>
                <th>头像</th>
            </tr>
            <tr v-for="stu in stus">
                <td>{{stu.sid}}</td>
                <td>{{stu.sname}}</td>
                <td>{{stu.sage}}</td>
                <td>{{stu.sgender}}</td>
                <td>{{stu.semail}}</td>
                <td>
                    <img :src="'http://localhost:8888/sms_pic/student/'+stu.sphoto" width="50">
                </td>
            </tr>
        </table>
        <div>
            <a href="javascript:void(0)" @click="getStudentByPage(1)">首页</a>
            <a href="javascript:void(0)" @click="getStudentByPage(prevPage)">上一页</a>
            {{page}}/{{countPages}}
            <a href="javascript:void(0)" @click="getStudentByPage(nextPage)">下一页</a>
            <a href="javascript:void(0)" @click="getStudentByPage(countPages)">尾页</a>
        </div>
    </div>
    <script>
        const vueApp = Vue.createApp({
            data:function(){
                return {
                    stus:"",
                    page:"",
                    countPages:"",
                    prevPage:"",
                    nextPage:""
                }
            },
            methods:{
                getStudentByPage(p){
                    let params = new URLSearchParams();
                    params.append("flag","getStudentByPage");
                    params.append("page",p);
                    axios({
                        method:"post",
                        url:"http://localhost:8888/day10_war_exploded/studentServlet",
                        data:params
                    }).then(resp => {
                        this.stus = resp.data.list;
                        this.page = resp.data.page;
                        this.countPages = resp.data.countPages;
                        this.prevPage = resp.data.prevPage;
                        this.nextPage = resp.data.nextPage;
                    });
                }
            },
            created:function(){
                this.getStudentByPage(1);
            }
        });

        vueApp.mount("#app");
    </script>
</body>
</html>

(2) PageUtil.java-分页代码

package com.etime.util;

import java.util.List;

public class PageUtil {
    private int page;      //当前页页码
    private int rows;       //每页显示条数
    private int index;      //偏移量
    private int countRows;      //总条数
    private int countPages;     //总页数
    private int prevPage;       //当前页的上一页页码
    private int nextPage;       //当前页的下一页页码
    private List list;  //当前页的数据

    public PageUtil(String page,int rows,int countRows){
        init_page(page);
        this.rows = rows;
        init_index();
        this.countRows = countRows;
        init_countPages();
        init_prevPage();
        init_nextPage();
    }

    private void init_page(String page){
        if (page == null || "".equals(page)) {
            this.page = 1;
        } else {
            this.page = Integer.parseInt(page);
        }
    }

    private void init_index(){
        this.index = (this.page - 1) * this.rows;
    }

    private void init_countPages(){
        int mod = this.countRows % this.rows;
        if (mod == 0) {
            this.countPages = this.countRows / this.rows;
        } else {
            this.countPages = this.countRows / this.rows + 1;
        }
    }

    private void init_prevPage(){
        if (this.page == 1) {
            this.prevPage = 1;
        } else {
            this.prevPage = this.page - 1;
        }
    }

    private void init_nextPage(){
        if (this.page == this.countPages) {
            this.nextPage = this.countPages;
        } else {
            this.nextPage = this.page + 1;
        }
    }

    public int getPage() {
        return page;
    }

    public int getRows() {
        return rows;
    }

    public int getIndex() {
        return index;
    }

    public int getCountRows() {
        return countRows;
    }

    public int getCountPages() {
        return countPages;
    }

    public int getPrevPage() {
        return prevPage;
    }

    public int getNextPage() {
        return nextPage;
    }

    public List getList() {
        return list;
    }

    public void setList(List list) {
        this.list = list;
    }
}

(3)StudentServlet.java

    protected void getStudentByPage(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        //分页数据查询
        String page = req.getParameter("page");
        int rows = 10;
        int countRows = studentService.getCountRows();
        PageUtil pageUtil = new PageUtil(page, rows, countRows);
        List<Student> list = studentService.getStudentByPage(pageUtil);
        pageUtil.setList(list);
        ObjectMapper mapper = new ObjectMapper();
        String res = mapper.writeValueAsString(pageUtil);
        PrintWriter out = resp.getWriter();
        out.print(res);
        out.close();
    }

(3)StudentServlet.java

    protected void getStudentByPage(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        //分页数据查询
        String page = req.getParameter("page");
        int rows = 10;
        int countRows = studentService.getCountRows();
        PageUtil pageUtil = new PageUtil(page, rows, countRows);
        List<Student> list = studentService.getStudentByPage(pageUtil);
        pageUtil.setList(list);
        ObjectMapper mapper = new ObjectMapper();
        String res = mapper.writeValueAsString(pageUtil);
        PrintWriter out = resp.getWriter();
        out.print(res);
        out.close();
    }

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

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

手写模拟SpringBoot核心流程(一):实现极简一个SpringBoot——模拟SpringBoot启动过程

前言 Spring Boot 是一个开源的框架&#xff0c;用于简化 Spring 应用程序的开发和部署。它建立在 Spring Framework 的基础上&#xff0c;内置了web服务器——tomcat和jetty&#xff0c;使得 Spring 应用的构建变得更加快速、简单和可维护。 本文通过实现一个SpringBoot&…

HTTP连接管理

基础知识&#xff1a;非持久连接 HTTP初始时1.0版本在浏览器每一次向服务器请求完资源都会立即断开TCP连接&#xff0c;如果想要请求多个资源&#xff0c;就必须建立多个连接&#xff0c;这就导致了服务端和客户端维护连接的开销。 例如&#xff1a;一个网页中包含文字资源也包…

第一百三十三天学习记录:数据结构与算法基础:串、数组和广义表(串Ⅱ)(王卓教学视频)

注&#xff1a;在之前学习C语言的时候&#xff0c;了解过这一块。其中对KMP算法进行了自学&#xff0c;前面的学习记录也有提到过。这一次根据视频教学再系统性的学习学习一次。 串的模式匹配算法 KMP算法

[oneAPI] 基于BERT预训练模型的SQuAD问答任务

[oneAPI] 基于BERT预训练模型的SQuAD问答任务 Intel Optimization for PyTorch and Intel DevCloud for oneAPI基于BERT预训练模型的SQuAD问答任务语料介绍数据下载构建 模型 结果参考资料 比赛&#xff1a;https://marketing.csdn.net/p/f3e44fbfe46c465f4d9d6c23e38e0517 Int…

GPT-4一纸重洗:从97.6%降至2.4%的巨大挑战

斯坦福大学和加州大学伯克利分校合作进行的一项 “How Is ChatGPTs Behavior Changing Over Time?” 研究表明&#xff0c;随着时间的推移&#xff0c;GPT-4 的响应能力非但没有提高&#xff0c;反而随着语言模型的进一步更新而变得更糟糕。 研究小组评估了 2023 年 3 月和 20…

Django视图-HttpRequest请求对象和HttpResponse响应对象

文章目录 HttpRequestHttpResponse实践request对象的属性和方法响应 def index(request): 这个request其实就是内部已经封装好的Http请求HttpRequest&#xff0c;它是一个请求对象Django中的视图主要用来接受Web请求&#xff0c;并做出响应。 视图的本质就是一个Python中的函数…

Eduma主题 - 线上教育WordPress主题/网站

Eduma主题 – 线上教育WordPress主题是为教育网站、LMS、培训中心、课程中心、学院、大学、学校、幼儿园而制作的。基于我们使用以前的主题eLearning WP构建WordPress LMS的经验&#xff0c;Education WP是下一代&#xff0c;也是围绕WordPress最好的教育主题之一&#xff0c;它…

Qt下拉菜单

1&#xff0c;QComboBox 2&#xff0c;setMenu()---设置下拉菜单 AI对话未来丨智能写作对话: setMenu()是QWidget类的一个成员函数&#xff0c;在Qt中用于将一个菜单作为一个控件的下拉菜单设置。具体来说&#xff0c;它会把相应的菜单对象与该控件关联&#xff0c;并在控件上…

PySpark-核心编程

2. PySpark——RDD编程入门 文章目录 2. PySpark——RDD编程入门2.1 程序执行入口SparkContext对象2.2 RDD的创建2.2.1 并行化创建2.2.2 获取RDD分区数2.2.3 读取文件创建 2.3 RDD算子2.4 常用Transformation算子2.4.1 map算子2.4.2 flatMap算子2.4.3 reduceByKey算子2.4.4 Wor…

(一)idea连接GitHub的全部流程(注册GitHub、idea集成GitHub、增加合作伙伴、跨团队合作、分支操作)

&#xff08;二&#xff09;Git在公司中团队内合作和跨团队合作和分支操作的全部流程&#xff08;一篇就够&#xff09;https://blog.csdn.net/m0_65992672/article/details/132336481 4.1、简介 Git是一个免费的、开源的*分布式**版本控制**系统*&#xff0c;可以快速高效地…

mongodb 数据库管理(数据库、集合、文档)

目录 一、数据库操作 1、创建数据库 2、删除数据库 二、集合操作 1、创建集合 2、删除集合 三、文档操作 1、创建文档 2、 插入文档 3、查看文档 4、更新文档 1&#xff09;update() 方法 2&#xff09;replace() 方法 一、数据库操作 1、创建数据库 创建数据库…

hive表的全关联full join用法

背景&#xff1a;实际开发中需要用到全关联的用法&#xff0c;之前没遇到过&#xff0c;现在记录一下。需求是找到两张表的并集。 全关联的解释如下&#xff1b; 下面建两张表进行测试 test_a表的数据如下 test_b表的数据如下&#xff1b; 写第一个full join 的SQL进行查询…

树莓派时间更新为中国区时间

一、测试环境为&#xff1a;树莓派3B piraspberrypi:~/workfile/lorawan/lorawan-gw $ uname -a Linux raspberrypi 6.1.21-v7 #1642 SMP Mon Apr 3 17:20:52 BST 2023 armv7l GNU/Linux 测试过程中&#xff0c;请确保树莓派连接网络 &#xff1b; 二、安装ntp相关命令&…

RK3399平台开发系列讲解(内核调试篇)Valgrind使用案例

🚀返回专栏总目录 文章目录 一、使用未初始化的内存案例二、内存泄露三、在内存被释放后进行读/写案例四、从已分配内存块的尾部进行读/写案例五、两次释放内存案例沉淀、分享、成长,让自己和他人都能有所收获!😄 📢Valgrind 是一个开源的内存调试和性能分析工具,用于…

【计算机网络篇】TCP协议

✅作者简介&#xff1a;大家好&#xff0c;我是小杨 &#x1f4c3;个人主页&#xff1a;「小杨」的csdn博客 &#x1f433;希望大家多多支持&#x1f970;一起进步呀&#xff01; TCP协议 1&#xff0c;TCP 简介 TCP&#xff08;Transmission Control Protocol&#xff09;是…

CSS中如何实现文字溢出省略号(text-overflow: ellipsis)效果?

聚沙成塔每天进步一点点 ⭐ 专栏简介⭐ CSS中如何实现文字溢出省略号&#xff08;text-overflow: ellipsis&#xff09;效果&#xff1f;⭐ 写在最后 ⭐ 专栏简介 前端入门之旅&#xff1a;探索Web开发的奇妙世界 记得点击上方或者右侧链接订阅本专栏哦 几何带你启航前端之旅 …

阿里云服务器-修改ecs操作系统,把window系统更换成Linux操作系统

其他sql格式也在更新中&#xff0c;可直接查看这个系列&#xff0c;要是没有你需要的格式&#xff0c;可在评论或私信我 总目录 目录-后期更新打算 hive的nvl中的子查询 总目录我这个是window&#xff0c;默认应该都是window&#xff0c;我需要改成Linux系统第一步&#xff…

如何在Windows、Mac和Linux操作系统上安装Protocol Buffers(protobuf)编译器

&#x1f337;&#x1f341; 博主猫头虎 带您 Go to New World.✨&#x1f341; &#x1f984; 博客首页——猫头虎的博客&#x1f390; &#x1f433;《面试题大全专栏》 文章图文并茂&#x1f995;生动形象&#x1f996;简单易学&#xff01;欢迎大家来踩踩~&#x1f33a; &a…

排序算法之详解冒泡排序

引入 冒泡排序顾名思义&#xff0c;就是像冒泡一样&#xff0c;泡泡在水里慢慢升上来&#xff0c;由小变大。虽然冒泡排序和冒泡并不完全一样&#xff0c;但却可以帮助我们理解冒泡排序。 思路 一组无序的数组&#xff0c;要求我们从小到大排列 我们可以先将最大的元素放在数组…

UE4/5Niagara粒子特效之拖尾渐变

目录 开始操作 发射器一的制作 添加新的模块 ​编辑 让粒子长久存在 添加颜色 发射器二的制作 第三人称模板添加Niagara 效果 添加颜色 效果 隐藏第一个发射器 开始操作 首先创建一个粒子系统&#xff0c;用Fountain这个模板&#xff1a; 发射器一的制作 将不需要的…
最新文章