Advertisement
sipamski

Untitled

May 22nd, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. package com.xsis.batch197.controller;
  2.  
  3. import java.util.List;
  4.  
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.stereotype.Controller;
  7. import org.springframework.ui.Model;
  8. import org.springframework.web.bind.annotation.ModelAttribute;
  9. import org.springframework.web.bind.annotation.PathVariable;
  10. import org.springframework.web.bind.annotation.RequestMapping;
  11.  
  12. import com.xsis.batch197.model.BiodataModel;
  13. import com.xsis.batch197.repository.BiodataRepo;
  14.  
  15. @Controller
  16. public class HomeController {
  17. @Autowired
  18. private BiodataRepo repo;
  19.  
  20. @RequestMapping(value="/home/index")
  21. public String index() {
  22. return "/home/index";
  23. }
  24.  
  25. @RequestMapping(value="/home/save")
  26. public String save(@ModelAttribute BiodataModel biodata) {
  27. repo.save(biodata);
  28. return "redirect:/home/list";
  29. }
  30. @RequestMapping(value="/home/list")
  31. public String list(Model kirim) {
  32. List<BiodataModel> biodataList = repo.findAll();
  33. kirim.addAttribute("biodataList", biodataList);
  34. return "home/list";
  35. }
  36.  
  37. @RequestMapping(value="/home/edit/{id}")
  38. public String edit(Model kirim, @PathVariable(name = "id") Integer id) {
  39. BiodataModel biodataEdit=repo.findById(id).orElse(null);
  40. kirim.addAttribute("biodataEdit", biodataEdit);
  41. return "home/edit";
  42. }
  43. @RequestMapping(value="/home/hapus/{id}")
  44. public String hapus(@PathVariable(name = "id") Integer id) {
  45. BiodataModel biodataEdit=repo.findById(id).orElse(null);
  46. repo.delete(biodataEdit);
  47. return "redirect:/home/list";
  48. }
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement