forked from xkcoding/spring-boot-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
89 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...ing-jdbc/src/main/java/com/xkcoding/sharding/jdbc/config/CustomSnowflakeKeyGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.xkcoding.sharding.jdbc.config; | ||
|
||
import cn.hutool.core.lang.Snowflake; | ||
import io.shardingsphere.core.keygen.KeyGenerator; | ||
|
||
/** | ||
* <p> | ||
* 自定义雪花算法,替换 DefaultKeyGenerator,避免DefaultKeyGenerator生成的id大几率是偶数 | ||
* </p> | ||
* | ||
* @package: com.xkcoding.sharding.jdbc.config | ||
* @description: 自定义雪花算法,替换 DefaultKeyGenerator,避免DefaultKeyGenerator生成的id大几率是偶数 | ||
* @author: yangkai.shen | ||
* @date: Created in 2019-03-26 17:07 | ||
* @copyright: Copyright (c) 2019 | ||
* @version: V1.0 | ||
* @modified: yangkai.shen | ||
*/ | ||
public class CustomSnowflakeKeyGenerator implements KeyGenerator { | ||
private Snowflake snowflake; | ||
|
||
public CustomSnowflakeKeyGenerator(Snowflake snowflake) { | ||
this.snowflake = snowflake; | ||
} | ||
|
||
@Override | ||
public Number generateKey() { | ||
return snowflake.nextId(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters