Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Сущность
- **/
- @Entity
- @Table(name = "que")
- public class Que {
- @Id
- @GeneratedValue(strategy = GenerationType.AUTO)
- private Long id;
- private String queName;
- private String queDescription;
- public Que(){}
- public Que(String queName, String queDescription) {
- this.queName = queName;
- this.queDescription = queDescription;
- }
- public Long getId() {
- return id;
- }
- public void setId(Long id) {
- this.id = id;
- }
- public String getQueName() {
- return queName;
- }
- public void setQueName(String queName) {
- this.queName = queName;
- }
- public String getQueDescription() {
- return queDescription;
- }
- public void setQueDescription(String queDescription) {
- this.queDescription = queDescription;
- }
- }
- /**
- * Репозиторий
- */
- public interface QueRepo extends CrudRepository<Que, Long> {
- }
- /**
- * Контроллер
- */
- @Controller
- public class QueController {
- @Autowired
- private QueRepo queRepo;
- @GetMapping("/que")
- public String createQue(Model model){
- Iterable<Que> ques = queRepo.findAll();
- model.addAttribute("ques", ques);
- return "createQue";
- }
- @PostMapping("/que")
- public String createQue(@RequestParam String queName,
- @RequestParam String queDescription,
- Model model){
- Que que = new Que(queName, queDescription);
- queRepo.save(que);
- Iterable<Que> ques = queRepo.findAll();
- model.addAttribute("ques", ques);
- return "createQue";
- }
- }
- <form method="post">
- <input type="text" name="queName" class="form-control mt-3 col-sm-8 " placeholder="Name of que">
- <input type="text" name="queDescription" class="form-control mt-3 col-sm-8" placeholder="Description">
- <button class="btn btn-outline-info mt-3" formmethod="post" type="submit">Create</button>
- </form>
- <#list ques as que>
- <strong>${que.queName}</strong>
- <i>${que.queDescription}</i>
- </#list>
Add Comment
Please, Sign In to add comment