From 21c085917a15fce5a501b7d6ddc2062b0f253ec5 Mon Sep 17 00:00:00 2001 From: Ismailov_Rovshan Date: Mon, 3 Apr 2023 13:23:33 +0400 Subject: [PATCH] Lab03_1 --- build.gradle | 5 ++ src/main/java/SocialNetwork/model/User.java | 70 +++++++++++++++++++++ src/main/resources/application.properties | 12 +++- 3 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 src/main/java/SocialNetwork/model/User.java diff --git a/build.gradle b/build.gradle index 40bbb42..482c489 100644 --- a/build.gradle +++ b/build.gradle @@ -15,6 +15,11 @@ repositories { dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' testImplementation 'org.springframework.boot:spring-boot-starter-test' + implementation 'org.springframework.boot:spring-boot-starter-data-jpa' + implementation 'com.h2database:h2:2.1.210' + implementation group: 'org.springdoc', name: 'springdoc-openapi-ui', version: '1.6.5' + implementation 'org.hibernate.validator:hibernate-validator:7.0.1.Final' + } tasks.named('test') { diff --git a/src/main/java/SocialNetwork/model/User.java b/src/main/java/SocialNetwork/model/User.java new file mode 100644 index 0000000..20201d5 --- /dev/null +++ b/src/main/java/SocialNetwork/model/User.java @@ -0,0 +1,70 @@ +package SocialNetwork.model; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import java.util.Objects; + + +@Entity +public class User { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + @Column() + private String firstName; + private String lastName; + + public User() { + } + + public User(String firstName, String lastName) { + this.firstName = firstName; + this.lastName = lastName; + } + + public Long getId() { + return id; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + User user = (User) o; + return Objects.equals(id, user.id); + } + + @Override + public int hashCode() { + return Objects.hash(id); + } + + @Override + public String toString() { + return "Student{" + + "id=" + id + + ", firstName='" + firstName + '\'' + + ", lastName='" + lastName + '\'' + + '}'; + } + +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 8b13789..da7b0b1 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1 +1,11 @@ - +spring.main.banner-mode=off +#server.port=8080 +spring.datasource.url=jdbc:h2:file:./data +spring.datasource.driverClassName=org.h2.Driver +spring.datasource.username=sa +spring.datasource.password=password +spring.jpa.database-platform=org.hibernate.dialect.H2Dialect +spring.jpa.hibernate.ddl-auto=update +spring.h2.console.enabled=true +spring.h2.console.settings.trace=false +spring.h2.console.settings.web-allow-others=false