NutzCN Logo
问答 关于一对多关联查询的查询条件
发布于 1519天前 作者 lq1825 1765 次浏览 复制 上一个帖子 下一个帖子
标签:

列表页筛选条件里的条件不是主表的,比如我想筛选的条件是user表里,这个最后的参数subCnd怎么写呢。现在我这么写点查询之后没反应

 public Object data(@Param("userName") String userName, @Param("mobile") String mobile, @Param("startDate") String startDate, @Param("endDate") String endDate,@Param("length") int length, @Param("start") int start, @Param("draw") int draw, @Param("::order") List<DataTableOrder> order, @Param("::columns") List<DataTableColumn> columns) {
        Cnd cnd = Cnd.NEW().and("delFlag", "=", 0);
        Cnd subCnd = Cnd.NEW();
        if (!Strings.isBlank(userName)) {
            subCnd.and("user.username", "like", "%" + userName + "%");
        }
        if (!Strings.isBlank(mobile)) {
            subCnd.and("user.mobile", "like", "%" + mobile + "%");
        }
    	return appFeedbackService.data(length, start, draw, order, columns, cnd, "dict|user",subCnd);
    }
4 回复

生成的sql是怎样的?


[DEBUG] 15:07:57.395 [DubboServerHandler-192.168.13.59:16887-thread-54] com.alibaba.dubbo.remoting.transport.DecodeHandler - [DUBBO] Decode decodeable message com.alibaba.dubbo.rpc.protocol.dubbo.DecodeableRpcInvocation, dubbo version: 2.6.6, current host: 192.168.13.59 [DEBUG] 15:07:57.421 [DubboServerHandler-192.168.13.59:16887-thread-54] org.nutz.dao.impl.sql.run.NutDaoExecutor - SELECT COUNT(*) FROM app_feedback WHERE delFlag=? | 1 | |---| | 0 | For example:> "SELECT COUNT(*) FROM app_feedback WHERE delFlag=0" [DEBUG] 15:07:57.440 [DubboServerHandler-192.168.13.59:16887-thread-54] org.nutz.dao.impl.interceptor.DaoTimeInterceptor - time=19ms, sql=SELECT COUNT(*) FROM app_feedback WHERE delFlag=0 [DEBUG] 15:07:57.441 [DubboServerHandler-192.168.13.59:16887-thread-54] org.nutz.dao.impl.sql.run.NutDaoExecutor - SELECT * FROM app_feedback WHERE delFlag=? ORDER BY feedTime DESC LIMIT 0, 20 | 1 | |---| | 0 | For example:> "SELECT * FROM app_feedback WHERE delFlag=0 ORDER BY feedTime DESC LIMIT 0, 20 " [DEBUG] 15:07:57.460 [DubboServerHandler-192.168.13.59:16887-thread-54] org.nutz.dao.impl.interceptor.DaoTimeInterceptor - time=19ms, sql=SELECT * FROM app_feedback WHERE delFlag=0 ORDER BY feedTime DESC LIMIT 0, 20 [DEBUG] 15:07:57.460 [DubboServerHandler-192.168.13.59:16887-thread-54] org.nutz.dao.impl.sql.run.NutDaoExecutor - SELECT * FROM sys_dict WHERE id=? | 1 | |----------------------------------| | 3d3dc2befeb94aa8ad890a11c9c066b8 | For example:> "SELECT * FROM sys_dict WHERE id='3d3dc2befeb94aa8ad890a11c9c066b8'" [DEBUG] 15:07:57.480 [DubboServerHandler-192.168.13.59:16887-thread-54] org.nutz.dao.impl.interceptor.DaoTimeInterceptor - time=20ms, sql=SELECT * FROM sys_dict WHERE id='3d3dc2befeb94aa8ad890a11c9c066b8' [DEBUG] 15:07:57.480 [DubboServerHandler-192.168.13.59:16887-thread-54] org.nutz.dao.impl.sql.run.NutDaoExecutor - SELECT * FROM app_user WHERE id=? | 1 | |----------------------------------| | 987df65e69614739abf25f20c3096906 | For example:> "SELECT * FROM app_user WHERE id='987df65e69614739abf25f20c3096906'" [DEBUG] 15:07:57.499 [DubboServerHandler-192.168.13.59:16887-thread-54] org.nutz.dao.impl.interceptor.DaoTimeInterceptor - time=18ms, sql=SELECT * FROM app_user WHERE id='987df65e69614739abf25f20c3096906' [DEBUG] 15:07:57.500 [DubboServerHandler-192.168.13.59:16887-thread-54] org.nutz.dao.impl.sql.run.NutDaoExecutor - SELECT * FROM sys_dict WHERE id=? | 1 | |----------------------------------| | 3a94cb8ea25b4075919fa79979bd95e9 | For example:> "SELECT * FROM sys_dict WHERE id='3a94cb8ea25b4075919fa79979bd95e9'" [DEBUG] 15:07:57.518 [DubboServerHandler-192.168.13.59:16887-thread-54] org.nutz.dao.impl.interceptor.DaoTimeInterceptor - time=18ms, sql=SELECT * FROM sys_dict WHERE id='3a94cb8ea25b4075919fa79979bd95e9' [DEBUG] 15:07:57.519 [DubboServerHandler-192.168.13.59:16887-thread-54] org.nutz.dao.impl.sql.run.NutDaoExecutor - SELECT * FROM app_user WHERE id=? | 1 | |----------------------------------| | 987df65e69614739abf25f20c3096906 | For example:> "SELECT * FROM app_user WHERE id='987df65e69614739abf25f20c3096906'" [DEBUG] 15:07:57.538 [DubboServerHandler-192.168.13.59:16887-thread-54] org.nutz.dao.impl.interceptor.DaoTimeInterceptor - time=19ms, sql=SELECT * FROM app_user WHERE id='987df65e69614739abf25f20c3096906'

就是没带入查询条件

subCnd 是对两个关联表都生效的,而且不需要前缀

啊,可是我这样写也没报错,要是都生效不应该报错吗?现在是两个关联表都没带入这个条件啊

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