深度保持探索全栈开发的无限可能
记录技术成长的每一步

SpringBoot 集成百度UidGenerator

拉项目,打包

1、到官方的 github 上下载源代码。

项目地址:https://github.com/baidu/uid-generator

2、导入 IDEA 进行打包。

导包

1、在项目的 resourse 下新建一个 lib 目录,将刚才打好的包放进去;

2、在 pom.xml 中引入。

---
	-------------------
	-------------------
	-----------
	------------
	--------------------------------------------------------------------------------
---

创建表

- - - - ----
- - --- -
- ----
- - - - ------------
- - -----------
-
    -- - - - - - - - --
    --------- ---- - - - - --
    ---- ---- - - - --
    - - - - - - - - - --
    ----------- - - - - - --
    -------- - - - - - --
    ------- - - - - - --
    - -----
-
--- - - - - --- - --

代码编写

在自己的项目中按如下步骤编写代码

1、在 resourse -> mapper -> WorkerNodeMapper.xml

- - -
-- - - - - - --
-- ------

	-- ----- ------
		-- ----- ----- ----- -
		-- ----- ----- ----- -
		-- ----- ----- ----- -
		-- ----- ----- ----- -
		-- ----- ----- ----- -
		-- ----- ----- ----- -
		-- ----- ----- ----- -
	---

	-- ----- ----- ----- ------
		------ ---- ----------- -
			 ----------
			 -----
			 -----
			 ------------
			 ---------
			 -------
		 -
		------ -
		       ------------
		       --------
		       --------
		       --------------
		       ------
		       -----
		-
	---

	-- ----- ------
		------
			---
			----------
			-----
			-----
			------------
			---------
			-------
		----
			-----------
		-----
			--------- - ------- --- ---- - -------
	---

---

2、在 xxx.mapper -> WorkerNodeMapper.java

- ----

- --------------
- ----------
- ----------

-
- - - -
	- ------ - ----- ---- - ------
	- --- ------------------
-

3、在 xxx.worker -> DisposableWorkerIdAssigner.java

- ----

- ------
- ------------
- ------------
- ------------
- ------------
- --------------
- ------------
- ----------

- ------

- - -  - - -
  
	-
	- - -----------------
  
	-
	- - --- -
		- ---------------- - ----
		-------------------------------------
		- ---------------------
	-
  
	- - --- -
		- ---------------- - - ----
		- ------- -
			----------------------------
			--------------------------
			--------------------------
		- - -
			----------------------------
			--------------------------
			------------------------ - - - --------
		-
		- -----------------
	-
  
-

4、在 xxx.config -> CachedUidGeneratorConfig.java

- ----

- ------
- ------------
- ------------
- ------------
- ----------
- ----------

-
- - - -

	-
	- - --- -
		- - ----
	-

	-
	- - --- --------------------------- -
		- ------------------- - - ----
		--------------------------------------------------
		-------------------------
		-------------------------
		-------------------------
		-------------------------
		- --------------------
	-

	-
	- - --- --------------------------- -
		- ------------------ - - ----
		-------------------------------------------------
		------------------------
		------------------------
		------------------------
		------------------------
		------------------------
		------------------------
		- -------------------
	-

-

5、编写测试接口,xxx.controller -> UidTestController.java

- ----

- ----------
- ------------

- ------

-
-
----
- - - -

	-
	- - -------------------

	----
	- - ----
		--
			- ----------------------------
		-- -- ---
			- --
		-
	-

-