简体   繁体   English

使用Dropwizard,Hibernate和MySQL进行UTF-8编码

[英]UTF-8 Encoding using Dropwizard, Hibernate, and MySQL

I have a MySQL database with a Dropwizard Java application sitting on top of it. 我有一个MySQL数据库,在它上面有一个Dropwizard Java应用程序。 I have set up my YAML configuration file according to the Dropwizard Hibernate documentation, but for some reason my responses are not being returned UTF-8 encoded. 我已经根据Dropwizard Hibernate文档设置了我的YAML配置文件,但是由于某些原因,我的回复未以UTF-8编码返回。

In the YAML configuration you must be sure to include a characterEncoding and useUnicode property in addition to the charSet property. 在YAML配置中,您必须确保除了charSet属性之外还包括characterEncodinguseUnicode属性。 An example configuration could look like this (note the properties section): 配置示例如下所示(请注意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

Updating the YAML configuration in addition to adding a charset parameter to the Content-Type header should address the issue. 除了向Content-Type标头添加字符集参数以外,更新YAML配置也应解决此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM