greendao实现增删改查

news2024/11/19 2:41:29

说明:最近碰到一个需求,在安卓上使用greendao框架,实现增删改查数据

效果图:
在这里插入图片描述

step1:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        google()
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:4.1.2"
        classpath 'org.greenrobot:greendao-gradle-plugin:3.3.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

step2:

plugins {
    id 'com.android.application'
    id 'org.greenrobot.greendao'
}

android {
    compileSdkVersion 32

    defaultConfig {
        applicationId "com.example.iosdialogdemo"
        minSdkVersion 16
        targetSdkVersion 32
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

greendao {
    schemaVersion 7
    daoPackage 'com.example.iosdialogdemo'
    targetGenDir 'src/main/java'
}


dependencies {

    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'com.google.android.material:material:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation 'org.greenrobot:greendao:3.2.2'
    implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'

}

step3:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.iosdialogdemo">

    <application
        android:name=".GreenApp"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.IosDialogDemo">
        <activity android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

step4:

<?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="8dp"
    android:orientation="vertical">

    <LinearLayout
        android:id="@+id/linearLayout2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:orientation="horizontal">


        <EditText
            android:id="@+id/etLanguage"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:paddingRight="8dp" />


        <Button
            android:id="@+id/btn_add"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="3"
            android:backgroundTint="@android:color/holo_purple"
            android:text="新增"
            android:textColor="@android:color/white" />
        <Button
            android:id="@+id/btn_update"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="3"
            android:backgroundTint="@android:color/holo_purple"
            android:text="修改"
            android:textColor="@android:color/white" />
    </LinearLayout>

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/rvLanguage"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:listitem="@layout/item" />

</LinearLayout>

step5:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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="wrap_content"
    android:layout_marginBottom="16dp"
    android:gravity="center_vertical"
    android:orientation="horizontal">

    <TextView
        android:id="@+id/tvOrderNumber"
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:layout_marginEnd="16dp"
        android:text="1"
        android:textColor="@color/white"
        android:background="@color/purple_200"
        app:layout_constraintBottom_toBottomOf="@+id/tvLanguage"
        app:layout_constraintEnd_toStartOf="@+id/tvLanguage"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintHorizontal_chainStyle="spread_inside"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@+id/tvLanguage" />

    <TextView
        android:id="@+id/tvLanguage"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="Bahasa"
        android:textColor="@color/white"
        android:background="@color/teal_200"
        app:layout_constraintBottom_toBottomOf="@+id/btnDelete"
        app:layout_constraintEnd_toStartOf="@+id/btnDelete"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toEndOf="@+id/tvOrderNumber"
        app:layout_constraintTop_toTopOf="@+id/btnDelete" />

    <Button
        android:id="@+id/btnDelete"
        android:layout_width="50dp"
        android:layout_height="wrap_content"
        android:text="删除"
        android:backgroundTint="@android:color/holo_blue_dark"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toEndOf="@+id/tvLanguage"
        app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

step6:

package com.example.iosdialogdemo;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.util.Log;

import org.greenrobot.greendao.AbstractDaoMaster;
import org.greenrobot.greendao.database.StandardDatabase;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseOpenHelper;
import org.greenrobot.greendao.identityscope.IdentityScopeType;


// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/**
 * Master of DAO (schema version 7): knows all DAOs.
 */
public class DaoMaster extends AbstractDaoMaster {
    public static final int SCHEMA_VERSION = 7;

    /** Creates underlying database table using DAOs. */
    public static void createAllTables(Database db, boolean ifNotExists) {
        UserDao.createTable(db, ifNotExists);
    }

    /** Drops underlying database table using DAOs. */
    public static void dropAllTables(Database db, boolean ifExists) {
        UserDao.dropTable(db, ifExists);
    }

    /**
     * WARNING: Drops all table on Upgrade! Use only during development.
     * Convenience method using a {@link DevOpenHelper}.
     */
    public static DaoSession newDevSession(Context context, String name) {
        Database db = new DevOpenHelper(context, name).getWritableDb();
        DaoMaster daoMaster = new DaoMaster(db);
        return daoMaster.newSession();
    }

    public DaoMaster(SQLiteDatabase db) {
        this(new StandardDatabase(db));
    }

    public DaoMaster(Database db) {
        super(db, SCHEMA_VERSION);
        registerDaoClass(UserDao.class);
    }

    public DaoSession newSession() {
        return new DaoSession(db, IdentityScopeType.Session, daoConfigMap);
    }

    public DaoSession newSession(IdentityScopeType type) {
        return new DaoSession(db, type, daoConfigMap);
    }

    /**
     * Calls {@link #createAllTables(Database, boolean)} in {@link #onCreate(Database)} -
     */
    public static abstract class OpenHelper extends DatabaseOpenHelper {
        public OpenHelper(Context context, String name) {
            super(context, name, SCHEMA_VERSION);
        }

        public OpenHelper(Context context, String name, CursorFactory factory) {
            super(context, name, factory, SCHEMA_VERSION);
        }

        @Override
        public void onCreate(Database db) {
            Log.i("greenDAO", "Creating tables for schema version " + SCHEMA_VERSION);
            createAllTables(db, false);
        }
    }

    /** WARNING: Drops all table on Upgrade! Use only during development. */
    public static class DevOpenHelper extends OpenHelper {
        public DevOpenHelper(Context context, String name) {
            super(context, name);
        }

        public DevOpenHelper(Context context, String name, CursorFactory factory) {
            super(context, name, factory);
        }

        @Override
        public void onUpgrade(Database db, int oldVersion, int newVersion) {
            Log.i("greenDAO", "Upgrading schema from version " + oldVersion + " to " + newVersion + " by dropping all tables");
            dropAllTables(db, true);
            onCreate(db);
        }
    }

}

step7:

package com.example.iosdialogdemo;

import java.util.Map;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.AbstractDaoSession;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.identityscope.IdentityScopeType;
import org.greenrobot.greendao.internal.DaoConfig;

import com.example.iosdialogdemo.User;

import com.example.iosdialogdemo.UserDao;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.

/**
 * {@inheritDoc}
 * 
 * @see org.greenrobot.greendao.AbstractDaoSession
 */
public class DaoSession extends AbstractDaoSession {

    private final DaoConfig userDaoConfig;

    private final UserDao userDao;

    public DaoSession(Database db, IdentityScopeType type, Map<Class<? extends AbstractDao<?, ?>>, DaoConfig>
            daoConfigMap) {
        super(db);

        userDaoConfig = daoConfigMap.get(UserDao.class).clone();
        userDaoConfig.initIdentityScope(type);

        userDao = new UserDao(userDaoConfig, this);

        registerDao(User.class, userDao);
    }
    
    public void clear() {
        userDaoConfig.clearIdentityScope();
    }

    public UserDao getUserDao() {
        return userDao;
    }

}

step8:

package com.example.iosdialogdemo;

import android.app.Application;
import org.greenrobot.greendao.database.Database;


/**
 * Created by rhodel on 8/15/2017.
 */

public class GreenApp extends Application {

    private DaoSession daoSession;

    @Override
    public void onCreate() {
        super.onCreate();

        DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "notes-db");
        Database db = helper.getWritableDb();
        daoSession = new DaoMaster(db).newSession();
    }

    @Override
    public void onTerminate() {
        super.onTerminate();
        daoSession.clear();
    }

    public DaoSession getDaoSession() {
        return daoSession;
    }
}

step9:

package com.example.iosdialogdemo;



public interface ILanguageRecycleListener {
    void itemOnClick(int model,Long id,String title,int position);
    /* mode1 0:id,1:title,2:delete*/
}

step10:

package com.example.iosdialogdemo;


        import android.util.Log;
        import android.view.LayoutInflater;
        import android.view.View;
        import android.view.ViewGroup;

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

        import java.util.ArrayList;
        import java.util.List;

public class LanguageRecycleAdapter extends RecyclerView.Adapter<LanguageViewHolder> {

    private List<User> languageList = new ArrayList<>();

    private ILanguageRecycleListener listener;

    public LanguageRecycleAdapter(List<User> languageList, ILanguageRecycleListener listener) {
        this.languageList = languageList;
        this.listener = listener;

        Log.e("TAG", "LanguageRecycleAdapter " + languageList.size());
    }

    public void setData(List<User> languageList2) {
        this.languageList = languageList2;
    }

    @NonNull
    @Override
    public LanguageViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        LanguageViewHolder holder;
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item, parent, false);
        holder = new LanguageViewHolder(view);
        return holder;

    }

    @Override
    public void onBindViewHolder(@NonNull LanguageViewHolder holder, final int position) {
        holder.orderNumber.setText(String.valueOf(position));
        holder.language.setText(languageList.get(position).getName());
        holder.orderNumber.setText(String.valueOf(languageList.get(position).getId()));


        holder.btnDelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                listener.itemOnClick(2,languageList.get(position).getId(),languageList.get(position).getName(),position);
            }
        });
        holder.orderNumber.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                listener.itemOnClick(0,languageList.get(position).getId(),languageList.get(position).getName(),position);
            }
        });

        holder.language.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                listener.itemOnClick(1,languageList.get(position).getId(),languageList.get(position).getName(),position);
            }
        });
    }

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


}

step11:

package com.example.iosdialogdemo;



        import android.view.View;
        import android.widget.Button;
        import android.widget.TextView;

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

public class LanguageViewHolder extends RecyclerView.ViewHolder {
    TextView orderNumber;
    TextView language;
    Button btnDelete;

    public LanguageViewHolder(@NonNull View itemView) {
        super(itemView);
        orderNumber = itemView.findViewById(R.id.tvOrderNumber);
        language = itemView.findViewById(R.id.tvLanguage);
        btnDelete = itemView.findViewById(R.id.btnDelete);
    }
}

step12:

package com.example.iosdialogdemo;



        import androidx.appcompat.app.AppCompatActivity;
        import androidx.recyclerview.widget.LinearLayoutManager;
        import androidx.recyclerview.widget.RecyclerView;

        import android.os.Bundle;
        import android.util.Log;
        import android.view.View;
        import android.widget.Button;
        import android.widget.EditText;

        import java.util.ArrayList;
        import java.util.List;

public class MainActivity extends AppCompatActivity implements ILanguageRecycleListener {
    private LanguageRecycleAdapter languageRecycleAdapter;
    private RecyclerView rvLanguage;
//    private List<String> languageList = new ArrayList<>();
    private EditText editText;
    private Button btn_add,btn_update;
    private UserDao userDao;
    private DaoSession daoSession;

    private List<User> languageList;
    private Long id2;
    private String title2;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        daoSession = ((GreenApp) getApplication()).getDaoSession();
        userDao = daoSession.getUserDao();

        languageList = new ArrayList<>();

        if (languageList!=null){
            languageList.clear();
        }

        languageList.addAll(userDao.queryBuilder().list());



        rvLanguage = findViewById(R.id.rvLanguage);
        editText= findViewById(R.id.etLanguage);
        btn_add= findViewById(R.id.btn_add);
        btn_update= findViewById(R.id.btn_update);

        RecyclerView.LayoutManager layoutManager = new
                LinearLayoutManager(this);
        rvLanguage.setLayoutManager(layoutManager);
        languageRecycleAdapter = new LanguageRecycleAdapter(languageList, this);
        rvLanguage.setAdapter(languageRecycleAdapter);

        btn_add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String etString = editText.getText().toString();
               // languageList.add(etString);

                User user = new User();
                user.setName(etString);


                userDao.insert(user);


                if (languageList!=null){
                    languageList.clear();
                }

                languageList.addAll(userDao.queryBuilder().list());



                languageRecycleAdapter.setData(languageList);
                languageRecycleAdapter.notifyDataSetChanged();
            }
        });


        btn_update.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String etString = editText.getText().toString();
                // languageList.add(etString);
                Log.e("TAG", "sql_itemOnClick: " +id2+"==="+title2);

                User user = new User();
                user.setName(etString);
                user.setId(id2);


                userDao.update(user);


                if (languageList!=null){
                    languageList.clear();
                }

                languageList.addAll(userDao.queryBuilder().list());



                languageRecycleAdapter.setData(languageList);
                languageRecycleAdapter.notifyDataSetChanged();
            }
        });
    }

    @Override
    public void itemOnClick(int model,Long id, String title,int position) {
        Log.e("TAG", "itemOnClick: " + id + ", " + position);
        if (model==2){

            userDao.deleteByKey(id);

            if (languageList!=null){
                languageList.clear();
            }

            languageList.addAll(userDao.queryBuilder().list());


            Log.e("TAG", "sql_itemOnClick: " +languageList);


            languageRecycleAdapter.setData(languageList);
            languageRecycleAdapter.notifyDataSetChanged();

          /*  languageList.remove(position);
            languageRecycleAdapter.setData(languageList);
            languageRecycleAdapter.notifyDataSetChanged();*/
        }else if (model==1){
            editText.setText(title);

            id2 = id;
            title2=title;
        }
    }
}

step13:

package com.example.iosdialogdemo;

import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.Generated;

/**
 * Created by rhodel on 8/15/2017.
 */

@Entity
public class User {
    @Id(autoincrement = true)
    private Long id;

    private String name;

    @Generated(hash = 873297011)
    public User(Long id, String name) {
        this.id = id;
        this.name = name;
    }

    @Generated(hash = 586692638)
    public User() {
    }

    public Long getId() {
        return this.id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

step14:

package com.example.iosdialogdemo;

import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "USER".
*/
public class UserDao extends AbstractDao<User, Long> {

    public static final String TABLENAME = "USER";

    /**
     * Properties of entity User.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Id = new Property(0, Long.class, "id", true, "_id");
        public final static Property Name = new Property(1, String.class, "name", false, "NAME");
    }


    public UserDao(DaoConfig config) {
        super(config);
    }
    
    public UserDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"USER\" (" + //
                "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
                "\"NAME\" TEXT);"); // 1: name
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"USER\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, User entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        String name = entity.getName();
        if (name != null) {
            stmt.bindString(2, name);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, User entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        String name = entity.getName();
        if (name != null) {
            stmt.bindString(2, name);
        }
    }

    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
    }    

    @Override
    public User readEntity(Cursor cursor, int offset) {
        User entity = new User( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1) // name
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, User entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setName(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(User entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(User entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(User entity) {
        return entity.getId() != null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
}

end

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

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

相关文章

26计算机操作系统408考研--操作系统处理机调度篇章(五)

文章目录 一、调度简介死锁一、调度简介 计算机系统中,处理器和内存资源会出现供不应求的情况,特别是多个I/O设备与主机交互,作业不断进入系统,或者是多个批处理作业在磁盘的后备队列中等待进入内存的情况。操作系统在管理有限的资源的同时,需要考虑如何选取进入内存的作…

破解App渠道归因难题,Xinstall助你实现精准数据追踪!

在移动互联网时代&#xff0c;App的推广和运营面临着诸多挑战。其中&#xff0c;渠道归因问题一直困扰着众多推广者。如何准确追踪用户来源&#xff0c;分析不同渠道的推广效果&#xff0c;成为了摆在推广者面前的一大难题。然而&#xff0c;有了Xinstall的出现&#xff0c;这一…

LabVIEW软件需求分析文档内容和编写指南

编写LabVIEW软件需求分析文档&#xff08;Software Requirements Specification, SRS&#xff09;是软件开发的关键步骤之一。以下是详细的内容结构、编写指南和注意事项&#xff1a; 内容结构 引言 项目背景&#xff1a;简要介绍项目背景和目的。 文档目的&#xff1a;说明需…

AI Agent教育行业落地案例

【AI赋能教育】揭秘Duolingo背后的AI Agent&#xff0c;让学习更高效、更有趣&#xff01; ©作者|Blaze 来源|神州问学 引言 随着科技的迅猛发展&#xff0c;人工智能技术已经逐步渗透到我们生活的各个方面。而随着AI技术的广泛应用&#xff0c;教育培训正引领着一场新的…

双指针法和链表练习题(2024/5/28)

1面试题 02.07. 链表相交 给你两个单链表的头节点 headA 和 headB &#xff0c;请你找出并返回两个单链表相交的起始节点。如果两个链表没有交点&#xff0c;返回 null 。 图示两个链表在节点 c1 开始相交&#xff1a; 题目数据 保证 整个链式结构中不存在环。 注意&#xf…

【云原生】Kubernetes----POD调度策略

目录 引言 一、Pod调度策略 &#xff08;一&#xff09;基本概述 &#xff08;二&#xff09;调度原则 &#xff08;三&#xff09;Predicate常见算法 &#xff08;四&#xff09;优先级排序 &#xff08;五&#xff09;调度过程 1.过滤阶段 2.优先级排序 3.选择最优…

Python 点云处理-点云半径滤波

点云半径滤波 一、介绍二、代码示例三、结果示例其他参考:C++ 中点云半径滤波 一、介绍 点云半径滤波:删除点云一定范围内没有达到足够多领域的所有点云。通俗的讲:就是要求点云P在半径为R内需要有M个领域点,若在点P的R范围内领域点个数大于M个,则保留该点云,领域点个数…

OrangePi AIpro初识及使用大模型GPT-Neo-1.3B测试

OrangePi AIpro介绍 1.1. 开发板简介 Orange Pi AI Pro 开发板是香橙派联合华为精心打造的高性能AI 开发板&#xff0c;其搭 载了昇腾AI 处理器&#xff0c;可提供8TOPS INT8 的计算能力&#xff0c;内存提供了8GB 和16GB 两种版本。可以实现图像、视频等多种数据分析与推理…

Java | Leetcode Java题解之第108题将有序数组转换为二叉搜索树

题目&#xff1a; 题解&#xff1a; class Solution {Random rand new Random();public TreeNode sortedArrayToBST(int[] nums) {return helper(nums, 0, nums.length - 1);}public TreeNode helper(int[] nums, int left, int right) {if (left > right) {return null;}…

5 分钟快速上手图形验证码,防止接口被恶意刷量!

5 分钟快速上手图形验证码&#xff0c;防止接口被恶意刷量&#xff01; 大家好&#xff0c;我是程序员小白条&#xff0c;今天来给大家介绍一个快速实现图形验证码的优秀框架 AJ-Captcha。 需求分析 如果注册接口没有验证码这种类型的限制&#xff0c;很容易会被刷量&#x…

3D Slicer:从入门到精通——数据模块之DICOM

DICOM 文章目录 DICOM概述DICOM简介Slicer DICOM数据库DICOM插件 如何操作创建DICOM数据库将DICOM文件读入场景DICOM导入DICOM加载 从DICOM数据库中删除数据将数据从场景导出到DICOM数据库将数据从场景导出到DICOM文件DICOM网络传输DICOMweb网络传输 查看DICOM元数据 面板及其用…

Redis常见基本类型(5)-List, Set

List 命令小结 命令及解释时间复杂度lpush/rpush key value[key value...](向右/左端插入元素)O(k), k是元素个数linsert key before | after pivot value(在某个坐标之前/右插入元素)O(n), n是pivot距离头尾的距离lrange start end(获取从start到end部分的元素)O(s n): s是…

特朗普竞选带火PoliFi,以Bitget为例

以特朗普系列Meme币为代表的政治金融(PoliFi)概念币市场正在掀起热潮&#xff0c;前美国总统特朗普(Donald Trump)在本月稍早公开力挺加密货币&#xff0c;接着又在周二宣布接受比特币、以太币、SOL、USDC、DOGE…等政治献金&#xff0c;让相关通证高涨。 据CoinGecko数据&…

系统架构设计师【第1章】: 绪论 (核心总结)

文章目录 1.1 系统架构概述1.1.1 系统架构的定义及发展历程1.1.2 软件架构的常用分类及建模方法1.1.3 软件架构的应用场景1.1.4 软件架构的发展未来 1.2 系统架构设计师概述1.2.1 架构设计师的定义、职责和任务1.2.2 架构设计师应具备的专业素质1.2.3 架构设计师的知识…

linux开发之设备树基本语法一

设备树的根节点 设备树子节点和子子节点,子节点在根节点范围内 包含子节点以及子子节点 节点名称 比如这里led就是这个gpio的小名,可以直接用 gpio22020101是这里的名字,也就是要用这个gpio,符号后面的一串数字使用了这个gpio的寄存器地址,因为可能会用很多gpio,所以加入寄存…

纯前端怎么实现不同标签页下的数据通信

前言 我记得之前有做过这样的一个需求——可以简化的看作为一个 TODO List &#xff0c;我打开了两个 tab 页&#xff0c;都是对应这个 TODO List 。 然后我在 A 页面新增一个&#xff0c;不出意外的话&#xff0c;在 B 页面是看不到的。产品当时跟我提了一下这个&#xff0c…

K-独立钻石(dfs),G-邪恶铭刻(贪心)

这两题&#xff0c;都是应该赛场上A出来的。 K.独立钻石 当时一直关注点在 I. Path Planning&#xff0c;没关注榜单&#xff0c;K,也能写&#xff0c;也就是dfs,从数据范围可以看出&#xff0c;直接暴力搜索。 代码 #include<bits/stdc.h> #define int long long #d…

JavaScript的当前时间设置及Date的运算

作者:私语茶馆 1.场景描述 如下图,在HTML刚加载时,需要将开始时间设置为默认当前时间,结束时间设置为当前时间后7天的时间。手工填写时间时,时间段不超过30天。 这里涉及到两个技术点: 1)Input Date的当前时间设置 2)date的运算 由于是动态修改HTML,所以采用…

【软件设计师】算法

1、算法的效率 时间复杂度:程序从开始到结束所需要的时间 空间复杂度&#xff1a;算法在运行过程中临时占用存储空间大小的度量 时间渐近复杂度&#xff1a;时间复杂度由最高次幂决定(判断大小技巧&#xff1a;将n10代入&#xff09; O(log2 n):二分查找法 O(n&#xff09;:for…

Echarts x轴坐标二级分组

在使用echarts 封装组件的时候&#xff0c;偶尔会遇到需要x轴坐标进行二层分组的需求。那么如何对echarts 进行二层分组呢&#xff0c;有以下几个步骤&#xff1a; 仅介绍二层分组的逻辑。有兴趣的可以进行三层延伸。 1&#xff0c;修改echarts Options 中xAxis 的配置。 此…