我现在已经得到了专家表的expertid,我想用HibernateTemplate()里面的方法,给expert这个对象更新一下
,但不知道怎样做,哪位高手能给小弟指点一下?

解决方案 »

  1.   

    那你可以根据这个id去加载对象啊,然后把对象进行修改以后,通过HibernateTemplate去update一下就可以啊!
      

  2.   

    转载::你可以根据这个id去加载对象啊,然后把对象进行修改以后,通过HibernateTemplate去update一下就可以啊! 
     
      

  3.   


    public void updateExpert(Expert expert) {
    getHibernateTemplate().update(expert);
    }public Expert findExpert(Long id) {
    return (Expert)getHibernateTemplate().get(Expert.class, id);
    }
    贴出上面两个方法楼主应该知道怎么做了吧!
      

  4.   

    谢谢了,那个更新会了。
     我还有一个问题,就是用一个超链传一个参数,但是这个超链不是跳到Actiona上,在Actiona里面能用getRequest().getParameter()方法得到那个参数吗?
      

  5.   


    Java code
    public void updateExpert(Expert expert) {
        getHibernateTemplate().update(expert);
    }public Expert findExpert(Long id) {
        return (Expert)getHibernateTemplate().get(Expert.class, id);
    }
    引用楼上IceWee
    public ActionForward update(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response)
    throws Exception {

    Expert expert= (Client) request.getSession().getAttribute(
    "expert"); MyForm myForm = (MyForm) form;
    myForm.toBean(expert);
    try {
    clientService.updateExpert(expert);
    request.getSession().removeAttribute(Constant.client);
    addSessionMessage(request, "更新成功",false);
    } catch (Exception e) {
    return mapping.findForward("edit");
    }


              return mapping.findForward("list");
    } public ActionForward toUpdate(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response)
    throws Exception {

    Integer id = Integer.valueOf(request.getParameter("id"));
    Client client = clientService.findExpert(id);

    if (client == null) {
    addError(request, "这个不存在", false);
    return mapping.findForward("list");
    }
    //添加到session中,以便在update中更新时使用
                   request.getSession().setAttribute(Constant.client, client);
              request.setAttribute("updateClient", client);
    return mapping.findForward("update");/查询结果提交到页面
    }