HQL:
public boolean docreate (Dept vo) throws Exception {return this.sessionFactory.getCurrentSession (). Save (VO)! = null;} @Overridepublic boolean doupdate (Dept vo) throws Exception {String hql = "UPDATE Dept as D SET d.title=?" WHERE d.deptid=? "; Query query = this.sessionFactory.getCurrentSession (). CreateQuery (HQL); query.setstring (0, Vo.gettitle ()); Query.setinteger (1, Vo.getdeptid ()); return query.executeupdate () > 0;} @Overridepublic Boolean doremove (Integer id) throws Exception {String hql = "DELETE from Dept as D WHERE d.deptid=?"; Query query = this.sessionFactory.getCurrentSession (). CreateQuery (HQL); Query.setinteger (0, id); return Query.executeupdate () > 0;} @Overridepublic Dept FindByID (Integer id) throws Exception {return (Dept) this.sessionFactory.getCurrentSession (). Get ( Dept.class,id);} @SuppressWarnings ("unchecked") @Overridepublic list<tcataloginfo> FindAll () throws Exception {String hql = "from Tcataloginfo as TC "; Query query = this.sessionFactory.getCurrentSession (). createquEry (HQL); return query.list ();} @SuppressWarnings ("unchecked") @Override//Paging public list<tcataloginfo> findAll (string column, String KeyWord, Integer currentpage, Integer linesize) throws Exception {String hql = "from Tcataloginfo as TC WHERE TC." + column + "LIK E? "; Query query = this.sessionFactory.getCurrentSession (). CreateQuery (HQL); query.setstring (0, "%" + KeyWord + "%");// Query keyword Query.setfirstresult ((currentPage-1) * linesize);//Start Page query.setmaxresults (linesize);//maximum number of pages loaded return Query.list ();} @Overridepublic Integer getallcount (String column, String KeyWord) throws Exception {string hql = "Select COUNT (tc.cid) FR OM Tcataloginfo as TC WHERE TC. " + column + "like?"; Query query = this.sessionFactory.getCurrentSession (). CreateQuery (HQL); query.setstring (0, "%" + KeyWord + "%"); return ( (Long) Query.uniqueresult ()). Intvalue ();}
Criteria:
Public list<admin> FindAll () throws Exception {criteria = This.sessionFactory.getCurrentSession (). Createcriteria (Admin.class); return criteria.list ();} @SuppressWarnings ("unchecked") @Overridepublic list<admin> findAll (String column, String Keyword,integer CurrentPage, Integer linesize) throws Exception {criteria = This.sessionFactory.getCurrentSession (). Createcriteria (Admin.class); Criteria.add (restrictions.like (column, "%" + KeyWord + "%")); Criteria.setfirstresult (( CURRENTPAGE-1) * linesize); Criteria.setmaxresults (linesize); return criteria.list ();} @Overridepublic Integer getallcount (String column, String KeyWord) throws Exception {criteria = This.sessionfact Ory.getcurrentsession (). Createcriteria (Admin.class); Projectionlist plist = projections.projectionlist ();p List.add (Projections.rowcount (), "count"); Criteria.setprojection (plist); Adds a collection of statistical functions Criteria.add (restrictions.like (column, "%" + KeyWord + "%")), and return ((Long) Criteria.uniqueresult ()). IntvaLue ();}
HQL and Criteria