Commit c7c1742d by Patryk Czarnik

findById

parent 64b6b796
......@@ -5,9 +5,11 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.List;
import java.util.Optional;
@Controller
@RequestMapping("/emps9")
......@@ -21,4 +23,13 @@ public class Controller9 {
model.addAttribute("emps", employees);
return "employees.html";
}
@GetMapping("/{id}")
public String readOne(@PathVariable("id") Integer employeeId, Model model) {
Optional<Employee> employees = repo.findById(employeeId);
if(employees.isPresent()) {
model.addAttribute("emps", List.of(employees.get()));
}
return "employees.html";
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment