NutzCN Logo
问答 自定义sql中 如何查询view中的数据?????
发布于 73天前 作者 wx_7nq6jrsojn0gr1t9bvso 110 次浏览 复制 上一个帖子 下一个帖子
标签:

List listinfo = sql.getList(TopSpecialColumnTxtItemInfo.class);

我想查询通过这个实体类创建的view 改怎么查??? 想用 dao.count() 查询视图中的内容 怎么查???

11 回复

没懂,自定义sql不区分表还是视图的呀,都是一个用法

Sql sql = Sqls.create("SELECT count(*) FROM `t_special_column_txt_item_info` "
				+ "where (id not in (select t_special_column_txt_item_info_id from"
				+ " `t_ee_special_column_txt_item_info` WHERE state=1 ) AND column_id=85) "
				+ "OR (id not in (select t_special_column_txt_item_info_id from "
				+ "`t_ee_special_column_txt_item_info` WHERE state=1 ) AND column_id=25)"
				+ " ORDER BY add_time DESC");
		sql.setCallback(Sqls.callback.entities());
		sql.setEntity(dao.getEntity(Integer.class));
		dao.execute(sql);
		int allcount = sql.getInt();
Need non-arg constructor : int
	at org.nutz.dao.impl.entity.NutEntity.<init>(NutEntity.java:211)
	at org.nutz.dao.impl.entity.AnnotationEntityMaker._createNutEntity(AnnotationEntityMaker.java:558)
	at org.nutz.dao.impl.entity.AnnotationEntityMaker.make(AnnotationEntityMaker.java:89)
	at org.nutz.dao.impl.EntityHolder.getEntity(EntityHolder.java:69)
	at org.nutz.dao.impl.NutDao.getEntity(NutDao.java:646)
	at com.bluefrog.wx.module.JJLDEEModule.allpage(JJLDEEModule.java:1225)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.nutz.mvc.impl.processor.MethodInvokeProcessor.process(MethodInvokeProcessor.java:25)
	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:40)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:119)
	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:179)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java

      这个 为啥会报错呢????

因为int不会是实体,Sqls.callback.xxx 好多非entity回调的

那我这个 如何获取返回的int值呢??? 改成intteger也不对 因为我想获得连表查询的数据总量,如果单纯的从 t_special_column_txt_item_info 表中查数据量会不对, 昨天想了很久还是不知道如何获取

     Sql sql = Sqls.fetchInt("SELECT count(*) FROM `t_special_column_txt_item_info` "
				+ "where (id not in (select t_special_column_txt_item_info_id from"
				+ " `t_ee_special_column_txt_item_info` WHERE state=1 ) AND column_id=85) "
				+ "OR (id not in (select t_special_column_txt_item_info_id from "
				+ "`t_ee_special_column_txt_item_info` WHERE state=1 ) AND column_id=25)"
				+ " ORDER BY add_time DESC");
		dao.execute(sql);
		int allcount = sql.getInt();

java.lang.NullPointerException
这样写报了空指针 int allcount = sql.getInt(); 这一行报的

是不是没数据

或者没执行dao.execute

Sql sql = Sqls.create("SELECT count(*) FROM `t_special_column_txt_item_info` "
				+ "where (id not in (select t_special_column_txt_item_info_id from"
				+ " `t_ee_special_column_txt_item_info` WHERE state=1 ) AND column_id=85) "
				+ "OR (id not in (select t_special_column_txt_item_info_id from "
				+ "`t_ee_special_column_txt_item_info` WHERE state=1 ) AND column_id=25)"
				+ " ORDER BY add_time DESC");
		dao.execute(sql);
		int allcount = sql.getInt();
java.lang.NullPointerException
	at org.nutz.dao.impl.sql.NutStatement.getInt(NutStatement.java:121)
	at com.bluefrog.wx.module.JJLDEEModule.allpage(JJLDEEModule.java:1225)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.nutz.mvc.impl.processor.MethodInvokeProcessor.process(MethodInvokeProcessor.java:25)
	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:40)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:119)
	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:179)
	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

  还是报的那个.....
有数据 这个sql语句在mysql中执行的又407条数据呢

看清楚,我写的是Sqls.fetchInt

好的~ 厉害 厉害 谢谢谢谢谢~~~~ 谢谢 大哥~

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