Web
package com.situ.cotroller; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import com.situ.dao.ClassDao; import com.situ.dao.UserDao; import com.situ.entity.User; import com.situ.utils.JsonInfo; import com.situ.utils.SearchInfo; @Controller @RequestMapping("User") public class UserController { @Autowired UserDao dao; @Autowired ClassDao cdao; @RequestMapping("register") public String register(User u,ModelMap m) { dao.insert(u); return "redirect:../login.html"; } @RequestMapping("index") public String index(@RequestParam(defaultValue="",value="txt") String t,SearchInfo info,ModelMap m) { if(t.length()>0) info.setWhere(" where user.name like '%"+t+"%' "); m.put("list", dao.select(info)); m.put("search", info); m.put("txt",t); return "User/index"; } @RequestMapping("delete") public String delete(int id,ModelMap m) { dao.delete(id); return index("",new SearchInfo(),m); } @RequestMapping("insert") public @ResponseBody JsonInfo insert(User u,ModelMap m) { dao.insert(u); return new JsonInfo(1); } @RequestMapping("update") public @ResponseBody JsonInfo update(User u,ModelMap m) { dao.update(u); return new JsonInfo(1); } @RequestMapping("updatepass") public @ResponseBody JsonInfo updatepass(User u,ModelMap m) { dao.updatepass(u); return new JsonInfo(1); } @RequestMapping("add") public String add(ModelMap m) { m.put("sexs",User.sexs); m.put("classlist",cdao.select()); return "User/edit"; } @RequestMapping("edit") public String edit(int id,ModelMap m) { m.put("info", dao.getById(id)); return add(m); } @RequestMapping("login") public String login(User u,ModelMap m,HttpServletRequest req) { User user=dao.login(u); if(user==null&&u.getPass()!=null) { return "redirect:../login.html"; }else { HttpSession s=req.getSession(); s.setMaxInactiveInterval(100); s.setAttribute("user", user); return "redirect:../index.jsp"; } } }