NutzCN Logo
问答 nutzDao的cri问题
发布于 2736天前 作者 蛋蛋的忧伤 2051 次浏览 复制 上一个帖子 下一个帖子
标签:

我获取到cri之后,然后用这个条件查询了,然后我想基于这个条件,再加不同的条件,但是我发现我将此cri赋值给另一个new出来的cri时,改变新的cri,原来的cri也改变了,这不是我想要的,我想要的就是原来的一直不改变...

SimpleCriteria cri = Cnd.cri();
cri.where.and("id","=",1);
   SimpleCriteria c2 = new SimpleCriteria();
            c2 = cri;
            c2.where().and(ProductCartfre.PRO_BARCODE, "=", rows.get(i).getPro_barcode());     //cri和c2的条件是一样的.
10 回复

c2=cri; 都指向同一个对象了, 能不一样吗?

可是我的c2是new出来的

好吧.....new出来我重新给他赋值了

我的错...那应该怎么弄呢

这是想复制cri的where语句??

嗯对.我想基于cri加其他条件

for(int i=0; i<rows.size(); i++){

            ProductCartfre fetch = dao.fetch(ProductCartfre.class, Cnd.byCri(cri).and(ProductCartfre.PRO_BARCODE, "=", rows.get(i).getPro_barcode()));
            if(fetch!=null){
                rows.get(i).setCarts(fetch.getFrequence());
            }
        }

Cnd.byCri(cri)也不行...

Cnd.where(cri.where().clone()).and........

只有这个
cri.where().cloneExps()
没有clone方法,这个方法返回LIst...

好了..我用个笨方法写的....

List<SqlExpression> sqlExpressions = cri.where().cloneExps();
        for(int i=0; i<rows.size(); i++){
            SimpleCriteria c3 = Cnd.cri();
            for(SqlExpression s : sqlExpressions){
                c3.where().and(s);
            }
            c3.where().and(ProductCartfre.PRO_BARCODE, "=", rows.get(i).getPro_barcode());
            ProductCartfre fetch = dao.fetch(ProductCartfre.class, c3);
            if(fetch!=null){
                rows.get(i).setCarts(fetch.getFrequence());
            }
        }

真菜啊...我

哇去...这个方式有问题啊....莫名其妙多加了几个and

[DEBUG] 11:56:27.010 org.nutz.plugins.cache.dao.CachedNutDaoExecutor.exec(CachedNutDaoExecutor.java:110) - parser SQL sql, skip cache detect!! SQL=SELECT * FROM product_cartfre  WHERE create_time>? AND  AND  AND create_time<? AND pro_barcode=? LIMIT 0, 1 
[DEBUG] 11:56:27.012 org.nutz.dao.impl.sql.run.NutDaoExecutor._runSelect(NutDaoExecutor.java:211) - SELECT * FROM product_cartfre  WHERE create_time>? AND  AND  AND create_time<? AND pro_barcode=? LIMIT 0, 1 
    |                1 |                2 |       3 |
    |------------------|------------------|---------|
    | 2017-06-01 11:54 | 2017-06-28 11:54 | 1000017 |
  For example:> "SELECT * FROM product_cartfre  WHERE create_time>'2017-06-01 11:54' AND  AND  AND create_time<'2017-06-28 11:54' AND pro_barcode='1000017' LIMIT 0, 1 "
[ERROR] 11:56:27.014 com.alibaba.druid.filter.stat.StatFilter.mergeSql(StatFilter.java:147) - merge sql error, dbType mysql, sql : 
SELECT * FROM product_cartfre  WHERE create_time>? AND  AND  AND create_time<? AND pro_barcode=? LIMIT 0, 1 
com.alibaba.druid.sql.parser.ParserException: ERROR. token : AND, pos : 59
	at com.alibaba.druid.sql.parser.SQLExprParser.primary(SQLExprParser.java:587)
	at com.alibaba.druid.sql.dialect.mysql.parser.MySqlExprParser.primary(MySqlExprParser.java:167)
	at com.alibaba.druid.sql.parser.SQLExprParser.bitXor(SQLExprParser.java:120)
	at com.alibaba.druid.sql.parser.SQLExprParser.multiplicative(SQLExprParser.java:157)
	at com.alibaba.druid.sql.parser.SQLExprParser.additive(SQLExprParser.java:1246)
	at com.alibaba.druid.sql.parser.SQLExprParser.shift(SQLExprParser.java:1274)
	at com.alibaba.druid.sql.parser.SQLExprParser.bitAnd(SQLExprParser.java:1152)
	at com.alibaba.druid.sql.parser.SQLExprParser.bitOr(SQLExprParser.java:1166)
	at com.alibaba.druid.sql.parser.SQLExprParser.equality(SQLExprParser.java:1181)
	at com.alibaba.druid.sql.parser.SQLExprParser.relational(SQLExprParser.java:1353)
	at com.alibaba.druid.sql.parser.SQLExprParser.andRest(SQLExprParser.java:1311)
	at com.alibaba.druid.sql.parser.SQLExprParser.exprRest(SQLExprParser.java:113)
	at com.alibaba.druid.sql.parser.SQLExprParser.expr(SQLExprParser.java:100)
	at com.alibaba.druid.sql.parser.SQLSelectParser.expr(SQLSelectParser.java:527)
	at com.alibaba.druid.sql.parser.SQLSelectParser.parseWhere(SQLSelectParser.java:247)
	at com.alibaba.druid.sql.dialect.mysql.parser.MySqlSelectParser.query(MySqlSelectParser.java:160)
	at com.alibaba.druid.sql.parser.SQLSelectParser.select(SQLSelectParser.java:62)
	at com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser.parseSelect(MySqlStatementParser.java:237)
	at com.alibaba.druid.sql.parser.SQLStatementParser.parseStatementList(SQLStatementParser.java:183)
	at com.alibaba.druid.sql.parser.SQLStatementParser.parseStatementList(SQLStatementParser.java:148)
	at com.alibaba.druid.sql.parser.SQLStatementParser.parseStatementList(SQLStatementParser.java:143)
	at com.alibaba.druid.sql.visitor.ParameterizedOutputVisitorUtils.parameterize(ParameterizedOutputVisitorUtils.java:54)
	at com.alibaba.druid.filter.stat.StatFilter.mergeSql(StatFilter.java:145)
	at com.alibaba.druid.filter.stat.StatFilter.createSqlStat(StatFilter.java:630)
	at com.alibaba.druid.filter.stat.StatFilter.statementPrepareAfter(StatFilter.java:305)
	at com.alibaba.druid.filter.FilterEventAdapter.connection_prepareStatement(FilterEventAdapter.java:146)
	at com.alibaba.druid.filter.FilterChainImpl.connection_prepareStatement(FilterChainImpl.java:471)
	at com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl.prepareStatement(ConnectionProxyImpl.java:375)
	at com.alibaba.druid.pool.DruidPooledConnection.prepareStatement(DruidPooledConnection.java:369)
	at org.nutz.dao.impl.sql.run.NutDaoExecutor._runSelect(NutDaoExecutor.java:217)
	at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:45)
	at org.nutz.plugins.cache.dao.CachedNutDaoExecutor.exec(CachedNutDaoExecutor.java:111)
	at org.nutz.dao.impl.DaoSupport$DaoExec.invoke(DaoSupport.java:334)
	at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:59)
	at org.nutz.dao.impl.DaoSupport.run(DaoSupport.java:257)
	at org.nutz.dao.impl.DaoSupport._exec(DaoSupport.java:289)
	at org.nutz.dao.impl.NutDao.fetch(NutDao.java:565)
	at com.yixin.xv.admin.controller.ProductFrequenceController.list(ProductFrequenceController.java:85)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	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:58)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at me.zouooh.mvc.shiro.NutShiroProcessor.process(NutShiroProcessor.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.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at com.yixin.xv.admin.mvc.VmcProcessor.process(VmcProcessor.java:54)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at me.zouooh.mvc.LogTimeProcessor.process(LogTimeProcessor.java:22)
	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:198)
	at me.zouooh.mvc.BurroFilter.doFilter(BurroFilter.java:38)
添加回复
请先登陆
回到顶部