欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

hibernate中文乱码(&和&)

程序员文章站 2022-05-13 20:53:51
...

1)数据库支持中文;

建表语句类似于下面的

DROP  DATABASE  IF EXISTS XDSCLIENT ;
CREATE DATABASE XDSCLIENT CHARACTER SET 'utf8' COLLATE 'utf8_general_ci';
USE XDSCLIENT;
DROP TABLE IF EXISTS client;
create table client(
	id int primary key auto_increment,
	code varchar(200) not null unique,
	name varchar(200) not null unique,
	registryurl varchar(200) default null,
	registryurlssl varchar(200) default null,
	repositoryurl varchar(200) default null,
	repositoryurlssl varchar(200) default null,
	repositoryID varchar(200) default null unique
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


-- 插入基础数据
insert into client 
	(code,name,registryurl,registryurlssl,repositoryurl,repositoryurlssl,repositoryID)
values(
'ClientA',
'厂商A',
'http://localhost:8010/axis2/services/xdsregistryb',
'https://localhost:8011/axis2/services/xdsregistryb',
'http://localhost:8020/axis2/services/xdsrepositoryb',
'https://localhost:8021/axis2/services/xdsrepositoryb',
'1.3.6.1.4.1.21367.13.2250.2000'
);


insert into client 
	(code,name,registryurl,registryurlssl,repositoryurl,repositoryurlssl,repositoryID)
values(
'ClientB',
'厂商B',
'http://60.191.39.142:7096/registry/axis2/services/xdsregistryb',
'https://60.191.39.142:7096/registry_ssl/axis2/services/xdsregistryb',
'http://60.191.39.142:7096/repository/axis2/services/xdsrepositoryb',
'https://60.191.39.142:7096/repository_ssl/axis2/services/xdsrepositoryb',
'1.19.6.24.109.42.1.5'
);



2)数据库连接带上参数;

jdbc.url=jdbc:mysql://localhost:3306/xdsclient?useUnicode=true&characterEncoding=utf-8

注意点:

a)与符号(&和&)是否需要转意处理

b) characterEncoding=utf-8和characterEncoding=UTF-8等效,即(utf-8不区分大小写)