Android studio实现登录验证后返回token及用户信息,使用token获取用户信息并生成列表展示

news2024/9/24 17:20:01

大概时序图
在这里插入图片描述
登录成功保存token,然后带token请求获取用户列表

实现效果:
在这里插入图片描述
在这里插入图片描述
依赖
build.gradle(:app)

dependencies {
    implementation 'androidx.recyclerview:recyclerview:1.2.1'
    implementation 'com.google.code.gson:gson:2.8.9'
    implementation 'com.tencent:mmkv-static:1.2.9'
    implementation 'com.squareup.okhttp3:okhttp:4.9.1'
    }

AndroidManifest.xml

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

MainActivity

import androidx.appcompat.app.AppCompatActivity;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.tencent.mmkv.MMKV;
import org.json.JSONObject;
import java.io.IOException;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

public class MainActivity extends AppCompatActivity {
    private EditText usernameEditText;
    private EditText passwordEditText;
    private Button loginButton;
    private String token;
    @SuppressLint("MissingInflatedId")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        usernameEditText = findViewById(R.id.userNameEditText);
        passwordEditText = findViewById(R.id.passwordEditText);
        loginButton = findViewById(R.id.loginButton);

        //初始化
        MMKV.initialize(this);

        //点击事件
        loginButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String username = usernameEditText.getText().toString();
                String password = passwordEditText.getText().toString();

                if (isValidUsernameAndPassword(username, password)) {
                    LoginTask loginTask = new LoginTask();
                    loginTask.execute();
                } else {
                    Toast.makeText(MainActivity.this, "用户名或密码无效", Toast.LENGTH_SHORT).show();
                }
            }
        });
    }

    private boolean isValidUsernameAndPassword(String username, String password) {
        // 在这里可以添加验证用户名和密码的逻辑,例如检查用户名和密码的格式等
        return true;
    }

    private class LoginTask extends AsyncTask<Void, Void, String> {
        private final OkHttpClient client = new OkHttpClient();

        @Override
        protected String doInBackground(Void... voids) {
            String username = usernameEditText.getText().toString();
            String password = passwordEditText.getText().toString();
            //post请求的URL
            String url = "https://2k317b5009.goho.co/login?username=" + username + "&password=" + password; // 替换为实际的登录接口地址
            try {
                //创建了一个新的Request对象。Request对象用于封装请求的各种参数,如URL、HTTP方法、请求头、请求体等
                Request request = new Request.Builder()
                        .url(url)
                        //设置了请求的方法为POST,并创建了请求体。
                        //请求体中包含了以JSON格式发送的用户名和密码。
                        // MediaType.parse("application/json")指示了请求体的格式是JSON。
                        .post(RequestBody.create(okhttp3.MediaType.parse("application/json"), "{\"username\":\"" + username + "\", \"password\":\"" + password + "\"}")) // 将username和password以JSON格式发送给服务器
                        .build();
                Response response = client.newCall(request).execute();//发送了请求并获取了响应
                return response.body().string();//从响应中获取了响应体,并将其转换为字符串格式
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }

        @Override
        protected void onPostExecute(String response) {
            if (response != null) {
                try {
                    JSONObject jsonObject = new JSONObject(response);
                    token = jsonObject.getJSONObject("userMsg").getString("token"); // 获取token字段的值,根据实际情况修改字段名称和JSON解析方式
                    MMKVUtil.putString("key",token);//MMKVUtil储存token
                    Log.e("MainActivity", token);
                    Toast.makeText(MainActivity.this, "登录成功", Toast.LENGTH_SHORT).show();//弹框提示
                    Intent intent = new Intent(MainActivity.this, ListActivity.class);//跳转页面
                    startActivity(intent);

                } catch (Exception e) {
                    e.printStackTrace();
                    Toast.makeText(MainActivity.this, "登录失败", Toast.LENGTH_SHORT).show();
                }
            } else {
                Toast.makeText(MainActivity.this, "没有服务", Toast.LENGTH_SHORT).show();
            }
        }
    }
}

ListActivity 将数据解析转换为list进行列表展示

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import org.json.JSONException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

public class ListActivity extends AppCompatActivity {
    private RecyclerView mRecyclerView;
    private final List<User> mUserList = new ArrayList<>();
    private final String TAG = "ListActivity";
    private Handler mHandler;
    private MyAdapter mMyAdapter;

    @SuppressLint("MissingInflatedId")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_list);
        mRecyclerView = findViewById(R.id.recyclerView);

        //创建了一个新的Handler对象,在Android的主线程(UI线程)上执行特定的任务
        mHandler = new Handler();
        //创建了一个新的线程来执行后面的代码  不会阻塞主线程
        new Thread(new Runnable() {//定义了新线程要执行的操作
            @Override
            public void run() {
                try {
                    //获取处理好的网络数据
                    String JSON = getUserjson();
                    List<User> userList = getList(JSON);

                    //将新的Runnable对象添加到Handler中,这使得Runnable中的代码将在主线程上执行
                    mHandler.post(new Runnable() {
                        @Override
                        public void run() {
                            //设置了一个线性布局管理器
                            mRecyclerView.setLayoutManager(new LinearLayoutManager(ListActivity.this));
                            //实例化适配器
                            mMyAdapter = new MyAdapter(userList);
                            //将适配器设置为RecyclerView的适配器
                            mRecyclerView.setAdapter(mMyAdapter);
                            if (userList != null) {
                                // 处理响应结果
                            } else {
                                // 处理错误情况
                            }
                        }
                    });
                } catch (IOException | JSONException e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }

    public String getUserjson() throws IOException, JSONException {
        // 创建OkHttpClient实例
        OkHttpClient client = new OkHttpClient();

        // 设置请求的URL和token
        String strurl = "https://2k317b5009.goho.co/userList";
        String Token = MMKVUtil.getString("key");//获取token

        // 创建请求头部,包括token
        Request request = new Request.Builder()
                .url(strurl)
                .addHeader("token", Token)//添加headers信息
                .build();

        Log.e(TAG, request.toString());
        // 发送GET请求并获取响应
        String responseBody = null;
        try (Response response = client.newCall(request).execute()) {
            if (response.isSuccessful()) {
                // 处理成功响应
                responseBody = response.body().string();
            }
        }
        return responseBody;
    }

    public List<User> getList(String responseBody) {
        //创建了一个新的JsonParser对象。JsonParser是Gson库中的一个类,
        //提供了从JSON文本字符串解析JSON并生成JsonElement对象的方法
        JsonParser parser = new JsonParser();

        //使用JsonParser对象来解析responseBody中的JSON文本,并将解析的结果存储在一个JsonElement对象中
        JsonElement element = parser.parse(responseBody);

        //解析得到的element是否是一个JSON数组
        if (element.isJsonArray()) {
            //获取上一步解析得到的element作为一个JsonArray对象
            JsonArray array = element.getAsJsonArray();
            //遍历上一步得到的JsonArray对象中的每一个元素
            for (JsonElement e : array) {
                //检查当前的元素e是否是一个JSON对象
                if (e.isJsonObject()) {
                    JsonObject obj = e.getAsJsonObject();
                    String name = obj.get("name").getAsString();
                    String password = obj.get("password").getAsString();
                    int Id = obj.get("id").getAsInt();
                    String sex = obj.get("sex").getAsString();
                    int age = obj.get("age").getAsInt();
                    //String token = obj.get("token").getAsString();
                    String msg1 = obj.get("msg1").getAsString();
                    String msg2 = obj.get("msg2").getAsString();
                    String msg3 = obj.get("msg3").isJsonNull() ? "default" : obj.get("msg3").getAsString();

                    User user = new User(name, password, Id, sex, age, "", msg1, msg2, msg3);
                    mUserList.add(user);
                    // 在这里将每个User对象进行存储或处理
                }
                // 在这里对响应数据进行解析和处理
                Log.e(TAG, "————————————————————————");
            }
        }
        return mUserList;
    }
}

MMKVUtil 管理token

import com.tencent.mmkv.MMKV;

/**
 * 管理token
 */
public class MMKVUtil {
    private static MMKV mmkv;

    //获取实例
    private static MMKV getInstance() {
        if (mmkv == null) {
            mmkv = MMKV.defaultMMKV();
        }
        return mmkv;
    }

    //存
    public static void putString(String key, String value) {
        getInstance().encode(key, value);
    }

    //取
    public static String getString(String key) {
        return getInstance().decodeString(key);
    }

    //删
    public static void remove(String key) {
        getInstance().removeValueForKey(key);
    }
}

MyAdapter RecyclerView适配器

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;


import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

/**
 * RecyclerView适配器
 */
//ViewHolder类通常用于持有RecyclerView的item视图中的控件,并可以避免频繁的 findViewById() 调用
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> {
    private final List<User> mUserList;

    public MyAdapter(List<User> mUserList) {
        this.mUserList = mUserList;
    }

    //onCreateViewHolder接受一个ViewGroup(通常是RecyclerView)和一个视图类型整数值作为参数,并返回一个新的ViewHolder实例,该实例持有新创建或复用的视图
    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        //使用LayoutInflater从parent的上下文中获取一个实例
        //并使用R.layout.list_item(一个XML布局文件)来inflate(填充)一个新的视图。这个新视图被赋值给view变量
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item, parent, false);
        //ViewHolder将负责管理和操作这个视图以及其中的控件
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    //onBindViewHolder在RecyclerView中显示数据
    public void onBindViewHolder(ViewHolder holder, int i) {
        User user = mUserList.get(i);
        holder.mName.setText(user.getName());
        holder.mPwd.setText(user.getPassword());
        holder.mId.setText(String.valueOf(user.getId()));
        holder.mSex.setText(user.getSex());
        holder.mAge.setText(String.valueOf(user.getAge()));
        holder.mToken.setText(user.getToken());
        holder.mMsg1.setText(user.getMsg1());
        holder.mMsg2.setText(user.getMsg2());
        holder.mMsg3.setText(user.getMsg3());
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public int getItemCount() {
        return mUserList.size();
    }

    /**
     * 创建了一个ViewHolder类,
     * 用于保存和提供对RecyclerView列表项视图中各种文本视图(如姓名、密码、ID等)的引用,
     * 以便在处理列表项视图时能方便地访问这些视图并进行相应的操作
     */
    public class ViewHolder extends RecyclerView.ViewHolder {
        //ViewHolder类通常用于保存每个列表项的视图以及与这些视图相关的数据
        private final TextView mName;
        private final TextView mPwd;
        private final TextView mId;
        private final TextView mSex;
        private final TextView mAge;
        private final TextView mToken;
        private final TextView mMsg1;
        private final TextView mMsg2;
        private final TextView mMsg3;

        //ViewHolder类的构造函数,它接收一个View对象作为参数。在构造函数中,通过给定的View对象找到并保存了对应的TextView
        public ViewHolder(View view) {
            super(view);
            mName = view.findViewById(R.id.name);
            mPwd = view.findViewById(R.id.pwd);
            mId = view.findViewById(R.id.id);
            mSex = view.findViewById(R.id.sex);
            mAge = view.findViewById(R.id.age);
            mToken = view.findViewById(R.id.token);
            mMsg1 = view.findViewById(R.id.msg1);
            mMsg2 = view.findViewById(R.id.msg2);
            mMsg3 = view.findViewById(R.id.msg3);
        }
    }
}

User

public class User {
    private String Name;
    private String Password;
    private int Id;
    private String Sex;
    private int Age;
    private String Token;
    private String Msg1;
    private String Msg2;
    private String Msg3;

    public User() {
    }

    public User(String name, String password, int id, String sex, int age, String token, String msg1, String msg2, String msg3) {
        Name = name;
        Password = password;
        Id = id;
        Sex = sex;
        Age = age;
        Token = token;
        Msg1 = msg1;
        Msg2 = msg2;
        Msg3 = msg3;
    }

    public String getName() {
        return Name;
    }

    public void setName(String name) {
        Name = name;
    }

    public String getPassword() {
        return Password;
    }

    public void setPassword(String password) {
        Password = password;
    }

    public int getId() {
        return Id;
    }

    public void setId(int id) {
        Id = id;
    }

    public String getSex() {
        return Sex;
    }

    public void setSex(String sex) {
        Sex = sex;
    }

    public int getAge() {
        return Age;
    }

    public void setAge(int age) {
        Age = age;
    }

    public String getToken() {
        return Token;
    }

    public void setToken(String token) {
        Token = token;
    }

    public String getMsg1() {
        return Msg1;
    }

    public void setMsg1(String msg1) {
        Msg1 = msg1;
    }

    public String getMsg2() {
        return Msg2;
    }

    public void setMsg2(String msg2) {
        Msg2 = msg2;
    }

    public String getMsg3() {
        return Msg3;
    }

    public void setMsg3(String msg3) {
        Msg3 = msg3;
    }
}

activity_mian.xml 登录页面

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:orientation="horizontal"
    android:gravity="center">


   <LinearLayout
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_gravity="center_vertical|center_horizontal"
       android:orientation="vertical"
       android:gravity="center">

      <EditText
          android:id="@+id/userNameEditText"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:ems="10"
          android:inputType="text"
          android:hint="用户名"/>

      <EditText
          android:id="@+id/passwordEditText"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:ems="10"
          android:inputType="textPassword"
          android:hint="密码"/>


      <CheckBox
          android:id="@+id/rememberPwdCheckBox"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="记住密码"
          android:checked="true" />

      <LinearLayout
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_gravity="center_vertical|center_horizontal"
          android:orientation="horizontal"
          android:gravity="center">

         <Button
             android:id="@+id/loginButton"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:text="  登   录   "/>



         <Button
             android:id="@+id/logoutButton"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:text="退出登录"/>

      </LinearLayout>
   </LinearLayout>
</LinearLayout>

acitivty_list.xml 列表页面

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="5dp"
    android:orientation="vertical"
    tools:context=".ListActivity">

   <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#BBD5E1"
        tools:ignore="MissingConstraints">

        <TextView
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="name"
            android:textSize="10dp" />

        <TextView
            android:id="@+id/pwd"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="pwd"
            android:textSize="10dp" />
        <TextView
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="id"
            android:textSize="10dp" />
        <TextView
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="sex"
            android:textSize="10dp" />
        <TextView
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="age"
            android:textSize="10dp" />
        <TextView
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="token"
            android:textSize="10dp" />
        <TextView
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="msg1"
            android:textSize="10dp" />
        <TextView
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="msg2"
            android:textSize="10dp" />
        <TextView
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="msg3"
            android:textSize="10dp" />

    </LinearLayout>

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</LinearLayout>

list_item.xml 列表项页面

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="5sp"
            android:layout_weight="1"
            android:layout_gravity="center"
            android:orientation="horizontal">
        <TextView
            android:id="@+id/name"
            android:layout_width="match_parent"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="name"
            android:textSize="10dp" />

        <TextView
            android:id="@+id/pwd"
            android:layout_width="match_parent"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="pwd"
            android:textSize="10dp" />
        <TextView
            android:id="@+id/id"
            android:layout_width="match_parent"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="id"
            android:textSize="10dp" />
        <TextView
            android:id="@+id/sex"
            android:layout_width="match_parent"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="sex"
            android:textSize="10dp" />
        <TextView
            android:id="@+id/age"
            android:layout_width="match_parent"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="age"
            android:textSize="10dp" />
        <TextView
            android:id="@+id/token"
            android:layout_width="match_parent"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="token"
            android:textSize="10dp" />
        <TextView
            android:id="@+id/msg1"
            android:layout_width="match_parent"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="msg1"
            android:textSize="10dp" />
        <TextView
            android:id="@+id/msg2"
            android:layout_width="match_parent"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="msg2"
            android:textSize="10dp" />
        <TextView
            android:id="@+id/msg3"
            android:layout_width="match_parent"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="msg3"
            android:textSize="10dp" />

    </LinearLayout>
</LinearLayout>

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

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

相关文章

Python爬虫逆向猿人学刷题系列——第七题

题目&#xff1a;采集这5页中胜点列的数据&#xff0c;找出胜点最高的召唤师&#xff0c;将召唤师姓名填入答案中 地址&#xff1a;https://match.yuanrenxue.cn/match/7 本题主要是考察字体的动态变化&#xff0c;同样也是从字体文件下手构造出映射关系就好&#xff0c;但本题…

k8s(Kubernetes)集群部署--使用 kubeadm方式部署

k8s集群部署--使用 kubeadm方式部署 一、测试所需环境&#xff08;三台均要执行&#xff09;二、配置准备&#xff08;三台均要执行&#xff09;1. 重命名hostname、添加hosts2. 关闭防火墙、selinux与swap3. 添加网桥过滤及内核转发配置文件4.同步时间5.安装ipset及ipvsadm 三…

Tomcat 下部署 jFinal

1、检查web.xml 配置&#xff0c;在 tomcat 下部署需要检查 web.xml 是否存在&#xff0c;并且要确保配置正确&#xff0c;配置格式如下。 <?xml version"1.0" encoding"UTF-8"?> <web-app xmlns:xsi"http://www.w3.org/2001/XMLSchema-i…

网址导航收藏引导页面H5源码(自适应引导页HTML源码)-自动检测域名延迟

简介&#xff1a; 网址导航收藏引导页面H5源码&#xff08;自适应引导页HTML源码&#xff09;&#xff0c;可以自动检测域名延迟。这网址导航发布页不同于其它的&#xff0c;因为它可以测试所有域名的一个访问速度&#xff0c;并且将访问速度具象化显示出来&#xff0c;具体的…

性能调优降本实例

降本思路 在A企业内部&#xff0c;线上业务稳定性标准为&#xff1a;达到业务核定TPS时&#xff0c;CPU利用率的峰值不超过60&#xff05;&#xff0c;即为稳定状态。 在这个背景下&#xff0c;测试部门针对部分CPU消耗较高的系统进行了统一梳理和专项性能测试&#xff0c;旨…

Linux 挂载

挂载需要挂载源和挂载点 虚拟机本身就有的挂源 添加硬件 重启虚拟机 操作程序 sudo fdisk -l //以管理员权限查看电脑硬盘使用情况sudo mkfs.ext4 /dev/sdb //以管理员身份格式化硬盘sudo mkdir guazai //创建挂载文件夹 sudo mount /dev/sdb/guazai //将挂载源接上挂载点 s…

【数据结构】堆排序详解

文章目录 一、堆排序思想二、向上调整建堆排序三、向下调整建堆排序四、总结 对于什么是堆&#xff0c;堆的概念分类以及堆的向上和向下两种调整算法可见&#xff1a; 堆的创建 一、堆排序思想 int a[] { 2,3,5,7,4,6 };对于这样一个数组来说&#xff0c;要想要用堆排序对它…

Webserver项目解析

一.webserver的组成部分 Buffer类 用于存储需要读写的数据 Channel类 存储文件描述符和相应的事件&#xff0c;当发生事件时&#xff0c;调用对应的回调函数 ChannelMap类 Channel数组&#xff0c;用于保存一系列的Channel Dispatcher 监听器&#xff0c;可以设置为epo…

分享一个基于微信小程序的社区生活小助手源码调试和lw,有java+python双版本

&#x1f495;&#x1f495;作者&#xff1a;计算机源码社 &#x1f495;&#x1f495;个人简介&#xff1a;本人七年开发经验&#xff0c;擅长Java、Python、PHP、.NET、微信小程序、爬虫、大数据等&#xff0c;大家有这一块的问题可以一起交流&#xff01; &#x1f495;&…

让NPU跑起来迅为RK3588开发板设置交叉编译器

让NPU跑起来迅为RK3588开发板设置交叉编译器 编译器下载地址是网盘资料“iTOP-3588 开发板\02_【iTOP-RK3588 开发板】开发资料 \12_NPU 使用配套资料\03_编译所需工具\Linux”。 拷贝 gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu.tar.gz 到 Ubuntu 的/opt/tool_ch…

JavaScript中的`async`和`await`关键字的作用

聚沙成塔每天进步一点点 ⭐ 专栏简介⭐ async关键字⭐ await 关键字3. 错误处理 ⭐ 写在最后 ⭐ 专栏简介 前端入门之旅&#xff1a;探索Web开发的奇妙世界 记得点击上方或者右侧链接订阅本专栏哦 几何带你启航前端之旅 欢迎来到前端入门之旅&#xff01;这个专栏是为那些对We…

中国汽车供应商远赴德国,中国智驾方案能否远渡重洋?

作者|Amy 编辑|德新 今年的上海车展&#xff0c;中国智能汽车的进步有目共睹&#xff0c;吸引了大批外企高管和研发人员的关注&#xff0c;甚至引发了海外车企一系列的动作和调整。 而在刚刚结束的慕尼黑车展&#xff0c;中国车企及汽车供应链把「肌肉」秀到了现代汽车起源地…

flask要点与坑

简介 Flask是一个用Python编写的Web应用程序框架&#xff0c;该框架简单易用、模块化、灵活性高。 该笔记主要记录Flask的关键要点和容易踩坑的地方 Flask 日志配置 Flask 中的自带logger模块&#xff08;也是python自带的模块&#xff09;&#xff0c;通过简单配置可以实现…

浅谈拓展欧几里得算法

1、求特解 x 0 , y 0 x_0, y_0 x0​,y0​ 普通的欧几里得算法依据是辗转相除法&#xff0c;也就是&#xff0c;比如求 a &#xff0c; b a&#xff0c;b a&#xff0c;b 的最大公约数&#xff0c; a &#xff0c; b a&#xff0c;b a&#xff0c;b 进行辗转相除直到 a − b …

复盘:细数这些年写文字的成与败

引言 最近一直在思考和复盘&#xff0c;要说我这些年最后悔没坚持或者没做对的一件事就是没有好好写文字。时间过得很快&#xff0c;一晃笔者已经快毕业十年了&#xff0c;文章写得比较密集的时候还是大学时代和毕业头几年&#xff0c;后面输出就越来越少了&#xff0c;甚至一…

前端性能优化:提升网站速度与用户体验的终极指南

&#x1f482; 个人网站:【工具大全】【游戏大全】【神级源码资源网】&#x1f91f; 前端学习课程&#xff1a;&#x1f449;【28个案例趣学前端】【400个JS面试题】&#x1f485; 寻找学习交流、摸鱼划水的小伙伴&#xff0c;请点击【摸鱼学习交流群】 在今天的数字时代&#…

【C++ 学习 ㉑】- 详解 map 和 set(上)

目录 一、C STL 关联式容器 二、pair 类模板 三、set 3.1 - set 的基本介绍 3.2 - set 的成员函数 3.1.1 - 构造函数 3.1.2 - 迭代器 3.1.3 - 修改操作 3.1.4 - 其他操作 四、map 4.1 - map 的基本介绍 4.2 - map 的成员函数 4.2.1 - 迭代器 4.2.2 - operator[] …

避免使用违规词,企业新媒体营销应注重品牌形象维护

随着越来越多的主体入局新媒体平台&#xff0c;为了维护平台健康的内容生态和创造良好的社区氛围&#xff0c;社交平台在内容上的监管越发严格。 不可避免的&#xff0c;很多做新媒体营销的企业开始陷入与平台审核的“拉扯”之中。 为了让品牌账号在各平台上顺利运营&#xff0…

二十一、MySQL(多表)内连接、外连接、自连接实现

1、多表查询 &#xff08;1&#xff09;基础概念&#xff1a; &#xff08;2&#xff09;多表查询的分类&#xff1a; 2、内连接 &#xff08;1&#xff09;基础概念&#xff1a; &#xff08;2&#xff09;隐式内连接&#xff1a; 基础语法&#xff1a; select 表1.name,…

使用Oracle自带SqlPlus导入导出数据库脚本

sqlplus sys/passwordorcl as sysdba ----cmd 进入Oracle sqlplus 1、导入例子&#xff1a; imp username/username127.0.0.1:1521/orcl fileD:\datasource\username0919.dmp fully imp 用户名/密码127.0.0.1:1521/orcl fileD:\datasource\备份名字.dmp fully 2、导出例子&a…