??????
????????sharding-jdbc????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
?? ??2??????????????Postgresql????
dsjava??dsc
??????????????????java??c
----------------------------------------
?? ????????????2??????
t_staff_male, t_staff_female
????????????????????????
-------------------------------------------
?? ????????????
DROP TABLE "public"."t_staff_male";
CREATE TABLE "public"."t_staff_male" (
"staff_id" varchar(10) NOT NULL,
"staff_name" varchar(16) NOT NULL,
"staff_sex" varchar(8) NOT NULL,
"group_code" varchar(8),
"id_number_plain" varchar(32),
"id_number_cipher" varchar(64)
)
WITH (OIDS=FALSE)
;
ALTER TABLE "public"."t_staff_male" ADD PRIMARY KEY ("staff_id");
--------------------------------------------------------------------------------------
?? ??Springboot2.1.*+Mybatis3.5.* ??????????application.yml????
mybatis:
config-location: classpath:META-INF/mybatis-config.xml
mapper-locations: classpath:com/example/shardingsphere/dao/mappers/*.xml
spring:
shardingsphere:
datasource:
names: dsjava,dsc
dsjava:
type: org.apache.commons.dbcp2.BasicDataSource
driver-class-name: org.postgresql.Driver
url: jdbc:postgresql://127.0.0.1:5444/dsjava
username: fan
password:
dsc:
type: org.apache.commons.dbcp2.BasicDataSource
driver-class-name: org.postgresql.Driver
url: jdbc:postgresql://127.0.0.1:5444/dsc
username: fan
password:
sharding:
default-database-strategy:
inline:
sharding-column: group_code
algorithm-expression: ds$->{group_code}
tables:
t_staff:
actual-data-nodes: ds$->{['java', 'c']}.t_staff_$->{['male',
'female']}
table-strategy:
inline:
sharding-column: staff_sex
algorithm-expression: t_staff_$->{staff_sex}
encrypt:
encryptors:
encryptor_aes:
type: aes
props:
aes.key.value: 123456
tables:
t_staff:
columns:
id_number:
plainColumn: id_number_plain
cipherColumn: id_number_cipher
encryptor: encryptor_aes
props:
sql.show: true
query.with.cipher.comlum: true
---------------------------------------------------------------------------- ??
??StaffMapper.xml <insert id="save" parameterType="staff">
insert into t_staff
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="staffId != null" >
staff_id,
</if>
<if test="staffName != null" >
staff_name,
</if>
<if test="staffSex != null" >
staff_sex,
</if>
<if test="groupCode != null" >
group_code,
</if>
<if test="idNumber != null" >
id_number,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="staffId != null" >
#{staffId},
</if>
<if test="staffName != null" >
#{staffName},
</if>
<if test="staffSex != null" >
#{staffSex},
</if>
<if test="groupCode != null" >
#{groupCode},
</if>
<if test="idNumber != null" >
#{idNumber},
</if>
</trim>
</insert>
---------------------------------------------------------------------- ??
??????????
1????????application.yml????????????????????????????????????t_staff??????????????????????????????????????
2?????????????????????????????? ### Error updating database. Cause:
org.postgresql.util.PSQLException: ????: ???? "t_staff" ??????
??????13
### The error may exist in file
[D:\idea_workspace\sharding-sphere\target\classes\com\example\shardingsphere\dao\mappers\StaffMapper.xml]
### The error may involve com.example.shardingsphere.dao.StaffMapper.save-Inline
### The error occurred while setting parameters
### SQL: insert into t_staff( staff_id, staff_name, staff_sex, group_code,
id_number ) values (?, ?, ?, ?, ? )
### Cause: org.postgresql.util.PSQLException: ????: ???? "t_staff" ??????
??????13; bad SQL grammar []; nested exception is
org.postgresql.util.PSQLException: ????: ???? "t_staff" ?????? ??????13] with
root cause ??????????????????????????????????