NutzCN Logo
问答 请问一下,哪位大神帮忙解答一下,通过service对象,怎么设置动态表名吗?按照教程来好像不生效
发布于 1743天前 作者 米底底 1497 次浏览 复制 上一个帖子 下一个帖子
标签:
        Ksb_user user = ksbuser.fetch(Cnd.where("wxOpenId", "=", wxid));
        TableName.set(1);
        List<Ksb_customer> customerlist = ksbcustomer.query(Cnd.where("wxOpenId", "=", wxid));
        TableName.clear();
        return Result.success("success").addData(customerlist);

按上面这样写,查询时表名并没有动态变化,报错如下

java.lang.RuntimeException: org.nutz.dao.DaoException: !Nutz SQL Error: 'SELECT * FROM ksb_customer_  WHERE wxOpenId='oJYgp4_CQlHIcvccd2HBB7HDEkjQ''
PreparedStatement: 
'SELECT * FROM ksb_customer_  WHERE wxOpenId=?'
CaseMessage=Table 'kbs.ksb_customer_' doesn't exist
org.nutz.dao.DaoException: !Nutz SQL Error: 'SELECT * FROM ksb_customer_  WHERE wxOpenId='oJYgp4_CQlHIcvccd2HBB7HDEkjQ''
PreparedStatement: 
'SELECT * FROM ksb_customer_  WHERE wxOpenId=?'
CaseMessage=Table 'kbs.ksb_customer_' doesn't exist
	at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:110)

哪位大神有空帮忙解答一下,该怎么写,非常感谢~

7 回复

TableName.run,文档有吧

如果用TableName.run,我怎么能在一个接口的方法里,正常返回查询结果呢?

    @POST
    @At("/getcustomerlist")
    @Ok("json")
    public Object getcustomerlist(@Param("wxid") String wxid) {
        Ksb_user user = ksbuser.fetch(Cnd.where("wxOpenId", "=", wxid));
        //ksbcustomer.setTableName(user.getRandomTabNum());
        TableName.run(1, new Runnable() {
            @Override
            public void run() {

            }
        });
        List<Ksb_customer> customerlist = ksbcustomer.query(Cnd.where("wxOpenId", "=", wxid));
        return Result.success("success").addData(customerlist);
    }

像这样,感觉没办法实现了

试过用TableName.run了,也不行

你真的看文档了吗?

Ksb_customer贴出来

我参照syslog的写法,把问题解决了,感谢

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