【问题标题】:how to post-convert all strings getters within package?如何后转换包中的所有字符串获取器?
【发布时间】:2013-11-29 10:30:33
【问题描述】:

假设我在 java 包

中有 java bean

com.mycompany.dto

在这个包中有类他们的字符串有enconings,例如win-1520。当我对他们的属性调用 get 时,我想让他们编码为 utf-8 而不是 win-1250

我想为此创建一个类并在某个地方注册(可能是 package-info.java)并让它自动进行。

你能在这里发布一个sn-p如何配置spring应用程序来做到这一点吗?

提前致谢

【问题讨论】:

  • 一个方面应该是一个很好的解决方案

标签: java spring encoding aop dto


【解决方案1】:

这不是字符串编码在 Java 中的工作方式。字符串与编码无关(尽管它们在内部存储为 UTF16)。将它们转换为字节时只需要编码。

所以你可能有不同的问题。

【讨论】:

  • 我通过在休眠配置中添加以下行解决了这个问题。 <prop key="hibernate.connection.useUnicode">true</prop> <prop key="hibernate.connection.characterEncoding">utf8</prop> <prop key="hibernate.connection.charSet">utf8</prop> 还是谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多