Guest User

Untitled

a guest
Feb 18th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. /**
  2. * Сущность
  3. **/
  4. @Entity
  5. @Table(name = "que")
  6. public class Que {
  7. @Id
  8. @GeneratedValue(strategy = GenerationType.AUTO)
  9. private Long id;
  10.  
  11. private String queName;
  12. private String queDescription;
  13.  
  14. public Que(){}
  15.  
  16. public Que(String queName, String queDescription) {
  17. this.queName = queName;
  18. this.queDescription = queDescription;
  19. }
  20.  
  21. public Long getId() {
  22. return id;
  23. }
  24.  
  25. public void setId(Long id) {
  26. this.id = id;
  27. }
  28.  
  29. public String getQueName() {
  30. return queName;
  31. }
  32.  
  33. public void setQueName(String queName) {
  34. this.queName = queName;
  35. }
  36.  
  37. public String getQueDescription() {
  38. return queDescription;
  39. }
  40.  
  41. public void setQueDescription(String queDescription) {
  42. this.queDescription = queDescription;
  43. }
  44. }
  45.  
  46. /**
  47. * Репозиторий
  48. */
  49. public interface QueRepo extends CrudRepository<Que, Long> {
  50. }
  51.  
  52.  
  53. /**
  54. * Контроллер
  55. */
  56. @Controller
  57. public class QueController {
  58. @Autowired
  59. private QueRepo queRepo;
  60.  
  61. @GetMapping("/que")
  62. public String createQue(Model model){
  63. Iterable<Que> ques = queRepo.findAll();
  64. model.addAttribute("ques", ques);
  65. return "createQue";
  66. }
  67.  
  68. @PostMapping("/que")
  69. public String createQue(@RequestParam String queName,
  70. @RequestParam String queDescription,
  71. Model model){
  72. Que que = new Que(queName, queDescription);
  73. queRepo.save(que);
  74. Iterable<Que> ques = queRepo.findAll();
  75. model.addAttribute("ques", ques);
  76. return "createQue";
  77. }
  78. }
  79.  
  80.  
  81. <form method="post">
  82. <input type="text" name="queName" class="form-control mt-3 col-sm-8 " placeholder="Name of que">
  83. <input type="text" name="queDescription" class="form-control mt-3 col-sm-8" placeholder="Description">
  84. <button class="btn btn-outline-info mt-3" formmethod="post" type="submit">Create</button>
  85. </form>
  86. <#list ques as que>
  87. <strong>${que.queName}</strong>
  88. <i>${que.queDescription}</i>
  89. </#list>
Add Comment
Please, Sign In to add comment