【问题标题】:UTF-8 Encoding using Dropwizard, Hibernate, and MySQL使用 Dropwizard、Hibernate 和 MySQL 进行 UTF-8 编码
【发布时间】:2017-01-24 04:28:36
【问题描述】:

我有一个 MySQL 数据库,上面有一个 Dropwizard Java 应用程序。我已经根据Dropwizard Hibernate 文档设置了我的 YAML 配置文件,但由于某种原因,我的响应没有返回 UTF-8 编码。

【问题讨论】:

    标签: mysql hibernate dropwizard


    【解决方案1】:

    在 YAML 配置中,除了 charSet 属性之外,您还必须确保包含 characterEncodinguseUnicode 属性。示例配置可能如下所示(注意properties 部分):

    database:
      driverClass: com.mysql.jdbc.Driver
      user: ...
      password: ...
      url: jdbc:mysql://...
      properties:
        charSet: UTF-8
        characterEncoding: UTF-8
        useUnicode: true
        hibernate.dialect: org.hibernate.dialect.MySQL5InnoDBDialect
      maxWaitForConnection: 1s
      validationQuery: "/* DropWizard Health Check */ SELECT 1"
      minSize: 5
      maxSize: 25
      checkConnectionWhileIdle: false
      checkConnectionOnBorrow: true
    

    adding a charset parameter to the Content-Type header 之外更新 YAML 配置应该可以解决该问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-10-26
      • 2015-03-23
      • 2014-04-09
      • 2012-10-15
      • 2014-02-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多