用springmvc和mystaic框架写增删改查
发布网友
发布时间:2022-12-31 13:20
我来回答
共1个回答
热心网友
时间:2023-11-03 01:00
package com.qm.smm.web;
002
003 import java.util.List;
004
005 import javax.annotation.Resource;
006 import javax.servlet.http.HttpServletRequest;
007 import javax.servlet.http.HttpServletResponse;
008
009 import org.apache.commons.codec.digest.DigestUtils;
010 import org.springframework.stereotype.Controller;
011 import org.springframework.web.bind.annotation.RequestMapping;
012
013 import com.qm.smm.entity.User;
014 import com.qm.smm.service.IUserService;
015
016 /**
017 * 控制层
018 * @author quanmin
019 *
020 */
021 @Controller
022 public class UserController{
023
024 @Resource(name="userService")
025 private IUserService userService;
026 /**
027 * 更新
028 * @return
029 */
030 @RequestMapping(value="/updateUser")
031 public String updateUser(HttpServletRequest request,User user){
032 userService.update(user.getId());
033 return "redirect:/findUserList.do";
034 }
035 /**
036 * 删除
037 * @param request
038 * @param user
039 * @return
040 */
041 @RequestMapping(value="/deleteUser")
042 public String deleteUser(HttpServletRequest request,User user){
043 userService.delete(user.getId());
044 return "redirect:/findUserList.do";
045 }
046 /**
047 * 查找所有
048 * @param request
049 * @return
050 */
051 @RequestMapping(value="/findUserList")
052 public String findUserList(HttpServletRequest request){
053 List<User> userList=userService.findUserList();
054 request.setAttribute("userList", userList);
055 return "list_user";
056 }
057
058 /**
059 * 跳转到添加用户
060 * @param request
061 * @return
062 */
063 @RequestMapping("/toAddUser")
064 public String toAddUser(HttpServletRequest request){
065 return "/add";
066 }
067 /**
068 * 查找一个
069 * @param request
070 * @param user
071 * @return
072 */
073 @RequestMapping("/findOne")
074 public String findOne(HttpServletRequest request,User user){
075 user=userService.selectUser(user.getId());
076 request.setAttribute("u", user);
077 return "/edit";
078 }
079 /**
080 * 登录
081 * @param request
082 * @param response
083 * @param user
084 * @return
085 */
086 @RequestMapping(value="/login")
087 public String login(HttpServletRequest request,HttpServletResponse response,User user){
088 User ul=userService.login(user.getName(),DigestUtils.md5Hex(user.getPwd()));
089 //User ul=userService.login(user.getName(),user.getPwd());
090 if(ul!=null){
091 return "redirect:index.jsp";
092 }else{
093 return "redirect:erro.jsp";
094 }
095 }
096 /**