写代码主义

判空

对集合判空

//锁定库存
	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

posted @ 2023-01-28 21:06  拿受用  阅读(14)  评论(0编辑  收藏  举报