KEMBAR78
Activity 7 | PDF
0% found this document useful (0 votes)
4 views3 pages

Activity 7

Uploaded by

bmrajesh2007
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Activity 7

Uploaded by

bmrajesh2007
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

model/Employee.

java
package com.example.employeedetails.model;
public class Employee {
private int id;
private String name;
private String department;
private double salary;

public Employee() {
}
public Employee(int id, String name, String department, double salary) {
this.id = id;
this.name = name;
this.department = department;
this.salary = salary;
}

// Getters and setters


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 getDepartment() {


return department;
}
public void setDepartment(String department) {
this.department = department;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
}

service/EmployeeService.java
import java.util.ArrayList;
import java.util.List;
@Service
public class EmployeeService {
private final List<Employee> employeeList = new ArrayList<>();
public List<Employee> getAllEmployees() {
return employeeList;
}
public void addEmployee(Employee employee) {
employeeList.add(employee);
}
}

controller/EmployeeController.java
import java.util.List;
@RestController
@RequestMapping("/employees")
public class EmployeeController {
@Autowired
private EmployeeService employeeService;

@GetMapping
public List<Employee> getAllEmployees() {
return employeeService.getAllEmployees();
}
@PostMapping
public String addEmployee(@RequestBody Employee employee) {
employeeService.addEmployee(employee);
return "Employee added successfully!";
}
}

You might also like