package com.hp.Controller;
import javax.servlet.http.HttpSession;
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.Feed;
import com.hp.domain.User;
import com.hp.service.FeedService;
@Controller
public class FeedController {
@Autowired
private FeedService feedService;
ModelAndView mode = new ModelAndView();
//显示
@RequestMapping("/findselect")
public ModelAndView findselect(Feed feed,HttpSession session)
{
String uname = (String)session.getAttribute("uname");
feed.setUname(uname);
mode.addObject("eistList",feedService.eist());
mode.addObject("findselectList", feedService.findselect(feed));
mode.setViewName("index");
return mode;
}
//登录
@RequestMapping("/login")
public ModelAndView login(User user,HttpSession session)
{
User u = feedService.login(user);
if(u!=null)
{
Integer id = feedService.findUser(user.getUname());
session.setAttribute("id", id);
System.out.println(id);
session.setAttribute("uname", user.getUname());
mode.setViewName("redirect:/findselect");
}
else
{
mode.setViewName("login");
}
return mode;
}
//删除
@RequestMapping("/del/{id}")
public ModelAndView del(@PathVariable Integer id)
{
feedService.del(id);
mode.setViewName("redirect:/findselect");
return mode;
}
//新增带参回显
@RequestMapping("/toadd")
public ModelAndView toadd(HttpSession session)
{
String uname = (String)session.getAttribute("uname");
Integer id = (Integer)session.getAttribute("id");
mode.addObject("uname",uname);
mode.addObject("id",id);
mode.setViewName("add");
return mode;
}
//新增
@RequestMapping("/add")
public ModelAndView add(Feed feed)
{
feedService.add(feed);
mode.setViewName("redirect:/findselect");
return mode;
}
//修改公开和不公开
@RequestMapping("/update/{id}")
public ModelAndView update(@PathVariable Integer id)
{
feedService.update(id);
mode.setViewName("redirect:/findselect");
return mode;
}
}