得之,我幸;不得,我命。------徐志摩
如果我们需要造一些假数据,例如随机姓名之类的,可以使用javaFaker
首先是GAV
|---------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 1 2 3 4 5 6
| hljs xml <!-- javaFaker --> <dependency> <groupId>com.github.javafaker</groupId> <artifactId>javafaker</artifactId> <version>1.0.2</version> </dependency>
|
然后我们可以往数据库放入200
条数据,这里用我们的Faker.instance(Locale.ENGLISH).name().lastName()
生成用户名
|---------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 1 2 3 4 5 6 7 8 9
| hljs java @Resource private MpUserService mpUserService; @Test public void insert() { AtomicInteger index = new AtomicInteger(5); List<UserPO> userList = Stream.generate(() -> UserPO.builder().id(index.getAndIncrement()).username(Faker.instance(Locale.ENGLISH).name().lastName()).password(new BCryptPasswordEncoder().encode("123456")).build()).limit(200).collect(Collectors.toList()); mpUserService.saveBatch(userList); }
|
可以看到都是一些假数据