[Microservice] - Integrate database

This commit is contained in:
Sanjoy Kumer Deb
2020-05-02 00:51:54 +06:00
parent 4c94bde6ac
commit 1737c7e42d
6 changed files with 39 additions and 6 deletions

View File

@@ -29,6 +29,16 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>

Binary file not shown.

View File

@@ -0,0 +1,9 @@
package com.ayoosh.profilemanagement.dao;
import com.ayoosh.profilemanagement.domain.EmployeeProfile;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface ProfileRepository extends JpaRepository<EmployeeProfile,Integer> {
}

View File

@@ -1,8 +1,18 @@
package com.ayoosh.profilemanagement.domain;
public class EmployeeProfile {
private int id;
import javax.persistence.*;
@Entity
@Table(name = "employee_profile")
public class EmployeeProfile {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private int id;
@Column(name = "name")
private String name;
@Column(name = "address")
private String address;
public int getId() {
return id;
}
@@ -27,6 +37,5 @@ public class EmployeeProfile {
this.address = address;
}
private String name;
private String address;
}

View File

@@ -1,6 +1,8 @@
package com.ayoosh.profilemanagement.service;
import com.ayoosh.profilemanagement.dao.ProfileRepository;
import com.ayoosh.profilemanagement.domain.EmployeeProfile;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
@@ -8,15 +10,18 @@ import java.util.List;
@Service
public class EmployeeProfileServiceImpl implements EmployeeProfileService {
@Autowired
ProfileRepository repository;
List<EmployeeProfile> employeeProfileList = new ArrayList<>();
@Override
public void addEmployeeProfile(EmployeeProfile profile) {
employeeProfileList.add(profile);
repository.save(profile);
}
@Override
public List<EmployeeProfile> getEmployeeProfiles() {
return employeeProfileList;
return repository.findAll();
}
}

Binary file not shown.