1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
| import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.*; import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.util.List;
/** * Created by Administrator on 2015/12/23. */ @Controller @RequestMapping(value = "/task") public class TaskAct {
private static Logger log = LoggerFactory.getLogger(TaskAct.class);
@Autowired private TaskService taskService; @Autowired private NodeService nodeService;
@RequestMapping(value="/{id}") public @ResponseBody Task json(@PathVariable Integer id,ModelMap model,HttpServletRequest request, HttpServletResponse response){ log.info("id2:"+id); //SFTPUtil.download("192.168.0.180", "root", "zzcm2014", "/opt", "cid.jar", "D:/test/aaaa.jar"); //ResponseUtils.renderJson(response, "true"); return taskService.findById(1); }
@RequestMapping(value="/") public String list(Model model,RedirectAttributes attr){ List<Task> tasks = taskService.getAll(); model.addAttribute("tasks",tasks); //attr.addFlashAttribute(user); //attr.addFlashAttribute("user",user); return "/task/list"; }
@RequestMapping(value="/add",method = RequestMethod.GET) public String add(Model model){ List<Node> nodes =nodeService.getAllNodes(); model.addAttribute("nodes",nodes); return "/task/add"; }
@RequestMapping(value="/add",method = RequestMethod.POST) public String add(@ModelAttribute Task task, Model model){ Node node = nodeService.findById(task.getFrom().getId()); task.setFrom(node); taskService.insertTask(task); return "redirect:/task/"; }
@RequestMapping(value="/update/{id:\\d+}",method = RequestMethod.GET) public String update(@PathVariable Integer id,Model model){ List<Node> nodes =nodeService.getAllNodes(); Task task = taskService.findById(id); if(task.getStatus() != Task.Status.STOP){ return "redirect:/task/"; } model.addAttribute("task",task); model.addAttribute("nodes",nodes); return "/task/add"; }
@RequestMapping(value="/update",method = RequestMethod.POST) public String update(@ModelAttribute Task task, Model model){ //Node node = nodeService.findById(task.getFrom().getId()); //task.setFrom(node); taskService.saveOrUpdate(task); return "redirect:/task/"; }
@RequestMapping(value="/delete/{id}") public String delete(@PathVariable Integer id, Model model){ taskService.deleteTask(id); return "redirect:/task/"; } }
|