2 weiranxi weiranxi 于 2016.09.21 15:18 提问

这些代码我需要查询哪些资料能理解下面的代码

public class TestDao extends HibernateDaoSupport
{
public void save(Test obj)
{
Session sess = this.getSessionFactory().openSession();
Transaction tran = sess.beginTransaction();
try
{
sess.saveOrUpdate(obj);
tran.commit();
}
catch (HibernateException e)
{
tran.rollback();
}
finally
{
sess.close();
}
}

public void delete(Test obj)
{
    Session sess = this.getSessionFactory().openSession();
    Transaction tran = sess.beginTransaction();
    try
    {
        sess.delete(obj);
        tran.commit();
    }
    catch (HibernateException e)
    {
        tran.rollback();
    }
    finally
    {
        sess.close();
    }
}

public Test get(int id)
{
    Session sess = this.getSessionFactory().openSession();
    try
    {
        return (Test) sess.get(Test.class, id);
    }
    finally
    {
        sess.close();
    }
}

private List<Test> findAll_lh(String where)
{
    Session sess = this.getSessionFactory().openSession();
    Collection result = new ArrayList();
    try
    {
        Query query = sess.createQuery(" From  Test a,Test3 b  where a.id=b.testId " + where + " order by a.id ");
        result = query.list();

    }
    finally
    {
        sess.close();
    }
    List<Test> list = new ArrayList<Test>();
    ArrayList sList = (ArrayList) result;
    Iterator iterator1 = sList.iterator();
    while (iterator1.hasNext())
    {
        Object[] o = (Object[]) iterator1.next();
        Test test = (Test) o[0];
        Test3 test3 = (Test3) o[1];

        test.setTest3(test3);
        list.add(test);
        System.out.println("0000000000000=" + test.getTest3().getMingCheng());
    }

    return list;
}

private List<Test> findAll(String where, Pager pager)
{
    String hSql = " From  Test a where 1=1 " + where + " order by id ";
    pager.setRowCount(getAllRowCount(hSql));
    Session sess = this.getSessionFactory().openSession();
    try
    {
        Query query = sess.createQuery(hSql);
        query.setFirstResult(pager.getFirstResult());
        query.setMaxResults(pager.getPageSize());
        return query.list();
    }
    finally
    {
        sess.close();
    }
}

//��������
public int getAllRowCount(String hql)
{
return getHibernateTemplate().find(hql).size();
}

public List<Test> getList(String startTime, String endTime, String mc, Pager pager)

{
    String where = " ";

    where = where + " and " + TypeChange.DateBetweenSql("a.riQi", startTime, endTime);
    if (!TypeChange.toNotNullDao(mc).equals(""))
    {
        where = where + " and   a.mingCheng like '%" + TypeChange.toNotNullDao(mc) + "%'";
    }

    return this.findAll(where, pager);
}

}

1个回答

weiranxi
weiranxi   2016.09.21 15:31
已采纳

看不懂 有没有大神指点一下 好让我知道查阅哪些资料啊

Csdn user default icon
上传中...
上传图片
插入图片