1、在springboot中的基本运用
-
导入maven依赖
<!--百度UidGenerator-->
<!-- https://mvnrepository.com/artifact/com.chungkui/uid-generator-spring-boot-starter -->
<dependency>
<groupId>com.chungkui</groupId>
<artifactId>uid-generator-spring-boot-starter</artifactId>
<version>1.4-bate</version>
</dependency>
-
编写service实现类
@Service
public class WorkerNodeEntityServiceImpl implements WorkerNodeEntityService {
-
测试是否能生成id
@RestController
public class TestController {
2、在mybatis-plus中整合UidGenerator,配置id自定义生成策略
-
创建CustomIdGenerator类实现IdentifierGenerator接口
@Component
public class CustomIdGenerator implements IdentifierGenerator {
-
在配置类中添加如下配置,添加自定义id生成器到mybatis-plus的全局配置中
@Configuration
public class MpConfig {
-
在实体类中的id属性上添加TableId注解
@Data
转自:https://www.cnblogs.com/lbao/p/17646205.html