Commit 64b6b796 by Patryk Czarnik

findAll

parent 62450b01
package alx.data; package alx.data;
import alx.model.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import java.util.List;
@Controller @Controller
@RequestMapping("/emps9") @RequestMapping("/emps9")
public class Controller9 { public class Controller9 {
@Autowired
private Repository9 repo;
@GetMapping @GetMapping
public String readAll() { public String readAll(Model model) {
List<Employee> employees = repo.findAll();
model.addAttribute("emps", employees);
return "employees.html"; return "employees.html";
} }
} }
package alx.data;
import alx.model.Employee;
import org.springframework.data.jpa.repository.JpaRepository;
public interface Repository9 extends JpaRepository<Employee, Integer> {
}
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