将 Spring + Hibernate + Sql server 与 unicode 支持集成

The*_*des 5 sql-server unicode spring hibernate

如何使用 sql server 2005 将 Spring 与 Hibernate 集成并获得 Unicode 支持。我尝试了很多不同的方法,但我就是无法让它发挥作用。

表中的列是 nvarchar,Spring 中的字符集是 UTF-8。我可以很好地读取 Unicode 文本(我使用 sql server 管理工具添加的),但写入不起作用,它在数据库中出现乱码。

jdbc 网址是

jdbc:sqlserver://localhost:1433;useUnicode=true;characterEncoding=UTF-8;databaseName=test;
Run Code Online (Sandbox Code Playgroud)

在休眠配置文件中使用这些属性

<property name="hibernate.connection.useUnicode">true</property>
<property name="hibernate.connection.charSet">UTF8</property>
Run Code Online (Sandbox Code Playgroud)

我还有一个过滤器可以更改所有页面的编码

response.setContentType("text/html; charset=UTF-8");
request.setCharacterEncoding("UTF8");

chain.doFilter(request, response);

//do it again, since JSPs will set it to the default
response.setContentType("text/html; charset=UTF-8");
request.setCharacterEncoding("UTF8");
Run Code Online (Sandbox Code Playgroud)

有没有好心人成功地做到了这一点,并且可以提供帮助?

非常感谢!

The*_*des 2

看来您需要将过滤器中的响应和请求编码更改为UTF-8,一切都很好!