Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.pds.controllers.profiles;
- import com.example.pds.model.roles.RoleRepository;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.boot.CommandLineRunner;
- import org.springframework.core.annotation.Order;
- @Order(1)
- public class ProfileDataLoader implements CommandLineRunner {
- @Autowired
- ProfilesRepository profilesRepository;
- @Autowired
- RoleRepository roleRepository;
- @Override
- public void run(String... args) throws Exception {
- loadProfileData();
- }
- void loadProfileData() {
- if (profilesRepository.count() == 0) {
- Profile profile1 = new Profile();
- profile1.setUsername("Asparuh");
- profile1.setPassword("1234");
- profile1.setEmail("Email");
- profile1.setRole(roleRepository.findRoleById(1));
- Profile profile2 = new Profile();
- profile1.setUsername("Artur");
- profile1.setPassword("1234");
- profile1.setEmail("OtherEmail");
- profile1.setRole(roleRepository.findRoleById(2));
- Profile profile3 = new Profile();
- profile1.setUsername("Spiridon");
- profile1.setPassword("1234");
- profile1.setEmail("EmailEmail");
- profile1.setRole(roleRepository.findRoleById(3));
- Profile profile4 = new Profile();
- profile1.setUsername("Margarit");
- profile1.setPassword("1234");
- profile1.setEmail("SomeEmail");
- profile1.setRole(roleRepository.findRoleById(4));
- profilesRepository.saveAndFlush(profile1);
- profilesRepository.saveAndFlush(profile2);
- profilesRepository.saveAndFlush(profile3);
- profilesRepository.saveAndFlush(profile4);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement