在数据库中存储大 html 文本

store large html text in database

在我的 Grails (2.2.1) 项目中,我想将一些大的 html 存储到数据库字段中。 我创建了以下域 class:

class SurgeryModule {

    byte[] html;

    static belongsTo = [doctor:Doctor]

    static constraints = {

        html sqlType: 'blob'
    }
}

但它在 mySql 数据库中创建了一个 tinyblob 字段。我也尝试过使用 clob 而不是 blob。 如何使用 BLOB 在数据库中存储大数据?

您可以添加约束条件

static mapping = {
    html (type:’longblob’)
}

下面显示了 Mysql 支持的不同类型的 Blob 数据类型及其大小

TINYBLOB: 最大长度为 255 字节

BLOB: 最大长度为 65,535 字节

MEDIUMBLOB: 最大长度为 16,777,215 字节

LONGBLOB: 最大长度为 4,294,967,295 字节