NutzCN Logo
问答 List<Record> 返回json值不区分大小写
发布于 2964天前 作者 Hamming 3114 次浏览 复制 上一个帖子 下一个帖子
标签: dao

List 返回json值不区分大小写 这个算不算是BUG

13 回复

说的是record类吧?

用maps回调

@wendal
酱紫 莫非改成

Sql sql = dao.sqls().create("shopping.list");
            sql.params().set("uid", uid);
            List<Record> shoppingCart = appShoppingCartService.list(sql);
Sql sql = dao.sqls().create("shopping.list");
            sql.params().set("uid", uid);
            List<maps> shoppingCart = appShoppingCartService.list(sql);

@tonyyule 不知道什么是回调?sql.setCallback

@wendal

原来是酱紫用

sql.setCallback(Sqls.callback.maps());

@wendal
为何加了这句话 返回值还是不区分大小写呢

  @At
    @Ok("json")
    @SLog(tag = "购物车列表", msg = "")
    @Filters(@By(type=AccessTokenFilter.class))
    public Object list(@Param("id") String uid) {
        try {
            Sql sql = dao.sqls().create("shopping.list");
            //区分大小写
           sql.setCallback(Sqls.callback.maps());
            sql.params().set("uid", uid);
            List<Record> shoppingCart = appShoppingCartService.list(sql);
            return ResultApp.success("system.success",shoppingCart);
        } catch (Exception e) {
            return ResultApp.error("system.error");
        }
    }

sql

/* shopping.list */
SELECT s.id , s.userId AS userId, s.prodId, s.size, s.color, s.prodCount, s.prodImg ,s.invenId,
	      i.prodNum, i.prodUrls, p.name, p.price, p.promPrice
  FROM app_shopping_cart s
  inner join app_inventory i on i.prodId = s.prodId
  inner join app_product p on p.id=s.prodId
  WHERE s.userId=@uid and s.size=i.size and s.color=i.color and s.delFlag=0

sql取了别名 还是不行

返回值

{
  "result": 1,
  "msg": "操作成功",
  "data": [
    {
      "id": 41,
      "userid": 5,
      "prodid": "0487ee781caf4151b621d0601409ce0b",
      "size": "M",
      "color": "绿色",
      "prodcount": 10,
      "invenid": "3abc852fe4d740c7b74c86397e75ce82",
      "prodnum": 99,
      "produrls": "/upload/image/20161012/7qgu124gicg3epgc9g1uht7olu.png;/upload/image/20161012/1573alr6dohlhqnppfvap3b4qc.png",
      "name": "绿帽 男 2017款 0300002698",
      "price": 139,
      "promprice": 110
    }
  ]
}

list的返回值怎么是Record

nutMap还是不区分大小写

	@At
	@Ok("json")
	public Object dictDo() {
		try {
			Sql sql = categoryService.dao().sqls().create("dict.list");
			//区分大小写
			sql.setCallback(Sqls.callback.maps());
			List<NutMap> re =categoryService.listM(sql);
			return re;
		} catch (Exception e) {
			return Result.error("system.error");
		}
	}
    public <T> List<NutMap> listM(Sql sql) {
        sql.setCallback(Sqls.callback.records());
        this.dao().execute(sql);
        return sql.getList(NutMap.class);

    }

NutMap是区分大小写,取出来的字段名,跟数据库里面字段名一致

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