xxxController.java

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;
    }
}
 


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值