0% found this document useful (0 votes)
5 views

Java Assignment 2 Deepan(Aiml)

report of nlp
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Java Assignment 2 Deepan(Aiml)

report of nlp
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

JAVA APPLICATON

package com.example.demo1;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Demo1Application {

public static void main(String[] args) {


SpringApplication.run(Demo1Application.class, args);
}

EMPLOYEE CODE:
package com.example.demo1;
import lombok.Data;
@Data
public class Employee {
public int id;
public String name;
public String email;

EMPLOYEE SERVCE CODE


package com.example.demo1;

import java.util.List;

public interface EmployeeService {


String createEmployee(Employee employee);
List<Employee> readEmployees();
boolean deleteEmployee(int id);

}
EMPLOYEE SERVICE CODE
package com.example.demo1;

import java.util.List;

import java.util.ArrayList;

public class EmployeeServiceImp implements EmployeeService {


List<Employee> employees = new ArrayList<>();
@Override
public String createEmployee(Employee employee) {
employees.add(employee);
return "Saved successfully";
}

@Override
public List<Employee> readEmployees() {
return employees;
}

@Override
public boolean deleteEmployee(int id) {
employees.remove(id);
return true;

MY CONTROLLER CODE
package com.example.demo1;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

@RestController
public class MyController {
EmployeeService employeeservice = new EmployeeServiceImp();
@GetMapping("get")
public List<Employee> getAllEmployee() {
return employeeservice.readEmployees();
}

@PostMapping("get")
public String CreateEmployee(@RequestBody Employee emp) {
return employeeservice.createEmployee(emp);

}
@DeleteMapping("get/{id}")
public String deleteEmployee(@PathVariable int id){
if(employeeservice.deleteEmployee(id))
return "deleted successfully";
return "not found";

You might also like