package com.hp.comtroller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import com.hp.domain.Task;
import com.hp.service.TaskService;
@Controller
@RequestMapping("/task")
public class TaskController {
@Autowired
private TaskService s;
@RequestMapping("/findTaskAll")
public ModelAndView findTaskAll(Task task)
{
ModelAndView mv = new ModelAndView();
mv.addObject("taskList", s.findTaskAll(task));
mv.addObject("pList", s.toAdd());
mv.setViewName("index");
return mv;
}
@RequestMapping("/del/{taskID}")
public ModelAndView del(@PathVariable Integer taskID)
{
ModelAndView mv = new ModelAndView();
s.del(taskID);
mv.setViewName("redirect:/task/findTaskAll");
return mv;
}
@RequestMapping("/update/{taskID}")
public ModelAndView update(@PathVariable Integer taskID)
{
ModelAndView mv = new ModelAndView();
s.update(taskID);
mv.setViewName("redirect:/task/findTaskAll");
return mv;
}
@RequestMapping("/toAdd")
public ModelAndView toAdd()
{
ModelAndView mv = new ModelAndView();
mv.addObject("plist", s.toAdd());
mv.setViewName("add");
return mv;
}
@RequestMapping("/add")
public ModelAndView add(Task task)
{
ModelAndView mv = new ModelAndView();
s.add(task);
mv.setViewName("redirect:/task/findTaskAll");
return mv;
}
}
---------------------------------------------------------------------------------------------------------------------------------
package com.hp.controller;
import java.util.List;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import com.hp.domain.Back;
import com.hp.domain.User;
import com.hp.service.impl.BackServiceImpl;
@Controller
public class BackController {
@Autowired
private BackServiceImpl backServiceImpl;
ModelAndView mv = new ModelAndView();
//登录
@RequestMapping("/login")
public ModelAndView login(User user,HttpSession session)
{
List<User> u =backServiceImpl.login(user);
if(u.size()>0)
{
Integer id = backServiceImpl.findUsers(user.getUname());
System.out.println(id);
//设置session。方便跨页面保存用户信息
session.setAttribute("id",id);
session.setAttribute("uname", user.getUname());
mv.setViewName("redirect:/findAll");
}
else
{
mv.setViewName("login");
}
return mv;
}
//显示所有
@RequestMapping("/findAll")
public ModelAndView findAll(Back back,HttpSession session)
{
String uname = (String)session.getAttribute("uname");
back.setUname(uname);
mv.addObject("findAll", backServiceImpl.findAll(back));
mv.setViewName("index");
return mv;
}
//跳到新增页面
@RequestMapping("/toAdd")
public ModelAndView toAdd(HttpSession session)
{
Integer id = (Integer)session.getAttribute("id");
String uname = (String)session.getAttribute("uname");
mv.addObject("id",id);
mv.addObject("uname",uname);
mv.setViewName("add");
return mv;
}
//新增功能
@RequestMapping("/add")
public ModelAndView add(Back back)
{
backServiceImpl.add(back);
mv.setViewName("redirect:/findAll");
return mv;
}
}