Backend Development 16 min read

Comparative Tutorial: Building CRUD Applications with Gin (Go) and Spring Boot (Java)

This article walks through step‑by‑step how to create a simple CRUD service using Go's Gin framework with Gorm and MySQL, then shows the equivalent implementation with Java Spring Boot, MyBatis‑Plus and MySQL, comparing the two approaches and providing complete source code.

Architecture Digest
Architecture Digest
Architecture Digest
Comparative Tutorial: Building CRUD Applications with Gin (Go) and Spring Boot (Java)

The author describes a friendly competition between two developers: one builds a CRUD service with Go's Gin and Gorm, the other uses Java Spring Boot with MyBatis‑Plus. Both projects manage people and book tables in a MySQL database.

Preparation

Two tables are created with the following SQL:

CREATE TABLE people (
    id INT(11) PRIMARY KEY AUTO_INCREMENT,
    p_name VARCHAR(255) NOT NULL,
    p_age INT(11) NOT NULL
);

CREATE TABLE book (
    id INT(11) PRIMARY KEY AUTO_INCREMENT,
    b_name VARCHAR(255) NOT NULL,
    b_price FLOAT NOT NULL
);

Gin (Go) Implementation

Project structure and go.mod :

module gobase

go 1.17

require (
    github.com/gin-gonic/gin v1.6.0
    github.com/jinzhu/gorm v1.9.16
    github.com/sirupsen/logrus v1.9.3
    github.com/spf13/cast v1.5.1
)

Model definitions ( book.go and people.go ) use Gorm tags to map struct fields to table columns and provide a TableName() method.

package model

const BookTableName = "book"

type Book struct {
    ID       int64  `gorm:"column:id"`
    BookName string `gorm:"column:b_name"`
    BookPrice float64 `gorm:"column:b_price"`
}

func (b *Book) TableName() string { return BookTableName }

DAO interfaces ( dao.go ) define CRUD methods; implementations ( book_dao_impl.go , people_dao_impl.go ) use a Gorm DB instance.

type BookDao interface {
    AddBook(book *model.Book) error
    UpdateBook(book *model.Book) error
    DeleteBook(book *model.Book) error
    ListBookById(id uint) (*model.Book, error)
}

A MySQL connection pool is created in mysql_connection_pool.go with configurable parameters.

func NewDataSource() *DataSouce {
    dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8&parseTime=True&loc=Asia%%2FShanghai", UserName, PassWord, Host, Port, Database)
    db, err := gorm.Open(Dialect, dsn)
    if err != nil { log.Fatal(err.Error()) }
    db.DB().SetConnMaxLifetime(MaxLifetime)
    db.DB().SetConnMaxIdleTime(MaxIdletime)
    db.DB().SetMaxOpenConns(MaxOpenconns)
    db.DB().SetMaxIdleConns(MaxIdleconns)
    return &DataSouce{db: db}
}

Routes are defined in webservice.go and controllers ( book_controller.go , people_controller.go ) handle HTTP requests, bind JSON payloads, invoke DAO methods, and return JSON responses.

Spring Boot (Java) Implementation

The Maven pom.xml includes Spring Boot starter, MyBatis‑Plus, MySQL driver and Lombok.

<project ...>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.1</version>
    </parent>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.1.0</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.16</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>
    </dependencies>
</project>

Entity classes Book and People use Lombok annotations and MyBatis‑Plus @TableField to map columns.

@Getter @Setter
public class Book {
    @TableField("id")
    private int id;
    @TableField("b_name")
    private String bookName;
    @TableField("b_price")
    private float bookPrice;
}

Mapper interfaces extend BaseMapper to inherit CRUD methods.

@Mapper
public interface BookMapper extends BaseMapper<Book> {}

Controllers ( BookController , PeopleController ) are annotated with @RestController and expose /add , /update , /delete , /list endpoints that call the mapper methods and return ResponseEntity objects.

Comparison and Conclusion

The author notes that Spring Boot provides out‑of‑the‑box web server and starter packages, making CRUD development very straightforward, while Gin requires more manual wiring but offers a lightweight Go solution. Both approaches achieve the same functional goals, and the choice depends on language preference and ecosystem.

Finally, the article offers a QR‑code link for readers to claim a free book‑management source code package.

goSpring BootMySQLMyBatis-PlusCRUDgormGin
Architecture Digest
Written by

Architecture Digest

Focusing on Java backend development, covering application architecture from top-tier internet companies (high availability, high performance, high stability), big data, machine learning, Java architecture, and other popular fields.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.