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
publicclassUserController{
@Autowired
UserInfoServiceuserInfoService;
@RequestMapping("/add")
publicvoidaddUser(){
userInfoService.addUser();
}
}
三、IService层(此处请确保继承的是mybatisplus下的IService,上述的UserInfoEntity为实体类)
importcom.baomidou.mybatisplus.extension.service.IService; importcom.entity.UserInfoEntity; publicinterfaceUserInfoServiceextendsIService{ publicvoidaddUser(); }
四、ServiceImpl(UserInfoDao和UserInfoEntitty分别为业务对应的UserEntityDao接口和UserInfoEntitty实体类)
@Service publicclassUserInfoServiceImplextendsServiceImplimplementsUserInfoService{ @Override publicvoidaddUser(){ Randomr=newRandom(100); Stringstr="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; Randomrandom=newRandom(); Set entityList=newHashSet (); for(inti=0;i<1000000;i++){ UserInfoEntityentity=newUserInfoEntity(); entity.setAge(r.nextInt()); intnumber=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
publicclassUserInfoEntity{
/**
*主键
*@TableId中可以决定主键的类型,不写会采取默认值,默认值可以在yml中配置
*AUTO:数据库ID自增
*INPUT:用户输入ID
*ID_WORKER:全局唯一ID,Long类型的主键
*ID_WORKER_STR:字符串全局唯一ID
*UUID:全局唯一ID,UUID类型的主键
*NONE:该类型为未设置主键类型
*/
@TableId(type=IdType.AUTO)
privateLongid;
/**
*姓名
*/
privateStringname;
/**
*年龄
*/
privateIntegerage;
/**
*技能
*/
privateStringskill;
/**
*评价
*/
privateStringevaluate;
/**
*分数
*/
privateLongfraction;
六、Mapper接口层
@Mapper publicinterfaceUserInfoDaoextendsBaseMapper{ }
到此这篇关于mybatis-plus批处理IService的实现示例的文章就介绍到这了,更多相关mybatis-plus批处理IService内容请搜索毛票票以前的文章或继续浏览下面的相关文章希望大家以后多多支持毛票票!
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。