NutzCN Logo
问答 自定义sql语句的回调函数
发布于 60天前 作者 qq_68fbea12 60 次浏览 复制 上一个帖子 下一个帖子
标签:
String sql="";
		if(type==0){//产品审核
			sql=" select oe.*,sc.commodity_name,oa.admin_name from os_examine oe LEFT JOIN shop_commodity sc ON oe.odd_id=sc.id "
					+" LEFT JOIN user u on sc.shop_id=u.shop_id LEFT JOIN os_admin oa on oe.admin_id=oa.id where type=0 ";
			if(oddId>0){
				sql+=" and u.id="+oddId;
			}
		}
		if(type==1){//采购审核
			sql=" select oe.*,sp.purchase_title,oa.admin_name from os_examine oe LEFT JOIN shop_purchase sp on oe.odd_id=sp.id "
					+" LEFT JOIN os_admin oa on oe.admin_id=oa.id where oe.type=1 ";
			if(oddId>0){
				sql+=" and sp.purchase_facture="+oddId;
			}
		}
		if(type==2){//用户审核
			sql=" select oe.*,ue.user_name,oa.admin_name from os_examine oe LEFT JOIN user ue on oe.odd_id=ue.id "
					+" LEFT JOIN os_admin oa on oe.admin_id=oa.id where oe.type=2 ";
			if(oddId>0){
				sql+=" and ue.id="+oddId;
			}
		}
		if(type==3){//申请参与会展审核
			
		}
		Sql sqly=Sqls.create(sql);
		sqly.setCallback(new SqlCallback() {
			@Override
			public Object invoke(Connection con, ResultSet rs, Sql sq) throws SQLException {
				// TODO Auto-generated method stub
				List<Map<String,Object>> lsit=new LinkedList<Map<String,Object>>();
				ResultSetMetaData  m=rs.getMetaData();
				int count=m.getColumnCount();
				for(int i=1;i<=count;i++){
					Map<String,Object> map=new HashMap<String, Object>();
					map.put(m.getColumnName(i), rs.getObject(i));
					lsit.add(map);
				}
				return lsit;
			}
		});
		dao.execute(sqly);

我想得到回调函数里的list,但是没有实体类,怎么获取数据啊

3 回复
sql.getList(Map.class);

map.put(m.getColumnName(i), rs.getObject(i));

这个rs.getObject(i)等不到数据??

CaseMessage=Before start of result set
	at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:104)
	at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:66)
	at org.nutz.dao.impl.interceptor.DaoLogInterceptor.filter(DaoLogInterceptor.java:22)
	at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:64)
	at org.nutz.dao.DaoInterceptorChain.invoke(DaoInterceptorChain.java:139)
	at org.nutz.dao.impl.sql.run.NutDaoRunner.runCallback(NutDaoRunner.java:158)
	at org.nutz.dao.impl.sql.run.NutDaoRunner._runWithoutTransaction(NutDaoRunner.java:125)
	at org.nutz.dao.impl.sql.run.NutDaoRunner._run(NutDaoRunner.java:92)
	at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:81)
	at org.nutz.dao.impl.DaoSupport.run(DaoSupport.java:245)
	at org.nutz.dao.impl.DaoSupport._exec(DaoSupport.java:257)
	at org.nutz.dao.impl.DaoSupport.execute(DaoSupport.java:241)
	at org.nutz.dao.impl.NutDao.execute(NutDao.java:965)
	at com.tongxin.b2b.dao.Os_examineDao.getOs_examineForSearch(Os_examineDao.java:117)
	at com.tongxin.b2b.service.Os_examineService.getOs_examineForindex(Os_examineService.java:51)
	at com.tongxin.b2b.controller.Main.getOs_examineForindex(Main.java:1628)
	at com.tongxin.b2b.controller.Main$FM$getOs_examineForindex$bb3baebe463d9747c19391253f1a197d.invoke(Main.java)
	at org.nutz.mvc.impl.processor.MethodInvokeProcessor.process(MethodInvokeProcessor.java:31)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:33)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:58)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:123)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
	at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
	at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
	at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
	at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:202)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:509)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1104)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:684)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Unknown Source)

要先调用rs.next()啊

话说,你这个回调跟内置的Sqls.callback.maps()不一样的嘛

添加回复
请先登陆
回到顶部