zoukankan      html  css  js  c++  java
  • springboot解决utf8mb4类型连接

    在使用springboot默认连接池的情况下,默认使用的是tomcat-jdbc-pool,在处理utf8mb4类型数据的时候,需要大致两步

    1.设置数据库、表、字段的编码类型为utf8mb4

    2.在创建数据库连接之后,要执行一条sql语句“SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci”,这样的数据库连接才可以操作utf8mb4类型的数据的存取。

    在配置数据库连接池的配置上,根据使用的连接池的不同,配置参数也不相同,下面给出springboot使用默认的tomcat连接池的时候,支持utf8mb4的配置。

    spring:

      datasource:
        driver-class-name: com.mysql.jdbc.Driver
        url: jdbc:mysql://*.*.*.*:3306/dbname?useUnicode=true&characterEncoding=utf-8
        username: username
        password: password
        tomcat:
            initSQL: SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci

    转载:https://blog.csdn.net/u013013170/article/details/79209444

  • 相关阅读:
    hlgoj 1766 Cubing
    Reverse Linked List
    String to Integer
    Bitwise AND of Numbers Range
    Best Time to Buy and Sell Stock III
    First Missing Positive
    Permutation Sequence
    Next Permutation
    Gray Code
    Number of Islands
  • 原文地址:https://www.cnblogs.com/fanbi/p/13940432.html
Copyright © 2011-2022 走看看