首页 > 代码库 > 修改用户功能

修改用户功能

先根据userID获取 其他属性,然后进行修改



<% List<User> lu = (List<User>)request.getAttribute("userlist"); for(User u : lu) { out.print(u+"【<a href=http://www.mamicode.com/‘getOne?userID="+u.getUserID()+"‘>修改</a>】【<a href=http://www.mamicode.com/‘deleteUser?userID="+u.getUserID()+"‘>删除</a>】<br>"); } %>
<!-- 查询单个 -->

<action name="getOne"  class="action.UserAction" method="getOne" >

<result name="fail" >/WEB-INF/pages/fail.jsp</result>
<result >/WEB-INF/pages/xiugaiUser.jsp</result>

</action>
<!-- 修改 -->

<action name="xiugaiUser"  class="action.UserAction" method="xiugaiUser" >

<result name="fail" >/WEB-INF/pages/fail.jsp</result>
<result >index.jsp</result>

</action>

 

//查询单个
    public User getOne(int userID)
    {
        return new UserDAO().getOne(userID);
    }


    //修改
    public User xiugai(int userID,String userName,Date birthday,double money,String password)
    {
        User rtn = new UserDAO().xiugai(userID, userName, birthday, money, password);
        return rtn;
    }
    //查询单个
    public User getOne(int userID)
    {
        init();
            
        User rtn = (User)se.get(User.class,userID);

        destory();
        
        return rtn;
    }
        //修改
    public User xiugai(int userID,String userName,Date birthday,double money,String password)
    {
        init();
        
        User u1 = null;
        
        u1 = (User)se.get(User.class, userID);
        
        u1.setUserName(userName);
        u1.setBirthday(birthday);
        u1.setMoney(money);
        u1.setPassword(password);
        
        destory();
        return u1;
    }
    
    //修改
    public String xiugaiUser()
    {
                
        String rtn = "fail";
        try
        {

            //获取userID
            
            HttpServletRequest hsr = ServletActionContext.getRequest();
            
            String userID = hsr.getParameter("userID");
            String userName = hsr.getParameter("userName");
            
            
            java.text.SimpleDateFormat formatter = new SimpleDateFormat( "yyyy-MM-dd ");
            
            String s= hsr.getParameter("birthday");
            Date date =  formatter.parse(s);
            
            double money =  Double.parseDouble(hsr.getParameter("money"));
            String password = hsr.getParameter("password");
            
    
            //执行查询
        new UserService().xiugai(Integer.parseInt(userID), userName, date, money, password);

            
            rtn = "success";
            
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
        
        return rtn;
        }
    
    
    //查询单个
    public String getOne()
    {
        String rtn = "fail";
        try
        {

            //获取userID
            
            HttpServletRequest hsr = ServletActionContext.getRequest();
            
            String uid = hsr.getParameter("userID");
            
            //执行查询
            User lu = new UserService().getOne(Integer.parseInt(uid));
            
            hsr.setAttribute("userone", lu);
            
            rtn = "success";
            
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
        
        return rtn;
        }
    
    

 

修改用户功能