`

Spring-访问数据库jdbcTemplate.queryForList的一个小问题

 
阅读更多

今天在写项目的时候发现了点小问题:

需求是:需要从数据库中用聚合函数sum查询一个属性的总数,并且要查询到此行的其他信息

jtt的query()方法以及jtt.list()方法 均 设置为对应语句参数以及传入包裹对象为Map.class后,查询发现返回空集合

解决方法为:

使用以下语句进行查询:

jdbcTemplate.queryForList(SEVEN_DAY_RANK_SQL, new Object[]{});

查询实现将结果行映射为一个map对象

将所有结果集中的结果行放入一个list中并返回list

 

成功返回结果:

{

  "msg": "",

  "rankList": [

    {

      "exchange_item_id": 1,

      "sender_acount_id": 1,

      "receiver_acount_id": 2,

      "exchange_type": 1,

      "amount": 1111,

      "create_time": 1441443600000,

      "pay_type": 1,

      "pay_no": "1",

      "status": 1,

      "totalMoney": 8328

    },

    {

      "exchange_item_id": 13,

      "sender_acount_id": 3,

      "receiver_acount_id": 2,

      "exchange_type": 1,

      "amount": 1111,

      "create_time": 1441443600000,

      "pay_type": 1,

      "pay_no": "1",

      "status": 1,

      "totalMoney": 3654

    },

    {

      "exchange_item_id": 25,

      "sender_acount_id": 5,

      "receiver_acount_id": 2,

      "exchange_type": 1,

      "amount": 1111,

      "create_time": 1441443600000,

      "pay_type": 1,

      "pay_no": "1",

      "status": 1,

      "totalMoney": 2332

    },

    {

      "exchange_item_id": 23,

      "sender_acount_id": 4,

      "receiver_acount_id": 2,

      "exchange_type": 1,

      "amount": 1111,

      "create_time": 1441443600000,

      "pay_type": 1,

      "pay_no": "1",

      "status": 1,

      "totalMoney": 1234

    },

    {

      "exchange_item_id": 28,

      "sender_acount_id": 6,

      "receiver_acount_id": 2,

      "exchange_type": 1,

      "amount": 100,

      "create_time": 1441443600000,

      "pay_type": 1,

      "pay_no": "1",

      "status": 1,

      "totalMoney": 200

    }

  ],

  "status": "0"

 

}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics