您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
这篇文章给大家分享的是有关mybatis-plus批处理IService的方法是什么的内容。小编觉得挺实用的,因此分享给大家做个参考。一起跟随小编过来看看吧。
一、pom文件引入
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.3.1.tmp</version> </dependency> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus</artifactId> <version>3.3.1.tmp</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>
二、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<UserInfoEntity>{
public void addUser();
}四、ServiceImpl(UserInfoDao和UserInfoEntitty分别为业务对应的UserEntityDao接口和UserInfoEntitty实体类)
@Service
public class UserInfoServiceImpl extends ServiceImpl<UserInfoDao, UserInfoEntity> implements UserInfoService{
@Override
public void addUser() {
Random r=new Random(100);
String str="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
Random random=new Random();
Set<UserInfoEntity> entityList=new HashSet<UserInfoEntity>();
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中可以决定主键的类型,不写会采取默认值,默认值可以在yml中配置
* AUTO: 数据库ID自增
* INPUT: 用户输入ID
* ID_WORKER: 全局唯一ID,Long类型的主键
* ID_WORKER_STR: 字符串全局唯一ID
* UUID: 全局唯一ID,UUID类型的主键
* NONE: 该类型为未设置主键类型
*/
@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<UserInfoEntity>{
}感谢各位的阅读!关于mybatis-plus批处理IService的方法是什么就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到吧!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。