fthb
package com.example.project_2.controller;
import com.example.project_2.model.employee;
import com.example.project_2.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class EmpController {
@Autowired
EmployeeService employeeService;
@GetMapping("/get/{id}")
public void getById(@PathVariable int id){
employeeService.getById(id);
}
}
package com.example.project_2.Dao;
import com.example.project_2.model.employee;
import jakarta.persistence.Entity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface Erepo extends JpaRepository<employee, Integer> {
}
package com.example.project_2.model;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
@Entity
public class employee {
@Id
private int id;
private String name;
private String cubicle_no;
public employee() {
}
public employee(int id, String name, String cubicle_no) {
this.id = id;
this.name = name;
this.cubicle_no = cubicle_no;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCubicle_no() {
return cubicle_no;
}
public void setCubicle_no(String cubicle_no) {
this.cubicle_no = cubicle_no;
}
@Override
public String toString() {
return "employee{" +
"id=" + id +
", name='" + name + '\'' +
", cubicle_no='" + cubicle_no + '\'' +
'}';
}
}
package com.example.project_2.service;
import com.example.project_2.Dao.Erepo;
import com.example.project_2.model.employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class EmployeeService {
@Autowired
Erepo repo;
public employee getById(int id) {
return repo.getById(id);
}
}