NutzCN Logo
问答 自定义sql返回报错
发布于 2529天前 作者 qq_857440e9 1698 次浏览 复制 上一个帖子 下一个帖子
标签:

报这个错不知道该怎么改

java.lang.ClassCastException: org.nutz.lang.util.NutMap cannot be cast to java.util.List
	at org.nutz.dao.impl.sql.NutStatement.getList(NutStatement.java:127)
	at com.panport.depms.system.service.impl.TrainServiceImpl.getTrainTime(TrainServiceImpl.java:198)
	at com.panport.depms.system.module.JXKHManagerModule.newjxkh(JXKHManagerModule.java:338)
	at com.panport.depms.system.module.JXKHManagerModule$$NUTZAOP._aop_invoke(JXKHManagerModule.java:1)
	at org.nutz.aop.InterceptorChain.invoke(InterceptorChain.java:77)
	at org.nutz.aop.InterceptorChain.doChain(InterceptorChain.java:57)
	at org.nutz.aop.interceptor.TransactionInterceptor.filter(TransactionInterceptor.java:34)
	at org.nutz.aop.InterceptorChain.doChain(InterceptorChain.java:60)
	at com.panport.depms.system.module.JXKHManagerModule$$NUTZAOP.newjxkh(JXKHManagerModule.java:1)
	at com.panport.depms.system.module.JXKHManagerModule$FM$newjxkh$62febe830a4a6764c634d9e263964cee.invoke(JXKHManagerModule.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.integration.shiro.NutShiroProcessor.process(NutShiroProcessor.java:126)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at com.panport.nutz.mvc.AccessTokenFilter.process(AccessTokenFilter.java:92)
	at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:62)
	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 com.panport.nutz.mvc.SimpleNutFilter.doFilter(SimpleNutFilter.java:36)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:123)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
	at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
	at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
	at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
	at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
	at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
	at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:506)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:962)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1115)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:748)

想获取sql语句中字段为“studentTime”的值

List<HashMap> y = trainService.getTrainTime(user.getAccount());
								 if(y.get(0).get("studentTime") != "0" || y.get(0).get("teacherTime") != "0")

回调函数:

Cnd cnd = Cnd.where("account", "=", account);
		cnd.desc("finishedDate");
		List<Workload> workload = dao().query(Workload.class, cnd);
		Sql sql = Sqls.create("SELECT " + 
				"	* " + 
				"FROM " + 
				"	( " + 
				"		SELECT " + 
				"			sum(b.time) AS studentTime, " + 
				"			b. NAME AS studentTrain " + 
				"		FROM " + 
				"			sys_train_user a " + 
				"		LEFT JOIN sys_train b ON b.id = a.train_id " + 
				"		WHERE " + 
				"			a.is_teacher = '0' " + 
				"		AND a.account = @A " + 
				"		AND b.date >= @D " + 
				"		AND b.date <= @E " + 
				"	) AS row1, " + 
				"	( " + 
				"		SELECT " + 
				"			sum(b.time) AS teachTime, " + 
				"			b. NAME AS teacherTrain " + 
				"		FROM " + 
				"			sys_train_user a " + 
				"		LEFT JOIN sys_train b ON b.id = a.train_id " + 
				"		WHERE " + 
				"			a.is_teacher = '1' " + 
				"		AND a.account = @B " + 
				"		AND b.date >= @F " + 
				"		AND b.date <= @G " + 
				"	) AS row2");
		sql.setCallback(Sqls.callback.map());
		sql.params().set("A", account);
		sql.params().set("B", account);
		if (workload.size()>0) {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			Date beginDate = workload.get(0).getBeginDate();
			Date endDate = workload.get(0).getEndDate();
			sql.params().set("D", sdf.format(beginDate));
			sql.params().set("E", sdf.format(endDate) + " 23:59:59");
			sql.params().set("F", sdf.format(beginDate));
			sql.params().set("G", sdf.format(endDate) + " 23:59:59");
		}
		dao().execute(sql);
		List<HashMap> maps = sql.getList(HashMap.class);
		return maps;
2 回复

用maps

sql.setCallback(Sqls.callback.maps());
添加回复
请先登陆
回到顶部