Go語言編寫一個進銷存Web軟件的demo

Go語言編寫一個進銷存Web軟件的demo

用戶現在要求用。之前他們已經討論了用Django實現的方案,現在突然切換到Go,可能有幾個原因。首先,用戶可能對Go語言感興趣,或者他們公司的技術棧轉向了Go。其次,用戶可能希望比較不同語言實現的差異,或者需要更高性能的解決方案。

go和django的區別

接下來,我需要分析用戶的具體需求。用戶提到需要多個界面和權限管理,之前Django版本中已經涉及了這些內容,所以用戶可能希望Go版本也能實現類似的功能,但用Go的特性來構建。同時,用戶可能希望這個demo足夠簡單,但又能展示關鍵功能,比如庫存管理、訂單處理、用戶權限等。

Gin是一個高性能的輕量級框架

我需要考慮Go語言常用的Web框架。Gin是一個高性能的輕量級框架,適合快速開發,所以選擇Gin作為基礎。數據庫方面,使用SQLite作為嵌入式數據庫,方便demo的部署和測試,不需要復雜的配置。

1.數據庫模型

數據模型的設計需要與之前的Django模型對應,但結構體定義會有所不同。比如,Product結構體需要包含名稱、庫存、價格等字段。User結構體需要處理權限,可能使用角色(Role)字段來區分不同用戶權限,如管理員、普通用戶等。

2.權限管理

在Go中可以使用中間件來處理。比如,對于需要管理員權限的路由,添加一個中間件檢查用戶的角色是否為admin。登錄認證可以使用JWT,生成token,然后在后續請求中驗證token的有效性,并解析用戶信息。

3.路由設計

需要區分公開路由(如登錄)和需要認證的路由(如產品管理)。每個路由組可以應用不同的中間件,確保權限控制。

4.前端

用戶可能希望有簡單的HTML界面,所以使用Go的模板引擎來渲染頁面。同時,提供RESTful API供前端調用,這樣以后可以擴展為前后端分離的架構。

在實現具體功能時,比如創建采購訂單,需要更新產品的庫存。這里要注意事務處理,確保庫存增減的原子性,避免并發問題。雖然demo可能不需要處理高并發,但良好的實踐可以提升代碼質量。

5.測試

需要確保各個接口的正常工作,比如添加產品、登錄、創建訂單等。使用curl命令或者Postman來測試API,同時檢查數據庫中的數據變化是否正確。

可能遇到的挑戰包括Go與Django在ORM方面的差異。Go沒有內置的ORM,所以需要使用database/sql庫手動編寫SQL語句,或者使用第三方庫如gorm。但在demo中,為了簡潔,可能直接使用SQLite的驅動和標準庫操作數據庫,這樣減少依賴。

最后,需要提供清晰的步驟說明,包括如何安裝依賴、運行程序、測試接口等。用戶可能不熟悉Go的模塊管理,所以需要指出使用go mod初始化項目,并獲取必要的依賴包。

總結來說,用戶需要一個用Go語言實現的簡單進銷存系統demo,具備基本的產品管理、訂單處理、用戶認證和權限控制功能。使用Gin框架和SQLite數據庫,通過中間件和JWT實現權限管理,前端使用HTML模板渲染。需要確保代碼結構清晰,易于理解和擴展。

一個使用Go語言(Gin框架)實現的簡易進銷存系統Demo

包含基礎功能、權限控制和API接口:

main.go

package mainimport ("database/sql""fmt""log""net/http""os""time""github.com/gin-gonic/gin"_ "github.com/mattn/go-sqlite3""golang.org/x/crypto/bcrypt"
)// 數據結構定義
type Product struct {ID        int     `json:"id"`Name      string  `json:"name" binding:"required"`Stock     int     `json:"stock"`Price     float64 `json:"price" binding:"required"`CreatedAt string  `json:"created_at"`
}type User struct {ID       int    `json:"id"`Username string `json:"username" binding:"required"`Password string `json:"password" binding:"required"`Role     string `json:"role"` // admin/user
}type Order struct {ID         int     `json:"id"`ProductID  int     `json:"product_id" binding:"required"`Quantity   int     `json:"quantity" binding:"required"`Type       string  `json:"type" binding:"required"` // purchase/saleTotalPrice float64 `json:"total_price"`CreatedAt  string  `json:"created_at"`
}// 數據庫初始化
func initDB() *sql.DB {db, err := sql.Open("sqlite3", "./inventory.db")if err != nil {log.Fatal(err)}// 創建表sqlStmt := `CREATE TABLE IF NOT EXISTS products (id INTEGER PRIMARY KEY AUTOINCREMENT,name TEXT NOT NULL,stock INTEGER DEFAULT 0,price REAL NOT NULL,created_at DATETIME DEFAULT CURRENT_TIMESTAMP);CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY AUTOINCREMENT,username TEXT UNIQUE NOT NULL,password TEXT NOT NULL,role TEXT NOT NULL DEFAULT 'user');CREATE TABLE IF NOT EXISTS orders (id INTEGER PRIMARY KEY AUTOINCREMENT,product_id INTEGER NOT NULL,quantity INTEGER NOT NULL,type TEXT NOT NULL,total_price REAL NOT NULL,created_at DATETIME DEFAULT CURRENT_TIMESTAMP);`_, err = db.Exec(sqlStmt)if err != nil {log.Printf("%q: %s\n", err, sqlStmt)return nil}return db
}// 中間件
func AuthMiddleware() gin.HandlerFunc {return func(c *gin.Context) {token := c.GetHeader("Authorization")if token == "" {c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": "未授權訪問"})return}claims, err := ParseToken(token)if err != nil {c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": "無效令牌"})return}c.Set("user", claims)c.Next()}
}func AdminMiddleware() gin.HandlerFunc {return func(c *gin.Context) {user, exists := c.Get("user")if !exists {c.AbortWithStatus(http.StatusUnauthorized)return}if user.(*UserClaims).Role != "admin" {c.AbortWithStatusJSON(http.StatusForbidden, gin.H{"error": "權限不足"})return}c.Next()}
}// 主函數
func main() {db := initDB()defer db.Close()r := gin.Default()// 公共路由public := r.Group("/api"){public.POST("/login", loginHandler(db))public.POST("/register", registerHandler(db))}// 需要認證的路由private := r.Group("/api")private.Use(AuthMiddleware()){// 產品管理private.GET("/products", getProductsHandler(db))private.POST("/products", AdminMiddleware(), createProductHandler(db))// 訂單管理private.POST("/orders", createOrderHandler(db))private.GET("/orders", getOrdersHandler(db))}// 啟動服務port := os.Getenv("PORT")if port == "" {port = "8080"}r.Run(":" + port)
}// 處理函數示例
func createProductHandler(db *sql.DB) gin.HandlerFunc {return func(c *gin.Context) {var product Productif err := c.ShouldBindJSON(&product); err != nil {c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})return}stmt, err := db.Prepare("INSERT INTO products(name, stock, price) VALUES(?, ?, ?)")if err != nil {c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})return}defer stmt.Close()result, err := stmt.Exec(product.Name, product.Stock, product.Price)if err != nil {c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})return}id, _ := result.LastInsertId()c.JSON(http.StatusCreated, gin.H{"id": id})}
}func createOrderHandler(db *sql.DB) gin.HandlerFunc {return func(c *gin.Context) {var order Orderif err := c.ShouldBindJSON(&order); err != nil {c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})return}// 開始事務tx, err := db.Begin()if err != nil {c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})return}// 檢查產品庫存var currentStock interr = tx.QueryRow("SELECT stock FROM products WHERE id = ?", order.ProductID).Scan(&currentStock)if err != nil {tx.Rollback()c.JSON(http.StatusNotFound, gin.H{"error": "產品不存在"})return}// 更新庫存newStock := currentStockif order.Type == "purchase" {newStock += order.Quantity} else if order.Type == "sale" {if currentStock < order.Quantity {tx.Rollback()c.JSON(http.StatusBadRequest, gin.H{"error": "庫存不足"})return}newStock -= order.Quantity}_, err = tx.Exec("UPDATE products SET stock = ? WHERE id = ?", newStock, order.ProductID)if err != nil {tx.Rollback()c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})return}// 創建訂單stmt, err := tx.Prepare("INSERT INTO orders(product_id, quantity, type, total_price) VALUES(?, ?, ?, ?)")if err != nil {tx.Rollback()c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})return}defer stmt.Close()_, err = stmt.Exec(order.ProductID, order.Quantity, order.Type, order.TotalPrice)if err != nil {tx.Rollback()c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})return}tx.Commit()c.JSON(http.StatusCreated, gin.H{"message": "訂單創建成功"})}
}// JWT相關功能(示例代碼)
func GenerateToken(user *User) (string, error) {// 實現JWT生成邏輯return "sample_token", nil
}func ParseToken(tokenString string) (*UserClaims, error) {// 實現JWT解析邏輯return &UserClaims{Username: "admin", Role: "admin"}, nil
}type UserClaims struct {Username stringRole     string
}

運行步驟

  1. 安裝依賴:

go mod init inventory
go get github.com/gin-gonic/gin
go get github.com/mattn/go-sqlite3
go get golang.org/x/crypto/bcrypt
運行界面
D:\work\goproject>go mod init inventory
go: creating new go.mod: module inventory
go: to add module requirements and sums:go mod tidyD:\work\goproject>go get github.com/gin-gonic/gin
go: downloading github.com/gin-gonic/gin v1.10.0
go: downloading github.com/gin-contrib/sse v0.1.0
go: downloading github.com/mattn/go-isatty v0.0.20
go: downloading golang.org/x/net v0.25.0
go: downloading github.com/bytedance/sonic v1.11.6
go: downloading github.com/goccy/go-json v0.10.2
go: downloading github.com/json-iterator/go v1.1.12
go: downloading github.com/go-playground/validator/v10 v10.20.0
go: downloading github.com/pelletier/go-toml/v2 v2.2.2
go: downloading github.com/ugorji/go/codec v1.2.12
go: downloading google.golang.org/protobuf v1.34.1
go: downloading gopkg.in/yaml.v3 v3.0.1
go: downloading golang.org/x/sys v0.20.0
go: downloading golang.org/x/text v0.15.0
go: downloading github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd
go: downloading github.com/leodido/go-urn v1.4.0
go: downloading github.com/modern-go/reflect2 v1.0.2
go: downloading golang.org/x/crypto v0.23.0
go: downloading github.com/gabriel-vasile/mimetype v1.4.3
go: downloading github.com/go-playground/universal-translator v0.18.1
go: downloading github.com/go-playground/locales v0.14.1

    下載完畢后會修改go.mod文件

    module inventorygo 1.24.2require (github.com/bytedance/sonic v1.11.6 // indirectgithub.com/bytedance/sonic/loader v0.1.1 // indirectgithub.com/cloudwego/base64x v0.1.4 // indirectgithub.com/cloudwego/iasm v0.2.0 // indirectgithub.com/gabriel-vasile/mimetype v1.4.3 // indirectgithub.com/gin-contrib/sse v0.1.0 // indirectgithub.com/gin-gonic/gin v1.10.0 // indirectgithub.com/go-playground/locales v0.14.1 // indirectgithub.com/go-playground/universal-translator v0.18.1 // indirectgithub.com/go-playground/validator/v10 v10.20.0 // indirectgithub.com/goccy/go-json v0.10.2 // indirectgithub.com/json-iterator/go v1.1.12 // indirectgithub.com/klauspost/cpuid/v2 v2.2.7 // indirectgithub.com/leodido/go-urn v1.4.0 // indirectgithub.com/mattn/go-isatty v0.0.20 // indirectgithub.com/mattn/go-sqlite3 v1.14.27 // indirectgithub.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirectgithub.com/modern-go/reflect2 v1.0.2 // indirectgithub.com/pelletier/go-toml/v2 v2.2.2 // indirectgithub.com/twitchyliquid64/golang-asm v0.15.1 // indirectgithub.com/ugorji/go/codec v1.2.12 // indirectgolang.org/x/arch v0.8.0 // indirectgolang.org/x/crypto v0.37.0 // indirectgolang.org/x/net v0.25.0 // indirectgolang.org/x/sys v0.32.0 // indirectgolang.org/x/text v0.24.0 // indirectgoogle.golang.org/protobuf v1.34.1 // indirectgopkg.in/yaml.v3 v3.0.1 // indirect
    )
    

    運行代碼

    go run main.go

    提示錯誤

    .\main.go:129:25: undefined: loginHandler
    .\main.go:130:28: undefined: registerHandler
    .\main.go:138:28: undefined: getProductsHandler
    .\main.go:143:26: undefined: getOrdersHandler

    可以看出代碼中沒有上面4個函數,直接屏蔽掉就OK

    再次運行

    go run main.go
    2025/04/10 22:16:58 "Binary was compiled with 'CGO_ENABLED=0', go-sqlite3 requires cgo to work. This is a stub":CREATE TABLE IF NOT EXISTS products (id INTEGER PRIMARY KEY AUTOINCREMENT,name TEXT NOT NULL,stock INTEGER DEFAULT 0,price REAL NOT NULL,created_at DATETIME DEFAULT CURRENT_TIMESTAMP);CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY AUTOINCREMENT,username TEXT UNIQUE NOT NULL,password TEXT NOT NULL,role TEXT NOT NULL DEFAULT 'user');CREATE TABLE IF NOT EXISTS orders (id INTEGER PRIMARY KEY AUTOINCREMENT,product_id INTEGER NOT NULL,quantity INTEGER NOT NULL,type TEXT NOT NULL,total_price REAL NOT NULL,created_at DATETIME DEFAULT CURRENT_TIMESTAMP);
    [GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.        - using env:   export GIN_MODE=release- using code:  gin.SetMode(gin.ReleaseMode)[GIN-debug] POST   /api/products             --> main.main.createProductHandler.func3 (5 handlers)
    [GIN-debug] POST   /api/orders               --> main.main.createOrderHandler.func4 (4 handlers)
    [GIN-debug] [WARNING] You trusted all proxies, this is NOT safe. We recommend you to set a value.
    Please check https://pkg.go.dev/github.com/gin-gonic/gin#readme-don-t-trust-all-proxies for details.
    [GIN-debug] Listening and serving HTTP on :8080
    

    提升運行成功

    功能說明

    1. 核心功能

    • 產品管理(CRUD)

    • 采購/銷售訂單管理

    • 實時庫存更新

    • 用戶認證(JWT)

    • 角色權限控制(admin/user)

    1. API接口示例

    bash

    復制

    # 注冊用戶
    curl -X POST http://localhost:8080/api/register \-H "Content-Type: application/json" \-d '{"username":"admin","password":"admin123","role":"admin"}'# 登錄獲取Token
    curl -X POST http://localhost:8080/api/login \-H "Content-Type: application/json" \-d '{"username":"admin","password":"admin123"}'# 創建產品(需要admin權限)
    curl -X POST http://localhost:8080/api/products \-H "Authorization: Bearer sample_token" \-H "Content-Type: application/json" \-d '{"name":"MacBook Pro", "stock":10, "price":1999.99}'# 創建采購訂單
    curl -X POST http://localhost:8080/api/orders \-H "Authorization: Bearer sample_token" \-H "Content-Type: application/json" \-d '{"product_id":1, "quantity":5, "type":"purchase", "total_price":9999.95}'
    1. 前端界面建議

    html

    復制

    <!-- 示例產品列表界面 -->
    <!DOCTYPE html>
    <html>
    <head><title>產品管理</title><link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    </head>
    <body><div class="container mt-4"><h2>產品列表</h2><div id="product-list" class="row"></div></div><script>// 使用fetch API獲取產品數據fetch('/api/products', {headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')}}).then(response => response.json()).then(data => {const container = document.getElementById('product-list');data.forEach(product => {const card = `<div class="col-md-4 mb-3"><div class="card"><div class="card-body"><h5 class="card-title">${product.name}</h5><p class="card-text">庫存: ${product.stock}<br>價格: $${product.price}</p></div></div></div>`;container.innerHTML += card;});});</script>
    </body>
    </html>

    運行 HTML

    系統擴展建議

    1. 增強功能

    • 添加供應商/客戶管理

    • 實現庫存預警功能

    • 增加報表統計模塊

    • 支持文件導入導出

    • 添加操作日志記錄

    1. 性能優化

    • 添加Redis緩存層

    • 實現數據庫連接池

    • 添加API限流中間件

    • 支持集群部署

    1. 安全增強

    • 實現HTTPS支持

    • 添加請求參數校驗

    • 實現密碼策略強制

    • 添加IP白名單控制

    1. 部署方案

    bash

    復制

    # 使用Docker部署
    FROM golang:1.18-alpine
    WORKDIR /app
    COPY go.mod ./
    COPY go.sum ./
    RUN go mod download
    COPY *.go ./
    RUN go build -o /inventory
    EXPOSE 8080
    CMD [ "/inventory" ]

    這個Demo實現了以下核心功能:

    • RESTful API設計

    • JWT身份驗證

    • 角色權限控制

    • 庫存事務管理

    • 基礎數據操作

    • 錯誤處理機制

    可以根據實際需求繼續擴展以下功能:

    1. 增加Swagger API文檔

    2. 實現單元測試

    3. 添加Prometheus監控

    4. 集成消息隊列

    5. 實現分布式鎖

    6. 添加數據驗證規則

    本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
    如若轉載,請注明出處:http://www.pswp.cn/web/75306.shtml
    繁體地址,請注明出處:http://hk.pswp.cn/web/75306.shtml
    英文地址,請注明出處:http://en.pswp.cn/web/75306.shtml

    如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

    相關文章

    【前綴和】矩陣區域和(medium)

    矩陣區域和&#xff08;medium&#xff09; 題?描述&#xff1a;解法&#xff1a;代碼Java 算法代碼&#xff1a;C 算法代碼&#xff1a; 題?描述&#xff1a; 題?鏈接&#xff1a;1314. 矩陣區域和 給你?個 m x n 的矩陣 mat 和?個整數 k &#xff0c;請你返回?個矩陣 …

    Java學習手冊:Java發展歷史與版本特性

    Java作為全球最流行的編程語言之一&#xff0c;其發展歷程不僅見證了技術的演進&#xff0c;也反映了軟件開發模式的變革。從1995年的首次發布到如今的持續更新&#xff0c;Java始終保持著強大的生命力和廣泛的影響力。本文將簡要回顧Java的發展歷程&#xff0c;并重點介紹其關…

    winserver2022備份

    安裝備份&#xff0c;然后等待安裝完成即可 然后可以在這里看到安裝好的win server2022備份 一直下一步然后到這里 不要用本地文件夾備份 備份到遠程服務器&#xff0c;遠程服務器路徑 然后確定備份即可 如何恢復呢&#xff1f; 點擊右側的恢復就可以了 打開任務計劃程序 這…

    Unity 設置彈窗Tips位置

    根據鼠標位于屏幕的區域&#xff0c;設置彈窗錨點以及位置 public static void TipsPos(Transform tf) {//獲取ui相機var uiCamera GetUICamera();var popup tf.GetComponent<RectTransform>();//獲取鼠標位置Vector2 mousePos Input.mousePosition;float screenWidt…

    【C++基礎-關鍵字】:extern

    深入理解 C++ 關鍵字 extern 在 C++ 編程中,extern 關鍵字扮演著重要角色,主要用于聲明全局變量或函數,使其在多個源文件間共享。本文將詳細探討 extern 的用法及其在實際開發中的應用。 1. 什么是 extern? extern 關鍵字用于聲明一個變量或函數的引用,表示該變量或函數…

    我為女兒開發了一個游戲網站

    大家好&#xff0c;我是星河。 自從協助妻子為女兒開發了算數射擊游戲后&#xff0c;星河就一直有個想法&#xff1a;為女兒打造一個專屬的學習游戲網站。之前的射擊游戲雖然有趣&#xff0c;但缺乏難度分級&#xff0c;無法根據女兒的學習進度靈活調整。而且&#xff0c;僅僅…

    基于 Python 卷積神經網絡的新聞文本分類系統,附源碼

    大家好&#xff0c;我是徐師兄&#xff0c;一個有著7年大廠經驗的程序員&#xff0c;也是一名熱衷于分享干貨的技術愛好者。平時我在 CSDN、掘金、華為云、阿里云和 InfoQ 等平臺分享我的心得體會。今天我來跟大家聊聊一個用 Python 和 Django 打造的人臉識別考勤系統&#xff…

    ngx_cycle_modules

    Ubuntu 下 nginx-1.24.0 源碼分析 - ngx_cycle_modules-CSDN博客 定義在 src/core/ngx_module.c ngx_int_t ngx_cycle_modules(ngx_cycle_t *cycle) {/** create a list of modules to be used for this cycle,* copy static modules to it*/cycle->modules ngx_pcalloc(…

    AI 代碼生成工具如何突破 Java 單元測試效能天花板?

    一、傳統單元測試的四大痛點 時間黑洞&#xff1a;根據 JetBrains 調研&#xff0c;Java 開發者平均花費 35% 時間編寫測試代碼覆蓋盲區&#xff1a;手工測試覆蓋率普遍低于 60%&#xff08;Jacoco 全球統計數據&#xff09;維護困境&#xff1a;業務代碼變更導致 38% 的測試用…

    【保姆級圖解】插入排序 算法詳解:直接插入排序、希爾排序

    總體引入 在計算機科學的算法領域中&#xff0c;排序是一項基礎且重要的操作。它旨在將一組無序的數據元素重新排列為有序序列&#xff0c;以滿足特定的順序要求&#xff0c;如升序或降序。常見的排序算法可分為不同類別&#xff0c;像插入排序&#xff0c;包含直接插入排序和…

    為什么ChatGPT選擇SSE而非WebSocket?

    為什么ChatGPT選擇SSE而非WebSocket&#xff1f; 一、ChatGPT回答問題的技術邏輯 ChatGPT的響應生成基于Transformer架構和自注意力機制&#xff0c;其核心是通過概率預測逐詞生成文本。當用戶輸入問題后&#xff0c;模型會先解析上下文&#xff0c;再通過預訓練的龐大語料庫…

    Android 手機指紋傳感器無法工作,如何恢復數據?

    天津鴻萌科貿發展有限公司從事數據安全服務二十余年&#xff0c;致力于為各領域客戶提供專業的數據恢復、數據清除、數據備份、數據取證、數據遷移解決方案&#xff0c;并針對企業面臨的數據安全風險&#xff0c;提供專業的相關數據安全培訓。 天津鴻萌科貿發展有限公司是眾多國…

    DeepSeek 在金融領域的應用解決方案

    DeepSeek 在金融領域的應用解決方案 一、背景 隨著人工智能技術的快速發展&#xff0c;DeepSeek 作為一款國產大模型&#xff0c;憑借其強大的語義理解、邏輯推理和多模態處理能力&#xff0c;在金融行業迅速嶄露頭角。金融行業作為經濟的核心&#xff0c;面臨著激烈的市場競…

    織光五載 煥新啟航

    成都時尚產業協會5周年 以創新為筆&#xff0c;續寫國際時尚之都的璀璨篇章 【一場跨越時空的時尚對話】 五年前&#xff0c;一顆名為"成都時尚產業協會"的種子在蓉城落地生根&#xff1b;五年后&#xff0c;這棵新芽已成長為枝繁葉茂的生態之樹&#xff0c;用交織…

    scala集合

    一、數組&#xff08;Array&#xff09; 1.數組轉換 不可變轉可變&#xff1a;arr1.toBuffer&#xff0c;arr1本身沒有變化 可變轉不可變&#xff1a;arr2.toArray&#xff0c;arr2本身沒有變化 2.多維數組 創建&#xff1a;val arr Array.ofDim[Int](3, 4)&#xff08;3 …

    常用 Excel VBA 技巧,簡單好學易上手

    在日常辦公中&#xff0c;我們常常會遇到各種繁瑣的數據處理任務&#xff0c;而 Excel VBA&#xff08;Visual Basic for Applications&#xff09;作為一款強大的自動化工具&#xff0c;能夠幫助我們輕松應對這些挑戰。本文將介紹一些常用且簡單好學的 Excel VBA 技巧&#xf…

    Java 基礎 - 反射(1)

    文章目錄 引入類加載過程1. 通過 new 創建對象2. 通過反射創建對象2.1 觸發加載但不初始化2.2 按需觸發初始化2.3 選擇性初始化控制 核心用法示例1. 通過無參構造函數創建實例對象2. 通過有參構造函數創建實例對象3. 反射通過私有構造函數創建對象&#xff0c; 破壞單例模式4. …

    如何在React中集成 PDF.js?構建支持打印下載的PDF閱讀器詳解

    本文深入解析基于 React 和 PDF.js 構建 PDF 查看器的實現方案&#xff0c;該組件支持 PDF 渲染、圖片打印和下載功能&#xff0c;并包含完整的加載狀態與錯誤處理機制。 完整代碼在最后 一個PDF 文件&#xff1a; https://mozilla.github.io/pdf.js/web/compressed.tracemo…

    數據結構與算法-動態規劃-線性動態規劃,0-1背包,多重背包,完全背包,有依賴的背包,分組背包,背包計數,背包路徑

    動態規劃原理 動態規劃這玩意兒&#xff0c;就好比是在拓撲圖上玩跳格子游戲。在圖論中&#xff0c;咱們是從特定的節點跳到其他節點&#xff1b;而在動態規劃里呢&#xff0c;我們是從一個狀態 “嗖” 地轉移到另一個狀態。狀態一般用數組來表示&#xff0c;就像 f [i][j]&am…

    解決文件夾解壓中文字符產生亂碼的問題

    太tm智能了&#xff0c;本來還想看看解壓工具在哪里修改&#xff0c;智能的識別到亂碼了。點贊 看到那個地球了嗎&#xff0c;點擊那個球&#xff0c;這個修改不是侵略性的&#xff0c;不會修改壓縮文件本身所以需要在當前頁面解壓 參考 https://blog.csdn.net/QCSYSZQ/artic…