SpringBoot中修改MySQL数据库建表方言

SpringBoot集成Hibernate后处理MySQL数据库时创建表的时候会出现乱码,是因为在创建表的时候使用默认的建表语言,需要修改建表语言

一、实现

修改配置数据

# jpa配置参数
# 数据库
spring.jpa.database=MYSQL
# 是否显示sql查询语句
spring.jpa.show-sql=true
spring.jpa.generate-ddl=true  
# Hibernate DDL auto (create, create-drop, update)
spring.jpa.hibernate.ddl-auto=update
spring.jpa.hibernate.naming_strategy=org.hibernate.cfg.ImprovedNamingStrategy  
# spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
# 替换重写后的类
spring.jpa.properties.hibernate.dialect=com.ustcinfo.thinkcloud.common.utilConfig.MySQL5DialectUTF8

重写方法

import org.hibernate.dialect.MySQL5InnoDBDialect;

/**
 * 设置数据库建表方言
 */
public class MySQL5DialectUTF8 extends MySQL5InnoDBDialect {

    @Override
    public String getTableTypeString() {
        return " ENGINE=InnoDB DEFAULT CHARSET=utf8";
    }
}

猜你喜欢

转载自blog.csdn.net/qq_35959573/article/details/80081066