日期:2014-05-16 浏览次数:20466 次
public classFieldmanage implements java.io.Serializable { // Fields private Integer fieldManageId; private String fieldManageName; private String fieldManageDesc; private String isuse; getter&&setter省略。 }
public classFieldManageDao extendsHibernateEntityDao<Fieldmanage> { public booleanoperaFieldmanage(Fieldmanage fieldmanage){ try { this.saveOrUpdate(fieldmanage); return true; } catch(Exception e) { e.printStackTrace(); } return false; } publicList<Fieldmanage> getFieldmanageList(String name,intstart,int end){ String hql="from Fieldmanage where fieldManageName like '%"+name+"%'"; List<Fieldmanage> list=null; try { Query q = this.getSession().createQuery(hql); q.setFirstResult(start); q.setMaxResults(end); list = q.list(); } catch(Exception e) { e.printStackTrace(); } return list; } public intgetFieldmanageCount(String name){ String hql="select count(*) from Fieldmanage where fieldManageName like '%"+name+"%'"; intcount=0; try { Query q =this.getSession().createQuery(hql); count = Integer.parseInt(q.uniqueResult().toString()); } catch(Exception e) { e.printStackTrace(); } returncount; }
public classFieldManageService { //spring注入 privateFieldManageDao fieldManageDao; public voidsetFieldManageDao(FieldManageDao fieldManageDao) { this.fieldManageDao = fieldManageDao; } public booleanoperaFieldmanage(Fieldmanage fieldmanage){ return fieldManageDao. operaFieldmanage (fieldmanage); } publicList<Fieldmanage> getFieldmanageList (String name,intstart,int end){ List<Fieldmanage> list=null; try { list = fieldManageDao.getFieldmanageList(name, start, end); } catch(Exception e) { e.printStackTrace(); } return list; } public intgetFieldmanageCount(String name){ return fieldManageDao.getFieldmanageCount(name); } }
public classFieldManageAction extends ActionSupport { privateFieldManageService fieldManageService; privateFieldmanage fieldmanage; privateList<Fieldmanage> data; private int totalCount; privateString success; //分页 private int start; private int limit; 均有getter和setter方法,但是service注入进来的方法最好没有get publicString operaFieldmanage(){ try { boolean sign = fieldManageService.operaFieldmanage(fieldmanage); if(sign){ this.setSuccess("true"); }else{ this.setSuccess("false"); } } catch(Exception e) { this.setSuccess("false"); e.printStackTrace(); } return "operaFieldmanage"; } publicString fieldManageList(){ String name=""; try { if(fieldmanage对象和名称是否为null){ name=fieldmanage.getFieldManageName(); } intlimitNo=15; if(limit!=0){ limitNo=limit; } int count = fieldManageService.getFieldmanageCount(name); List<Fieldmanage> list = fieldManageService.getFieldmanageList(name, start, limitNo); this.setData(list); this.setTotalCount(count); } catch(Ex