package com.hp.Controller;
import javax.servlet.http.HttpSession;
import org.apache.jasper.tagplugins.jstl.core.Out;
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.BackService;
@Controller
public class BackController {
@Autowired
private BackService backService;
//显示
@RequestMapping("/finselct")
public ModelAndView finselct(Back back,HttpSession session)
{
ModelAndView mode = new ModelAndView();
String uname = (String)session.getAttribute("uname");
back.setUname(uname);
mode.addObject("all",backService.finselct(back));
mode.setViewName("index");
return mode;
}
//登录
@RequestMapping("/login")
public ModelAndView login(User user,HttpSession session)
{
ModelAndView mode = new ModelAndView();
User u = backService.login(user);
if(u!=null)
{
Integer id = backService.findUsers(user.getUname());
//设置session。方便跨页面保存用户信息
System.out.println(id);
session.setAttribute("id", id);
session.setAttribute("uname", user.getUname());
mode.setViewName("redirect:/finselct");
}
else
{
mode.setViewName("login");
}
return mode;
}
//新增回显
@RequestMapping("/toadd")
public ModelAndView toadd(HttpSession session)
{
ModelAndView mode = new ModelAndView();
Integer id = (Integer)session.getAttribute("id");
String uname = (String)session.getAttribute("uname");
mode.addObject("id",id);
mode.addObject("uname",uname);
mode.setViewName("add");
return mode;
}
//新增
@RequestMapping("/add")
public ModelAndView add(Back back)
{
ModelAndView mode = new ModelAndView();
backService.add(back);
mode.setViewName("redirect:/finselct");
return mode;
}
}