最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
浅谈java中定义泛型类和定义泛型方法的写法
时间:2022-06-29 01:37:31 编辑:袖梨 来源:一聚教程网
1、方法中的泛型
| 代码如下 | 复制代码 |
publicstatic
FileInputStream fis =null; ObjectInputStream ois =null; Object obj =null;
try{
fis =newFileInputStream(path + fileName); ois =newObjectInputStream(fis); obj = ois.readObject();
}catch(FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); }catch(ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); }catch(IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally{
try{ if( fis!=null) fis.close(); if( ois!=null) ois.close(); }catch(IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }
}
return(T)obj; } | |
2、定义泛型类
| 代码如下 | 复制代码 |
publicclassPageHibernateCallback
privateString hql; privateObject[] params; privateintstartIndex; privateintpageSize;
publicPageHibernateCallback(String hql, Object[] params, intstartIndex,intpageSize) { super(); this.hql = hql; this.params = params; this.startIndex = startIndex; this.pageSize = pageSize; }
publicList SQLException { //1 执行hql语句 Query query = session.createQuery(hql); //2 实际参数 if(params !=null){ for(inti =0; i < params.length ; i ++){ query.setParameter(i, params[i]); } } //3 分页 query.setFirstResult(startIndex); query.setMaxResults(pageSize);
returnquery.list(); }
} | |
相关文章
- SimpleSvmHook:实践指南 09-10
- 灵兽大冒险地府怎么处理-任务条件和触发条件 09-10
- tplink1200g如何设置无线密码(tplink1200g设置无线密码方法) 09-10
- 灵兽大冒险葫芦在哪里在哪有哪些重点-关键信息和实际影响 09-10
- 江湖悠悠食谱配方整理汇总-主要信息和内容重点 09-10
- 灵兽大冒险装备打造流程是什么-概念边界和适用条件 09-10