【springboot】关于jpa自动建表 DEFAULT CHARSET=latin1 的简单解决方法
程序员文章站
2024-01-26 22:07:11
...
学习http://www.ityouknow.com/spring-boot.html这个系列文章,发现点小问题,就是jpa自动建表默认编码会有问题,找到一个简单的解决方法,如下:
1.新建类
import org.hibernate.dialect.MySQL5InnoDBDialect;
import org.springframework.stereotype.Component;
@Component
@SuppressWarnings("deprecation")
public class MysqlConfig extends MySQL5InnoDBDialect {
@Override
public String getTableTypeString() {
return "ENGINE=InnoDB DEFAULT CHARSET=utf8";
}
}
2.把application.properties文件中的下面第一句注释替换为上面新建类就可以了
#spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
spring.jpa.properties.hibernate.dialect=com.neo.util.MysqlConfig
3.然后去mysql看看show create table 表名; 是否变成 DEFAULT CHARSET=utf8
上一篇: java 线程中run 和start方法