File tree Expand file tree Collapse file tree 6 files changed +27
-38
lines changed
springboot-sharding-jdbc/src/main Expand file tree Collapse file tree 6 files changed +27
-38
lines changed Original file line number Diff line number Diff line change @@ -55,6 +55,7 @@ public String insertOrder() {
5555 order .setCreateName ("订单 " + i );
5656 order .setUserId (Long .parseLong (i + "" ));
5757 order .setPrice (new BigDecimal ("" + i ));
58+ order .setPhoneNo ("13651301474" );
5859 orderRepository .insert (order );
5960
6061// TOrderItem orderItem = new TOrderItem();
Original file line number Diff line number Diff line change 11package com .xiaofu .sharding .key ;
22
3- import com .xiaoju .uemc .tinyid .client .utils .TinyId ;
43import org .apache .shardingsphere .spi .keygen .ShardingKeyGenerator ;
54import org .springframework .stereotype .Component ;
65
76import java .util .Properties ;
8- import java .util .concurrent .atomic .AtomicInteger ;
97
108/**
119 * @Author: xiaofu
@@ -28,7 +26,7 @@ public String getType() {
2826 @ Override
2927 public Comparable <?> generateKey () {
3028
31- Long id = TinyId .nextId ("order" );
29+ Long id = null ; // TinyId.nextId("order");
3230
3331 return id ;
3432 }
Original file line number Diff line number Diff line change 11package com .xiaofu .sharding .model ;
22
3+ import lombok .Data ;
4+
35import java .util .Date ;
46
7+ @ Data
58public class TConfig {
69
710 private Long id ;
@@ -11,36 +14,4 @@ public class TConfig {
1114 private Date createTime ;
1215
1316 private Date lastModifyTime ;
14-
15- public Long getId () {
16- return id ;
17- }
18-
19- public void setId (Long id ) {
20- this .id = id ;
21- }
22-
23- public String getRemark () {
24- return remark ;
25- }
26-
27- public void setRemark (String remark ) {
28- this .remark = remark == null ? null : remark .trim ();
29- }
30-
31- public Date getCreateTime () {
32- return createTime ;
33- }
34-
35- public void setCreateTime (Date createTime ) {
36- this .createTime = createTime ;
37- }
38-
39- public Date getLastModifyTime () {
40- return lastModifyTime ;
41- }
42-
43- public void setLastModifyTime (Date lastModifyTime ) {
44- this .lastModifyTime = lastModifyTime ;
45- }
4617}
Original file line number Diff line number Diff line change @@ -17,4 +17,10 @@ public class TOrder {
1717 private String createName ;
1818
1919 private BigDecimal price ;
20+
21+ private String phoneNo ;
22+
23+ private String phoneNoPlain ;
24+
25+ private String phoneNoCipher ;
2026}
Original file line number Diff line number Diff line change @@ -33,9 +33,23 @@ spring.shardingsphere.sharding.tables.t_order.key-generator.column=order_id
3333spring.shardingsphere.sharding.tables.t_order.key-generator.type =SNOWFLAKE
3434# 工作机器唯一 id
3535spring.shardingsphere.sharding.tables.t_order.key-generator.props.worker.id =0000
36- #
36+ # 时钟回拨最大容忍值
3737spring.shardingsphere.sharding.tables.t_order.key-generator.max.tolerate.time.difference.milliseconds =5
3838
39+ # 数据脱敏--设置加密器
40+ spring.shardingsphere.encrypt.encryptors.phone_encryptor.type =aes
41+ spring.shardingsphere.encrypt.encryptors.phone_encryptor.props.aes.key.value =123456
42+ spring.shardingsphere.encrypt.encryptors.phone_encryptor.qualifiedColumns = t_order.phone_no
43+
44+
45+ # 数据脱敏--密文字段和明文字段
46+ spring.shardingsphere.encrypt.tables.t_order.columns.phone_no.plainColumn =phone_no_plain
47+ spring.shardingsphere.encrypt.tables.t_order.columns.phone_no.cipherColumn =phone_no_cipher
48+ spring.shardingsphere.encrypt.tables.t_order.columns.phone_no.encryptor =phone_encryptor
49+
50+ # 数据脱敏--查询时是否查询密文
51+ spring.shardingsphere.props.query.with.cipher.comlum =true
52+
3953# 配置分片表 t_order_item
4054spring.shardingsphere.sharding.tables.t_order_item.actual-data-nodes =ds-$->{0..1}.t_order_item_$->{0..2}
4155spring.shardingsphere.sharding.tables.t_order_item.database-strategy.inline.sharding-column =order_id
@@ -65,4 +79,3 @@ spring.devtools.restart.enabled=true
6579
6680
6781
68-
Original file line number Diff line number Diff line change 3333 <property name =" enableSubPackages" value =" false" />
3434 </javaClientGenerator >
3535
36- <table tableName =" t_config " enableCountByExample =" false" enableDeleteByExample =" false"
36+ <table tableName =" t_order_1 " enableCountByExample =" false" enableDeleteByExample =" false"
3737 enableSelectByExample =" false" enableUpdateByExample =" false" />
3838 </context >
3939</generatorConfiguration >
You can’t perform that action at this time.
0 commit comments