NutzCN Logo
问答 关于fetchLinks中查询关联对象中字段属性的过滤条件的问题
发布于 2553天前 作者 KartKing 1991 次浏览 复制 上一个帖子 下一个帖子
标签: nutzwk

class Bus_bid {
private String cusId;

@One(field = "cusId")
private Bus_customer customer;

}
class Bus_customer {
private String name;
}
现在想查询Bus_customer中name like '%name%'的Bus_bid列表,我用NutzWk中的data查询,看了下代码有fetchLinks(list, linkName, cnd)方法,我试了一下,结果没有用,只是查询出所有的Bus_bid列表。

Cnd cnd = Cnd.NEW();// 自身的查询条件
Cnd linkCnd = Cnd.NEW();// 关联查询条件
linkCnd.and("name", "like", "%" + cusName + "%");
busBidService.data(length, start, draw, order, columns, cnd, "customer", linkCnd);
[DEBUG] 2017-12-26 09:48:18,879 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) - SELECT COUNT(*) FROM bus_bid  WHERE subId=?
    |                                1 |
    |----------------------------------|
    | c272fb65a9e043fc892a7d0d2026123f |
  For example:> "SELECT COUNT(*) FROM bus_bid  WHERE subId='c272fb65a9e043fc892a7d0d2026123f'"
[DEBUG] 2017-12-26 09:48:18,882 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) - SELECT * FROM bus_bid  WHERE subId=? ORDER BY bidAt DESC   LIMIT 0, 10 
    |                                1 |
    |----------------------------------|
    | c272fb65a9e043fc892a7d0d2026123f |
  For example:> "SELECT * FROM bus_bid  WHERE subId='c272fb65a9e043fc892a7d0d2026123f' ORDER BY bidAt DESC   LIMIT 0, 10 "
[DEBUG] 2017-12-26 09:48:23,500 org.quartz.impl.jdbcjobstore.JobStoreSupport$ClusterManager.manage(JobStoreSupport.java:3923) - ClusterManager: Check-in complete.
[DEBUG] 2017-12-26 09:48:24,367 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) - SELECT * FROM bus_customer  WHERE id=?
    |                                1 |
    |----------------------------------|
    | 77a5af6951d349be9902df0ffa3554b0 |
  For example:> "SELECT * FROM bus_customer  WHERE id='77a5af6951d349be9902df0ffa3554b0'"

请问是不是我使用有错误?如果写自定义SQL效率是不是要快些?

5 回复

FieldFilter

来自炫酷的 NutzCN

需要重写NutzWk的data方法吗?

不需要的, FieldFilter基于ThreadLocal的, data方法应该没用到Daos.ext吧

能根据我这个例子写一下我看看吗?我刚刚看了一下FieldFilter,好像只是用来返回指定字段的呢,我这边需要查询bus_bid中bus_customer的name属性的条件,返回bus_bid的列表,实现 select a.* from bus_bid a, bus_customer b where a.cusId = b.id and a.subId = 'aaaaaaaaaa' and b.name like '%cusName%' 的效果。谢谢啦!

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