NutzCN Logo
问答 nutzwk4.0.1级联查询的时候报错了
发布于 2153天前 作者 码农 1377 次浏览 复制 上一个帖子 下一个帖子
标签: nutzwk

最后一个参数由null改成“unit”的时候报错了。

return userService.userData(length, start, draw, order, columns, cnd, "unit");
@One(field = "unitid")
    private Sys_unit unit;
//获取当前登陆对象
            Subject subject = SecurityUtils.getSubject();
            //获取当前用户的信息
            Sys_user login_user = (Sys_user) subject.getPrincipal();
            Cnd cnd = Cnd.NEW();
            if (!Strings.isBlank(unitid) && !"root".equals(unitid)) //isBlank 是判断 是否为空 或 长度为0 或 有空格内容 组成
                cnd.and("unitid", "=", unitid);
            if (!Strings.isBlank(loginname))
                cnd.and("loginname", "like", "%" + loginname + "%");
            if (!Strings.isBlank(username))
                cnd.and("username", "like", "%" + username + "%");
            if (!Strings.isBlank(condition)) {
                cnd.and("username", "like", "%" + condition + "%").or("loginname", "like", "%" + condition + "%").or("jobnumber", "like", "%" + condition + "%");
            }
            return userService.userData(length, start, draw, order, columns, cnd, null);
java.lang.RuntimeException: Can not insert map without key '.table' : 
{
   no: 1,
   id: "b19a540a300f417d90e7d23fa062fdb8",
   loginname: "赵延明",
   password: "Hl/aHGvQNSWOzZiByWUMKlYnFG3UKcnjZRFFxtQByEM=",
   salt: "7j7wVU1pchTXMGnG61kD+A==",
   username: "赵延明",
   isonline: "0",
   disabled: "0",
   loginsidebar: "0",
   loginboxed: "0",
   loginscroll: "0",
   loginpjax: "0",
   userphone: "13202293102",
   unitid: "87cca0ffe8344979be3c0e4aa5f4d57e",
   opby: "bae9ac75d26741f2a914eeb152a2c94f",
   opat: 1524063310,
   delflag: "0"
}
	at org.nutz.lang.Lang.makeThrow(Lang.java:132)
	at org.nutz.dao.impl.EntityHolder.getEntityBy(EntityHolder.java:104)
	at org.nutz.dao.impl.NutDao._optBy(NutDao.java:970)
	at org.nutz.dao.impl.NutDao._fetchLinks(NutDao.java:1167)
	at org.nutz.dao.impl.NutDao$11.invoke(NutDao.java:636)
	at org.nutz.lang.Lang.each(Lang.java:1596)
	at org.nutz.dao.impl.NutDao.fetchLinks(NutDao.java:634)
	at org.nutz.dao.impl.NutDao.fetchLinks(NutDao.java:628)
	at cn.wizzer.app.sys.modules.services.impl.SysUserServiceImpl.userData(SysUserServiceImpl.java:253)
	at cn.wizzer.app.web.modules.controllers.platform.sys.SysUserController.data(SysUserController.java:443)
	at cn.wizzer.app.web.modules.controllers.platform.sys.SysUserController$FM$data$44228b13788fb3dfc602289c140fec38.invoke(SysUserController.java)
	at org.nutz.mvc.impl.processor.MethodInvokeProcessor.process(MethodInvokeProcessor.java:31)
	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 cn.wizzer.app.web.commons.processor.XssSqlFilterProcessor.process(XssSqlFilterProcessor.java:43)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at cn.wizzer.app.web.commons.processor.NutShiroProcessor.process(NutShiroProcessor.java:52)
	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)
[DEBUG] 2018-12-23 16:59:51,207 cn.wizzer.app.web.commons.processor.LogTimeProcessor.process(LogTimeProcessor.java:26) - [POST]URI=/platform/sys/user/data 11144ms
	at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at cn.wizzer.app.web.commons.processor.GlobalsSettingProcessor.process(GlobalsSettingProcessor.java:36)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at cn.wizzer.app.web.commons.processor.LogTimeProcessor.process(LogTimeProcessor.java:21)
	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:202)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
	at cn.wizzer.app.web.commons.filter.RouteFilter.doFilter(RouteFilter.java:152)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
	at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61)
	at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)
	at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)
	at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
	at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)
	at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
	at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
	at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
	at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
	at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
	at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
	at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
	at org.nutz.mvc.WhaleFilter.doFilter(WhaleFilter.java:159)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:94)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:492)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:502)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1152)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:684)
	at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2527)
	at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2516)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:748)
 NutMap re = new NutMap();
        if (orders != null && orders.size() > 0) {
            for (DataTableOrder order : orders) {
                DataTableColumn col = columns.get(order.getColumn());
                cnd.orderBy(Sqls.escapeSqlFieldValue(col.getData()).toString(), order.getDir());
            }
        }
        Pager pager = new OffsetPager(start, length);
        re.put("recordsFiltered", this.dao().count(this.getEntityClass(), cnd));
        int startpager = start + pager.getPageSize()*(pager.getPageNumber()-1);
        //String  limitpagestr = " where rownum >= " + (startpager) + " AND " + "rownum <= " + (startpager + pager.getPageSize());//(start + pager.getPageSize()*(pager.getPageNumber()-1)) + "," + pager.getPageSize();
        String strsql = "select a.* from sys_user  a" + cnd.toString();
        String execute_strsql = "select * from (select rownum no,temp1.* from (" + strsql + " ) temp1 where rownum <= " + (startpager + pager.getPageSize()) + ") where no>" + startpager;
        Sql sql = Sqls.create(execute_strsql);
        
        sql.setEntity(dao().getEntity(Sys_user.class)); //这里屏蔽掉接受类型,因为在sys_user中没有部门名称,所以用自定义的方法去接收结果
        sql.setCallback(Sqls.callback.records());
        dao().execute(sql);
        List<?> list = sql.getList(Map.class);//使用这种方法去接收查询出的结果
        if (!Strings.isBlank(linkName)) {
            this.dao().fetchLinks(list, linkName);
        }
        
        re.put("data", list);
        re.put("draw", draw);
        re.put("recordsTotal", length);
        return re;
3 回复

这一段,getList应该传pojo,而非map

        Sql sql = Sqls.create(execute_strsql);
        
        sql.setEntity(dao().getEntity(Sys_user.class)); //这里屏蔽掉接受类型,因为在sys_user中没有部门名称,所以用自定义的方法去接收结果
        sql.setCallback(Sqls.callback.records());
        dao().execute(sql);
        List<?> list = sql.getList(Map.class);//使用这种方法去接收查询出的结果
        if (!Strings.isBlank(linkName)) {
            this.dao().fetchLinks(list, linkName);
        }

将geiList后还是报一样的错

List<?> list = sql.getList(Sys_user.class);

解决了,还需要将callback修改一下,

 sql.setCallback(Sqls.callback.entities());
添加回复
请先登陆
回到顶部