Основной класс
Код: Выделить всё
package com.example.kilohokla;
@SpringBootApplication
@EnableJpaRepositories("com.example.kilohokla")
@ComponentScan(basePackages = {"com.example.kilohokla"})
public class HelloApplication extends Application {
private ConfigurableApplicationContext applicationContext;
@Override
public void init() throws Exception {
applicationContext = SpringApplication.run(HelloApplication.class);
}
@Override
public void start(Stage stage) throws IOException {
// AccountsRepository accountsRepository = applicationContext.getBean(AccountsRepository.class);
Logger logger = LogManager.getLogger(HelloApplication.class);
//
// Accounts sampleUser = new Accounts();
// sampleUser.setName("Sample");
// sampleUser.setSurname("User");
// sampleUser.setEmail("sample@example.com");
// sampleUser.setPhoneNumber("123456789");
// sampleUser.setPassword("password");
// sampleUser.setLogin("sample");
// Save the sample user to the database
// accountsRepository.save(sampleUser);
logger.info("Applicaton has launched succesfully");
FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("login-view.fxml"));
Font.loadFont(getClass().getResourceAsStream("/com/example/kilohokla/fonts/Inter/Inter.ttf"), 32);
Scene scene = new Scene(fxmlLoader.load());
stage.setTitle("Kilohokla");
stage.setScene(scene);
stage.show();
}
@Override
public void stop() throws Exception {
applicationContext.stop();
}
public static void main(String[] args) {
launch(HelloApplication.class, args);
}
}
Код: Выделить всё
@Repository
public interface AccountsRepository extends JpaRepository {
void save(Accounts account);
}
Код: Выделить всё
@Entity
@Table(name = "accounts")
public class Accounts {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long accountID;
@ManyToOne
@JoinColumn(name = "permissionID")
private Permissions permission;
private String name;
private String surname;
private String email;
private String phoneNumber;
private String password;
private String login;
@ManyToOne
@JoinColumn(name = "teamID")
private Teams team;
Код: Выделить всё
@Controller
public class AccountsController {
@Autowired
private AccountService accountService;
public AccountsController() {
}
@PostMapping("/addAccount")
public String addAccount(Accounts account) {
accountService.addAccount(account);
return "redirect:/";
}
}
Код: Выделить всё
@Service
public class AccountService {
@Autowired
private AccountsRepository accountsRepository;
@Transactional
public void addAccount(Accounts account) {
accountsRepository.saveAndFlush(account);
}
}
Код: Выделить всё
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
org.springframework.boot
spring-boot-starter-parent
3.2.5
com.example
demo
0.0.1-SNAPSHOT
demo
Demo project for Spring Boot
17
org.springframework.boot
spring-boot-starter-data-jpa
org.springframework.boot
spring-boot-starter-web
jakarta.persistence
jakarta.persistence-api
3.1.0
javax.persistence
javax.persistence-api
2.2
org.springframework.boot
spring-boot-starter-test
test
org.openjfx
javafx-controls
17
org.openjfx
javafx-fxml
17
org.springframework.data
spring-data-jpa
2.1.2.RELEASE
mysql
mysql-connector-java
8.0.32
org.springframework.boot
spring-boot-maven-plugin
Подробнее здесь: https://stackoverflow.com/questions/784 ... ed-through