首页 > 其他分享 >写代码主义

写代码主义

时间:2023-01-28 21:24:15浏览次数:38  
标签:username String stockList jsonObject 代码 new 主义 example

判空

对集合判空

//锁定库存
	List<Stock> stockList = stockMapper.findStocksForUpdate(productIds);
	if(CollectionUtils.isEmpty(stockList)){
		throw new BizException("库存未初始化");
	}
	if(stockList.size() != productIds.size()){
		throw new BizException("部分商品库存未初始化!");
	}

Json转换成一个类

String jsonObject = JSON.toJSONString(object);
CartProductDto cartProductDto = JSONObject.parseObject(jsonObject, CartProductDto.class);
			

TK-MYBATIS

查询

  Example example = new Example(Member.class);
        example.createCriteria().andEqualTo("username",request.getUserName());
        List<Member> memberList = memberMapper.selectByExample(example);
		

token

String userInfo = (String) request.getAttribute(TokenIntercepter.USER_INFO_KEY);
JSONObject jsonObject = JSON.parseObject(userInfo);
String username = (String) jsonObject.get("username");
Integer id = (Integer) jsonObject.get("uid");
Long uid = Long.valueOf(id);

json查看接口文档

image

标签:username,String,stockList,jsonObject,代码,new,主义,example
From: https://www.cnblogs.com/hellojianzuo/p/17071278.html

相关文章