在工作中我们总是避免不了需要一些测试数据的支持,可是动辄成千上万条的数据编写起来让我们头痛不已,尤其是一些刁钻的场景还需要“假数据”不那么“假”,因此我们可以使用javafaker来实现假数据的制作。
<dependency>
<groupId>com.github.javafaker</groupId>
<artifactId>javafaker</artifactId>
<version>1.0.2</version>
</dependency>
Faker faker = new Faker(); //创建JavaFaker对象
String name = faker.name().fullName(); // Miss Samanta Schmidt
String firstName = faker.name().firstName(); // Emory
String lastName = faker.name().lastName(); // Barton
String streetAddress = faker.address().streetAddress(); // 60018 Sawayn Brooks Suite 449
Faker faker = new Faker(new Locale("YOUR_LOCALE"));
//示例:如果想使用中国的数据
Faker faker = new Faker(Locale.CHINA);
bg
ca
ca-CAT
da-DK
de
de-AT
de-CH
en
en-AU
en-au-ocker
en-BORK
en-CA
en-GB
en-IND
en-MS
en-NEP
en-NG
en-NZ
en-PAK
en-SG
en-UG
en-US
en-ZA
es
es-MX
fa
fi-FI
fr
he
hu
in-ID
it
ja
ko
nb-NO
nl
pl
pt
pt-BR
ru
sk
sv
sv-SE
tr
uk
vi
zh-CN
zh-TW
Address
Ancient
Animal
App
Aqua Teen Hunger Force
Artist
Avatar
Back To The Future
Aviation
Basketball
Beer
Bojack Horseman
Book
Bool
Business
ChuckNorris
Cat
Code
Coin
Color
Commerce
Company
Crypto
DateAndTime
Demographic
Disease
Dog
DragonBall
Dune
Educator
Esports
EnglandFootBall
File
Finance
Food
Friends
FunnyName
GameOfThrones
Gender
Hacker
HarryPotter
Hipster
HitchhikersGuideToTheGalaxy
Hobbit
HowIMetYourMother
IdNumber
Internet
Job
Kaamelott
LeagueOfLegends
Lebowski
LordOfTheRings
Lorem
Matz
Music
Name
Nation
Number
Options
Overwatch
PhoneNumber
Photography
Pokemon
Princess Bride
Relationship Terms
RickAndMorty
Robin
RockBand
Shakespeare
Sip
SlackEmoji
Space
StarCraft
StarTrek
Stock
Superhero
Team
TwinPeaks
University
Weather
Witcher
Yoda
Zelda
最后欢迎大家来讨论补充~~