jfinal中的反射使用

jfinal中的model不管是继承Model或者 baseModel ,都实现不了反射;jfinal怎么才能基于bean实现反射?

评论区

JFinal

2016-10-14 23:08

不能使用反射的具体代码是什么样的? 可以在这个贴子里面补充一下,一直是可以用反射的

153655101

2016-10-19 16:34

@JFinal controller中:
public void doExc() throws RowsExceededException, IllegalArgumentException, IllegalAccessException, WriteException, IOException{
Map params = new HashMap();
params.put("pageNumber", 1);
params.put("pageSize", 20);
List sysOperationlist = operationService.getSysOperationLsit(params);
System.out.println(sysOperationlist);
ExcelUtil.DbToExcel((ArrayList) sysOperationlist, "E:/excel/2.xls");
renderNull();
}
DbToExcel方法:
public static void DbToExcel(ArrayList arr, String url) throws
IllegalArgumentException, IllegalAccessException, RowsExceededException, WriteException,IOException {
WritableWorkbook book = null;
try {
book = Workbook.createWorkbook(new File(url));
WritableSheet sheet = book.createSheet("sheet", 0);
System.out.println("-=============arr:"+arr);
for (int i = 0; i < arr.size(); i++) {
Object obj = arr.get(i);
Class clazz = obj.getClass();
Field fields[] = clazz.getDeclaredFields();
for (int j = 0; j < fields.length; j++) {
fields[j].setAccessible(true);
System.out.println("=--==-=-=-==-fields[j].get(obj):"+fields[j].get(obj));
jxl.write.Label la = new jxl.write.Label(j, i,fields[j].get(obj).toString());
sheet.addCell(la);
}
}
book.write();
} catch (IOException e) {
e.printStackTrace();
} finally {
book.close();
}
}
model层:
public class SysOperation extends BaseSysOperation {
public static final SysOperation dao = new SysOperation();
/**
* 查询用户操作的分页数据
* @param params
* @return
*/
public List getSysOperationLsit(Map params){
return dao.find("SELECT * FROM sys_operation ORDER BY add_time DESC LIMIT ?,?;", params.get("pageNumber"), params.get("pageSize"));
}

控制台打印结果:[com.ynwl.cms.model.SysOperation@6d76c8b4 {id:45, operation:编辑广告:23,ID为:30, add_time:2016-10-18 15:34:29.0, account:admin}, com.ynwl.cms.model.SysOperation@6d906955 {id:44, operation:编辑广告:23,ID为:30, add_time:2016-10-18 15:26:25.0, account:admin}, com.ynwl.cms.model.SysOperation@c79082c3 {id:43, operation:新增广告:23, add_time:2016-10-18 15:07:54.0, account:admin}, com.ynwl.cms.model.SysOperation@11b084f1 {id:42, operation:删除广告:无, add_time:2016-10-18 15:07:34.0, account:admin}, com.ynwl.cms.model.SysOperation@a509911 {id:41, operation:编辑CP:友能,ID为:1, add_time:2016-10-14 11:05:33.0, account:admin}, com.ynwl.cms.model.SysOperation@ca02cbaf {id:40, operation:删除游戏类型:weqqwezcazsdfsd, add_time:2016-10-13 13:41:32.0, account:admin}, com.ynwl.cms.model.SysOperation@aa82d6a6 {id:39, operation:编辑游戏类型:weqqwezcazsdfsd,ID为:7, add_time:2016-10-13 13:41:07.0, account:test}, com.ynwl.cms.model.SysOperation@fd79fe69 {id:38, operation:新增游戏类型:weq, add_time:2016-10-13 13:40:57.0, account:test}, com.ynwl.cms.model.SysOperation@13c80a8f {id:37, operation:删除拦截:cdsd, add_time:2016-10-13 13:40:14.0, account:admin}, com.ynwl.cms.model.SysOperation@e36f89a6 {id:36, operation:删除拦截:sdfsdfsfdsdf, add_time:2016-10-13 13:40:09.0, account:admin}, com.ynwl.cms.model.SysOperation@cd2874dc {id:35, operation:编辑拦截:sdfsdfsfdsdf,ID为:1, add_time:2016-10-13 13:40:05.0, account:admin}, com.ynwl.cms.model.SysOperation@6aad18de {id:34, operation:新增拦截:sdfsdf, add_time:2016-10-13 13:40:01.0, account:admin}, com.ynwl.cms.model.SysOperation@c3532465 {id:33, operation:新增拦截类型:cdsd, add_time:2016-10-13 13:39:52.0, account:admin}, com.ynwl.cms.model.SysOperation@3b6eb70d {id:32, operation:删除游戏:西欧昂达, add_time:2016-10-13 12:02:34.0, account:admin}, com.ynwl.cms.model.SysOperation@29e23231 {id:31, operation:编辑游戏:西欧昂达,ID为:16, add_time:2016-10-13 11:51:43.0, account:admin}, com.ynwl.cms.model.SysOperation@b8603019 {id:30, operation:新增游戏:西欧昂达, add_time:2016-10-13 11:43:13.0, account:admin}, com.ynwl.cms.model.SysOperation@c9874634 {id:29, operation:删除游戏类型:竞, add_time:2016-10-13 11:42:07.0, account:admin}, com.ynwl.cms.model.SysOperation@e25c58ff {id:28, operation:编辑游戏类型:竞,ID为:6, add_time:2016-10-13 11:41:39.0, account:admin}, com.ynwl.cms.model.SysOperation@68c04924 {id:27, operation:编辑游戏类型:竞技,ID为:6, add_time:2016-10-13 11:39:09.0, account:admin}, com.ynwl.cms.model.SysOperation@f7eec023 {id:26, operation:新增游戏类型:竞技系列, add_time:2016-10-13 11:34:08.0, account:admin}]
-=============arr:[com.ynwl.cms.model.SysOperation@6d76c8b4 {id:45, operation:编辑广告:23,ID为:30, add_time:2016-10-18 15:34:29.0, account:admin}, com.ynwl.cms.model.SysOperation@6d906955 {id:44, operation:编辑广告:23,ID为:30, add_time:2016-10-18 15:26:25.0, account:admin}, com.ynwl.cms.model.SysOperation@c79082c3 {id:43, operation:新增广告:23, add_time:2016-10-18 15:07:54.0, account:admin}, com.ynwl.cms.model.SysOperation@11b084f1 {id:42, operation:删除广告:无, add_time:2016-10-18 15:07:34.0, account:admin}, com.ynwl.cms.model.SysOperation@a509911 {id:41, operation:编辑CP:友能,ID为:1, add_time:2016-10-14 11:05:33.0, account:admin}, com.ynwl.cms.model.SysOperation@ca02cbaf {id:40, operation:删除游戏类型:weqqwezcazsdfsd, add_time:2016-10-13 13:41:32.0, account:admin}, com.ynwl.cms.model.SysOperation@aa82d6a6 {id:39, operation:编辑游戏类型:weqqwezcazsdfsd,ID为:7, add_time:2016-10-13 13:41:07.0, account:test}, com.ynwl.cms.model.SysOperation@fd79fe69 {id:38, operation:新增游戏类型:weq, add_time:2016-10-13 13:40:57.0, account:test}, com.ynwl.cms.model.SysOperation@13c80a8f {id:37, operation:删除拦截:cdsd, add_time:2016-10-13 13:40:14.0, account:admin}, com.ynwl.cms.model.SysOperation@e36f89a6 {id:36, operation:删除拦截:sdfsdfsfdsdf, add_time:2016-10-13 13:40:09.0, account:admin}, com.ynwl.cms.model.SysOperation@cd2874dc {id:35, operation:编辑拦截:sdfsdfsfdsdf,ID为:1, add_time:2016-10-13 13:40:05.0, account:admin}, com.ynwl.cms.model.SysOperation@6aad18de {id:34, operation:新增拦截:sdfsdf, add_time:2016-10-13 13:40:01.0, account:admin}, com.ynwl.cms.model.SysOperation@c3532465 {id:33, operation:新增拦截类型:cdsd, add_time:2016-10-13 13:39:52.0, account:admin}, com.ynwl.cms.model.SysOperation@3b6eb70d {id:32, operation:删除游戏:西欧昂达, add_time:2016-10-13 12:02:34.0, account:admin}, com.ynwl.cms.model.SysOperation@29e23231 {id:31, operation:编辑游戏:西欧昂达,ID为:16, add_time:2016-10-13 11:51:43.0, account:admin}, com.ynwl.cms.model.SysOperation@b8603019 {id:30, operation:新增游戏:西欧昂达, add_time:2016-10-13 11:43:13.0, account:admin}, com.ynwl.cms.model.SysOperation@c9874634 {id:29, operation:删除游戏类型:竞, add_time:2016-10-13 11:42:07.0, account:admin}, com.ynwl.cms.model.SysOperation@e25c58ff {id:28, operation:编辑游戏类型:竞,ID为:6, add_time:2016-10-13 11:41:39.0, account:admin}, com.ynwl.cms.model.SysOperation@68c04924 {id:27, operation:编辑游戏类型:竞技,ID为:6, add_time:2016-10-13 11:39:09.0, account:admin}, com.ynwl.cms.model.SysOperation@f7eec023 {id:26, operation:新增游戏类型:竞技系列, add_time:2016-10-13 11:34:08.0, account:admin}]
=--==-=-=-==-fields[j].get(obj):com.ynwl.cms.model.SysOperation@0 {}
=--==-=-=-==-fields[j].get(obj):com.ynwl.cms.model.SysOperation@0 {}
=--==-=-=-==-fields[j].get(obj):com.ynwl.cms.model.SysOperation@0 {}
=--==-=-=-==-fields[j].get(obj):com.ynwl.cms.model.SysOperation@0 {}
=--==-=-=-==-fields[j].get(obj):com.ynwl.cms.model.SysOperation@0 {}
=--==-=-=-==-fields[j].get(obj):com.ynwl.cms.model.SysOperation@0 {}
=--==-=-=-==-fields[j].get(obj):com.ynwl.cms.model.SysOperation@0 {}
=--==-=-=-==-fields[j].get(obj):com.ynwl.cms.model.SysOperation@0 {}
=--==-=-=-==-fields[j].get(obj):com.ynwl.cms.model.SysOperation@0 {}
=--==-=-=-==-fields[j].get(obj):com.ynwl.cms.model.SysOperation@0 {}
=--==-=-=-==-fields[j].get(obj):com.ynwl.cms.model.SysOperation@0 {}
=--==-=-=-==-fields[j].get(obj):com.ynwl.cms.model.SysOperation@0 {}
=--==-=-=-==-fields[j].get(obj):com.ynwl.cms.model.SysOperation@0 {}
=--==-=-=-==-fields[j].get(obj):com.ynwl.cms.model.SysOperation@0 {}
=--==-=-=-==-fields[j].get(obj):com.ynwl.cms.model.SysOperation@0 {}
=--==-=-=-==-fields[j].get(obj):com.ynwl.cms.model.SysOperation@0 {}
=--==-=-=-==-fields[j].get(obj):com.ynwl.cms.model.SysOperation@0 {}
=--==-=-=-==-fields[j].get(obj):com.ynwl.cms.model.SysOperation@0 {}
=--==-=-=-==-fields[j].get(obj):com.ynwl.cms.model.SysOperation@0 {}
=--==-=-=-==-fields[j].get(obj):com.ynwl.cms.model.SysOperation@0 {}

麻烦帮忙看下问题在哪里!

JFinal

2016-10-20 10:47

没有任何异常抛出,情况很好啊

153655101

2016-10-22 09:54

@JFinal 关键写入的东西全部都是com.ynwl.cms.model.SysOperation@0 {} ,就是说fields[j].get(obj).toString()拿不到东西!

fmpoffice

2018-06-23 08:36

@153655101 解决了吗?

fmpoffice

2018-06-23 09:04

@JFinal 老大哥,我也遇到这个情况!请问应该怎么处理呢?

热门反馈

扫码入社