百度UidGenerator在Springboot中的应用
1、在springboot中的基本运用
@Service
public class WorkerNodeEntityServiceImpl implements WorkerNodeEntityService {
@Override
public Long save(WorkerNodeEntity workerNodeEntity) {
@RestController
public class TestController {
@Resource
private UidGenerator uidGenerator;
@GetMapping("/test")
public String test() {
long uid = uidGenerator.getUID();
return uidGenerator.parseUID(uid);
}
}
2、在mybatis-plus中整合UidGenerator,配置id自定义生成策略
@Component
public class CustomIdGenerator implements IdentifierGenerator {
@Resource
private UidGenerator uidGenerator;
@Override
public Number nextId(Object entity) {
@Configuration
public class MpConfig {
@Resource
private CustomIdGenerator customIdGenerator;
@Bean
public GlobalConfig globalConfig() {
GlobalConfig globalConfig = new GlobalConfig();
globalConfig.setMetaObjectHandler(new MyMetaObjectHandler());
@Data
@EqualsAndHashCode(callSuper = false)
@ApiModel(value="StudentInfo对象", description="")
public class StudentInfo extends BaseEntity {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "student_id")
@TableId(value = "student_id", type = IdType.NONE)
private Long studentId;
@ApiModelProperty(value = "年龄")
private Integer age;
@ApiModelProperty(value = "姓名")
private String name;
}