栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

mybatis-plus批处理IService的实现示例

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

mybatis-plus批处理IService的实现示例

一、pom文件引入

    
      org.springframework.boot
      spring-boot-starter
    
    
com.baomidou
 mybatis-plus-boot-starter
 3.3.1.tmp
    
    
 com.baomidou
 mybatis-plus
 3.3.1.tmp
    
     
      mysql
      mysql-connector-java
      runtime
    
    
 org.springframework.boot
spring-boot-starter-web
    

二、Controller层

@RequestMapping("/user")
@RestController
public class UserController {
  @Autowired
   UserInfoService userInfoService;
  
  @RequestMapping("/add")
  public void addUser() {
    userInfoService.addUser();
  }
}

三、IService层(此处请确保继承的是 mybatisplus下的 IService,上述的UserInfoEntity为实体类)

import com.baomidou.mybatisplus.extension.service.IService;
import com.entity.UserInfoEntity;

public interface UserInfoService extends IService{
  
  public void addUser();

}

四、ServiceImpl(UserInfoDao和UserInfoEntitty分别为业务对应的UserEntityDao接口和UserInfoEntitty实体类)

@Service
public class UserInfoServiceImpl extends ServiceImpl implements UserInfoService{
  @Override
  public void addUser() {
    Random r=new Random(100);
    String str="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
     Random random=new Random();
    Set entityList=new HashSet();
    for(int i=0;i<1000000;i++) {
      UserInfoEntity entity=new UserInfoEntity();
      entity.setAge(r.nextInt());
      int number=random.nextInt(62);
      entity.setName(""+str.charAt(number));
      entity.setevaluate("good");
      entity.setFraction(r.nextLong());
      entityList.add(entity);
    }
    this.saveBatch(entityList);
  }

五、entity层

@TableName("user_info")//@TableName中的值对应着表名
@Data
public class UserInfoEntity {

  
  @TableId(type = IdType.AUTO)
  private Long id;
  
  private String name;
  
  private Integer age;
  
  private String skill;
  
  private String evaluate;
  
  private Long fraction;

六、Mapper接口层

@Mapper


public interface UserInfoDao extends baseMapper{

}

到此这篇关于mybatis-plus批处理IService的实现示例的文章就介绍到这了,更多相关mybatis-plus批处理IService内容请搜索考高分网以前的文章或继续浏览下面的相关文章希望大家以后多多支持考高分网!

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/132356.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号