|
| 1 | +package org.capg.controller; |
| 2 | + |
| 3 | +import java.util.List; |
| 4 | + |
| 5 | + |
| 6 | +import org.capg.bean.Employee; |
| 7 | +import org.capg.service.EmployeeService; |
| 8 | +import org.springframework.beans.factory.annotation.Autowired; |
| 9 | +import org.springframework.http.HttpStatus; |
| 10 | +import org.springframework.http.MediaType; |
| 11 | +import org.springframework.http.ResponseEntity; |
| 12 | +import org.springframework.web.bind.annotation.DeleteMapping; |
| 13 | +import org.springframework.web.bind.annotation.GetMapping; |
| 14 | +import org.springframework.web.bind.annotation.PathVariable; |
| 15 | +import org.springframework.web.bind.annotation.PostMapping; |
| 16 | +import org.springframework.web.bind.annotation.PutMapping; |
| 17 | +import org.springframework.web.bind.annotation.RequestBody; |
| 18 | +import org.springframework.web.bind.annotation.RequestMapping; |
| 19 | +import org.springframework.web.bind.annotation.RestController; |
| 20 | + |
| 21 | +@RestController |
| 22 | +@RequestMapping("/employee") |
| 23 | +public class MyController { |
| 24 | + @Autowired |
| 25 | + EmployeeService eservice; |
| 26 | + |
| 27 | + @GetMapping |
| 28 | + public List<Employee> printAllEmployee() { |
| 29 | + return eservice.printAllEmployee(); |
| 30 | + } |
| 31 | + |
| 32 | + @GetMapping("/{empid}") |
| 33 | + public ResponseEntity<Employee> findEmployee(@PathVariable int empid) { |
| 34 | + Employee e=eservice.findEmployee(empid); |
| 35 | + if(e!=null) |
| 36 | + return new ResponseEntity<Employee>(e,HttpStatus.OK); |
| 37 | + else |
| 38 | + return new ResponseEntity<Employee>(HttpStatus.NOT_FOUND); |
| 39 | + } |
| 40 | + //@PostMapping(value="/create", consumes=MediaType.APPLICATION_JSON_VALUE) |
| 41 | + @PostMapping |
| 42 | + public List<Employee> saveEmployee(@RequestBody Employee emp) { |
| 43 | + return eservice.createEmployee(emp); |
| 44 | + } |
| 45 | + @DeleteMapping("/{empid}") |
| 46 | + public List<Employee> deleteEmployee(@PathVariable int empid){ |
| 47 | + return eservice.removeEmployee(empid); |
| 48 | + } |
| 49 | + @PutMapping |
| 50 | + public List<Employee> updateEmployee(@RequestBody Employee emp){ |
| 51 | + return eservice.updateEmployee(emp); |
| 52 | + } |
| 53 | +} |
0 commit comments