我想实现通过id值获得实体类
private Category getEntity(int id) {  不知此处代码怎么写}
哪位高手能帮帮忙啊,刚接触java,谢谢了!

解决方案 »

  1.   

    连接数据库...
    select * from Category where id=@id
    执行sql...
    new 一个Category接收resultset中的结果
    返回Category对象
      

  2.   

    我就是这么写的,不对的,我需要通过id得到实体类的id,然后我在通过这个id找到对应的名字。
      

  3.   

    <s:a href="findStudentById.action?student.id=%{id}">修改</s:a>给你个例子
      

  4.   

    继承 Spring的HibernateDaoSupport 有现成的方法...
      

  5.   

    Category entity = null;
    String sql = "select * from Category where id = ?";
    pstmt = BaseDao.conn().prepareStatement(sql);
    pstmt.setInt(1,id);
    rs = pstmt.executeQuery();
    if(rs.next){
        entity = new Category();
        //给字段赋值
    }
    return entity
      

  6.   

    用struts的框架通常就是通过条件在数据库中查询相关的属性,从而得到想要的实体