NutzCN Logo
问答 关于使用Sqls.callback.maps(),出现大小写不定的问题
发布于 1400天前 作者 Saviour 1526 次浏览 复制 上一个帖子 下一个帖子
标签:

调用方式

private List<NutMap> executeSql(Sql sql) {
        sql.setCallback(Sqls.callback.maps());
        baseService.dao().execute(sql);
        return sql.getList(NutMap.class);
    }

以下为日志

07-22 15:54:05.673  DEBUG - [Connection.http-apr-8081-exec-2] {conn-10010} pool-connect
07-22 15:54:05.673  DEBUG - [NutDaoExecutor.http-apr-8081-exec-2] select virusName, occurTimes, inHostNum from lastMonthNewVirusSum order by occurTimes desc
07-22 15:54:05.673  DEBUG - [Statement.http-apr-8081-exec-2] {conn-10010, stmt-20092} created
07-22 15:54:05.695  DEBUG - [Statement.http-apr-8081-exec-2] {conn-10010, stmt-20092, rs-50082} query executed. 20.887336 millis. select virusName, occurTimes, inHostNum from lastMonthNewVirusSum order by occurTimes desc
07-22 15:54:05.695  DEBUG - [ResultSet.http-apr-8081-exec-2] {conn-10010, stmt-20092, rs-50082} open
07-22 15:54:05.695  DEBUG - [ResultSet.http-apr-8081-exec-2] {conn-10010, stmt-20092, rs-50082} Header: [virusname, occurtimes, inhostnum]
07-22 15:54:05.695  DEBUG - [ResultSet.http-apr-8081-exec-2] {conn-10010, stmt-20092, rs-50082} Result: [virus.DD, 1, 1]
07-22 15:54:05.695  DEBUG - [ResultSet.http-apr-8081-exec-2] {conn-10010, stmt-20092, rs-50082} closed
07-22 15:54:05.695  DEBUG - [Statement.http-apr-8081-exec-2] {conn-10010, stmt-20092} closed
07-22 15:54:05.695  DEBUG - [Connection.http-apr-8081-exec-2] {conn-10010} pool-recycle
listA---------------->[{virusname=virus.DD, occurtimes=1, inhostnum=1}]
07-22 15:54:05.696  DEBUG - [Connection.http-apr-8081-exec-2] {conn-10010} pool-connect
07-22 15:54:05.696  DEBUG - [NutDaoExecutor.http-apr-8081-exec-2] select virusName, discoveryTime, deptName, deviceName, owner, ip, fullFileName, result, doWithInfo from lastMonthNewVirus order by virusName
07-22 15:54:05.696  DEBUG - [Statement.http-apr-8081-exec-2] {conn-10010, stmt-20093} created
07-22 15:54:05.699  DEBUG - [Statement.http-apr-8081-exec-2] {conn-10010, stmt-20093, rs-50083} query executed. 2.642631 millis. select virusName, discoveryTime, deptName, deviceName, owner, ip, fullFileName, result, doWithInfo from lastMonthNewVirus order by virusName
07-22 15:54:05.699  DEBUG - [ResultSet.http-apr-8081-exec-2] {conn-10010, stmt-20093, rs-50083} open
07-22 15:54:05.699  DEBUG - [ResultSet.http-apr-8081-exec-2] {conn-10010, stmt-20093, rs-50083} Header: [virusname, discoverytime, deptname, devicename, owner, ip, fullfilename, result, dowithinfo]
07-22 15:54:05.700  DEBUG - [ResultSet.http-apr-8081-exec-2] {conn-10010, stmt-20093, rs-50083} Result: [virus.DD, 2020-07-10 16:09:22.0, 党政办, D2111111, 党住你, 88.99.10.10, C:\new\new\创新改变世界.rar, 成功, null]
07-22 15:54:05.700  DEBUG - [ResultSet.http-apr-8081-exec-2] {conn-10010, stmt-20093, rs-50083} closed
07-22 15:54:05.701  DEBUG - [Statement.http-apr-8081-exec-2] {conn-10010, stmt-20093} closed
07-22 15:54:05.701  DEBUG - [Connection.http-apr-8081-exec-2] {conn-10010} pool-recycle
07-22 15:54:05.701  DEBUG - [Connection.http-apr-8081-exec-2] {conn-10010} pool-connect
07-22 15:54:05.701  DEBUG - [NutDaoExecutor.http-apr-8081-exec-2] select virusName, occurTimes, inHostNum, firstDiscoveryTime from lastMonthOldVirusSum order by occurTimes desc
07-22 15:54:05.701  DEBUG - [Statement.http-apr-8081-exec-2] {conn-10010, stmt-20094} created
07-22 15:54:05.708  DEBUG - [Statement.http-apr-8081-exec-2] {conn-10010, stmt-20094, rs-50084} query executed. 7.083828 millis. select virusName, occurTimes, inHostNum, firstDiscoveryTime from lastMonthOldVirusSum order by occurTimes desc
07-22 15:54:05.708  DEBUG - [ResultSet.http-apr-8081-exec-2] {conn-10010, stmt-20094, rs-50084} open
07-22 15:54:05.709  DEBUG - [ResultSet.http-apr-8081-exec-2] {conn-10010, stmt-20094, rs-50084} Header: [virusname, occurtimes, inhostnum, firstdiscoverytime]
07-22 15:54:05.709  DEBUG - [ResultSet.http-apr-8081-exec-2] {conn-10010, stmt-20094, rs-50084} Result: [hacker.EE, 1, 1, 2020-06-01 12:15:41.0]
07-22 15:54:05.709  DEBUG - [ResultSet.http-apr-8081-exec-2] {conn-10010, stmt-20094, rs-50084} Result: [trojan.AA, 1, 1, 2020-06-08 16:02:27.0]
07-22 15:54:05.709  DEBUG - [ResultSet.http-apr-8081-exec-2] {conn-10010, stmt-20094, rs-50084} closed
07-22 15:54:05.710  DEBUG - [Statement.http-apr-8081-exec-2] {conn-10010, stmt-20094} closed
07-22 15:54:05.710  DEBUG - [Connection.http-apr-8081-exec-2] {conn-10010} pool-recycle
listA1---------------->[{virusName=hacker.EE, occurTimes=1, inHostNum=1, firstDiscoveryTime=2020-06-01 12:15:41.0}, {virusName=trojan.AA, occurTimes=1, inHostNum=1, firstDiscoveryTime=2020-06-08 16:02:27.0}]

为什么有的大写,有的小写,语句方面我都是一样的写法,小写开头,遇到单词就驼峰

5 回复

调用方式补充

List<NutMap> listA = executeSql(Sqls.create("select virusName, occurTimes, inHostNum from lastMonthNewVirusSum order by occurTimes desc"));
        System.out.println("listA-------->"+listA);
        List<NutMap> listA1 = executeSql(Sqls.create("select virusName, discoveryTime, deptName, deviceName, owner, ip, fullFileName, result, doWithInfo from lastMonthNewVirus order by virusName"));
        System.out.println("listA1-------->"+listA1);
        List<NutMap> listB = executeSql(Sqls.create("select virusName, occurTimes, inHostNum, firstDiscoveryTime from lastMonthOldVirusSum order by occurTimes desc"));
        System.out.println("listB-------->"+listB);
        List<NutMap> listB1 = executeSql(Sqls.create("select virusName, discoveryTime, deptName, deviceName, owner, ip, fullFileName, result, doWithInfo from lastMonthOldVirus order by virusName"));
        System.out.println("listB1-------->"+listB1);
        List<NutMap> listC = executeSql(Sqls.create("select deptName, deviceName, deviceNo, owner, secretLevel, ip, offTime, offReason, installTime from antivirusOffInfo where dateDiff(now(), offTime) <= 30 order by deptName, offTime"));
        System.out.println("listC-------->"+listC);

就是上面

List<NutMap> listA = executeSql(Sqls.create("select virusName, occurTimes, inHostNum from lastMonthNewVirusSum order by occurTimes desc"));
        System.out.println("listA-------->"+listA);

执行后返回的List中所有key都是小写

listA---------------->[{virusname=virus.DD, occurtimes=1, inhostnum=1}]

同样的代码,执行

List<NutMap> listB = executeSql(Sqls.create("select virusName, occurTimes, inHostNum, firstDiscoveryTime from lastMonthOldVirusSum order by occurTimes desc"));

返回的List中所有key就是正常

listB---------------->[{virusName=hacker.EE, occurTimes=1, inHostNum=1, firstDiscoveryTime=2020-06-01 12:15:41.0}, {virusName=trojan.AA, occurTimes=1, inHostNum=1, firstDiscoveryTime=2020-06-08 16:02:27.0}]

感觉很奇怪

我大概定位都问题了,但是不知道原因,猜测是数据库设置问题
使用别名后是正常的,比如virusName as virusName,就可以了
跟踪代码发现
Record类中

name = meta.getColumnLabel(i);

其中,meta中的field信息,在未使用别名时,columnName和originalColumnName都是virusname,使用别名后columnName是virusName ,originalColumnName都是virusname。

但是如果是数据库设置问题,为什么有点语句不需要使用别名也正常呢,只是个别语句有问题?

listA 不是想要的结果
listB 达到预期

07-22 23:12:54.014  DEBUG - [Connection.http-nio-8081-exec-2] {conn-10009} pool-connect
07-22 23:12:54.014  DEBUG - [NutDaoExecutor.http-nio-8081-exec-2] select virusName, occurTimes, inHostNum from lastMonthNewVirusSum order by occurTimes desc
07-22 23:12:54.014  DEBUG - [Statement.http-nio-8081-exec-2] {conn-10009, stmt-20073} created
07-22 23:12:54.040  DEBUG - [Statement.http-nio-8081-exec-2] {conn-10009, stmt-20073, rs-50065} query executed. 25.376405 millis. select virusName, occurTimes, inHostNum from lastMonthNewVirusSum order by occurTimes desc
07-22 23:12:54.040  DEBUG - [ResultSet.http-nio-8081-exec-2] {conn-10009, stmt-20073, rs-50065} open
07-22 23:12:54.040  DEBUG - [ResultSet.http-nio-8081-exec-2] {conn-10009, stmt-20073, rs-50065} Header: [virusname, occurtimes, inhostnum]
07-22 23:12:54.040  DEBUG - [ResultSet.http-nio-8081-exec-2] {conn-10009, stmt-20073, rs-50065} Result: [virus.DD, 1, 1]
07-22 23:12:54.040  DEBUG - [ResultSet.http-nio-8081-exec-2] {conn-10009, stmt-20073, rs-50065} closed
07-22 23:12:54.040  DEBUG - [Statement.http-nio-8081-exec-2] {conn-10009, stmt-20073} closed
07-22 23:12:54.040  DEBUG - [Connection.http-nio-8081-exec-2] {conn-10009} pool-recycle
listA-------->[{virusname=virus.DD, occurtimes=1, inhostnum=1}]
07-22 23:12:54.040  DEBUG - [Connection.http-nio-8081-exec-2] {conn-10009} pool-connect
07-22 23:12:54.040  DEBUG - [NutDaoExecutor.http-nio-8081-exec-2] select virusName as virusName, occurTimes as occurTimes, inHostNum as inHostNum from lastMonthNewVirusSum order by occurTimes desc
07-22 23:12:54.040  DEBUG - [Statement.http-nio-8081-exec-2] {conn-10009, stmt-20074} created
07-22 23:12:54.042  DEBUG - [Statement.http-nio-8081-exec-2] {conn-10009, stmt-20074, rs-50066} query executed. 1.069875 millis. select virusName as virusName, occurTimes as occurTimes, inHostNum as inHostNum from lastMonthNewVirusSum order by occurTimes desc
07-22 23:12:54.042  DEBUG - [ResultSet.http-nio-8081-exec-2] {conn-10009, stmt-20074, rs-50066} open
07-22 23:12:54.042  DEBUG - [ResultSet.http-nio-8081-exec-2] {conn-10009, stmt-20074, rs-50066} Header: [virusname, occurtimes, inhostnum]
07-22 23:12:54.042  DEBUG - [ResultSet.http-nio-8081-exec-2] {conn-10009, stmt-20074, rs-50066} Result: [virus.DD, 1, 1]
07-22 23:12:54.042  DEBUG - [ResultSet.http-nio-8081-exec-2] {conn-10009, stmt-20074, rs-50066} closed
07-22 23:12:54.042  DEBUG - [Statement.http-nio-8081-exec-2] {conn-10009, stmt-20074} closed
07-22 23:12:54.042  DEBUG - [Connection.http-nio-8081-exec-2] {conn-10009} pool-recycle
listB-------->[{virusName=virus.DD, occurTimes=1, inHostNum=1}]
添加回复
请先登陆
回到顶部