SHARE
TWEET

Untitled

a guest Jan 23rd, 2020 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.example.demo.controller;
  2.  
  3.  
  4. import com.example.demo.model.Task;
  5. import com.example.demo.service.TaskService;
  6. import com.example.demo.service.UserService;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.stereotype.Controller;
  9. import org.springframework.ui.Model;
  10. import org.springframework.web.bind.annotation.GetMapping;
  11. import org.springframework.web.bind.annotation.PostMapping;
  12.  
  13. import javax.validation.Valid;
  14. import java.time.LocalDateTime;
  15.  
  16.  
  17. @Controller
  18. public class AddController {
  19.  
  20.  
  21.     private TaskService taskService;
  22.     private UserService userService;
  23.  
  24.     @Autowired
  25.     public AddController(TaskService taskService, UserService userService) {
  26.         this.taskService = taskService;
  27.         this.userService = userService;
  28.     }
  29.  
  30.     @GetMapping("/addtask")
  31.     public String add(Task task, Model model){
  32.         return "adds";
  33.     }
  34.  
  35.     @PostMapping("/add")
  36.     public String addTask(@Valid Task task, Model model){
  37.         task.setStart((LocalDateTime) model.getAttribute("start"));
  38.         task.setEnd((LocalDateTime) model.getAttribute("end"));
  39.         taskService.saveTask(task);
  40.         return "mainpage";
  41.     }
  42. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top