Skip to content

Commit 34e3fb8

Browse files
committed
数据脱敏
1 parent bb5a1e0 commit 34e3fb8

File tree

6 files changed

+27
-38
lines changed

6 files changed

+27
-38
lines changed

springboot-sharding-jdbc/src/main/java/com/xiaofu/sharding/contoller/TestController.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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();

springboot-sharding-jdbc/src/main/java/com/xiaofu/sharding/key/TinyIdShardingKeyGenerator.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
package com.xiaofu.sharding.key;
22

3-
import com.xiaoju.uemc.tinyid.client.utils.TinyId;
43
import org.apache.shardingsphere.spi.keygen.ShardingKeyGenerator;
54
import org.springframework.stereotype.Component;
65

76
import 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
}
Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package com.xiaofu.sharding.model;
22

3+
import lombok.Data;
4+
35
import java.util.Date;
46

7+
@Data
58
public 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
}

springboot-sharding-jdbc/src/main/java/com/xiaofu/sharding/model/TOrder.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

springboot-sharding-jdbc/src/main/resources/application.properties

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,23 @@ spring.shardingsphere.sharding.tables.t_order.key-generator.column=order_id
3333
spring.shardingsphere.sharding.tables.t_order.key-generator.type=SNOWFLAKE
3434
# 工作机器唯一 id
3535
spring.shardingsphere.sharding.tables.t_order.key-generator.props.worker.id=0000
36-
#
36+
# 时钟回拨最大容忍值
3737
spring.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
4054
spring.shardingsphere.sharding.tables.t_order_item.actual-data-nodes=ds-$->{0..1}.t_order_item_$->{0..2}
4155
spring.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-

springboot-sharding-jdbc/src/main/resources/generator/generatorConfig.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
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>

0 commit comments

Comments
 (0)