zoukankan      html  css  js  c++  java
  • twitter分布式主键id生成器

    pom

    <!--生成id-->
            <dependency>
                <groupId>com.github.bingoohuang</groupId>
                <artifactId>idworker-client</artifactId>
                <version>1.0</version>
            </dependency>

    添加到spring中

    @Bean
    public Sid returnSid(){
        return new Sid();
    }

    使用方法

    package com.lzh.service.impl;
    
    import com.lzh.dao.VideosMapper;
    import com.lzh.pojo.Videos;
    import com.lzh.service.VideoService;
    import org.n3r.idworker.Sid;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;
    import org.springframework.transaction.annotation.Propagation;
    import org.springframework.transaction.annotation.Transactional;
    
    /**
     * Created by 敲代码的卡卡罗特
     * on 2018/11/3 18:08.
     */
    @Service
    public class VideoServiceImpl implements VideoService {
    
        @Autowired
        private VideosMapper videosMapper;
        @Autowired
        private Sid sid;
    
        @Transactional(propagation = Propagation.REQUIRED)
        @Override
        public String saveVideo(Videos video) {
    
            String id = sid.nextShort();
            video.setId(id);
            videosMapper.insertSelective(video);
    
            return id;
        }
    
    }
  • 相关阅读:
    HDU 1594 find the max
    mongoose 数据库操作2
    我也来开发2048之终极奥义
    cocos2d-x 2.2.0 怎样在lua中注冊回调函数给C++
    windows常用运行命令
    机器学习——Pandas库
    搭建靶场环境
    Ubuntu快速安装MSF
    docker 基本使用
    linux下杀死进程
  • 原文地址:https://www.cnblogs.com/coder-lzh/p/9908363.html
Copyright © 2011-2022 走看看