Java Code Examples for cn.hutool.core.util.ObjectUtil#isNull()
The following examples show how to use
cn.hutool.core.util.ObjectUtil#isNull() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StoreCombinationController.java From yshopmall with Apache License 2.0 | 6 votes |
@Log("修改拼团") @ApiOperation(value = "新增/修改拼团") @PutMapping(value = "/yxStoreCombination") @PreAuthorize("@el.check('admin','YXSTORECOMBINATION_ALL','YXSTORECOMBINATION_EDIT')") public ResponseEntity update(@Validated @RequestBody YxStoreCombination resources){ if(ObjectUtil.isNotNull(resources.getStartTimeDate())){ resources.setStartTime(OrderUtil. dateToTimestamp(resources.getStartTimeDate())); } if(ObjectUtil.isNotNull(resources.getEndTimeDate())){ resources.setStopTime(OrderUtil. dateToTimestamp(resources.getEndTimeDate())); } if(ObjectUtil.isNull(resources.getId())){ resources.setAddTime(String.valueOf(OrderUtil.getSecondTimestampTwo())); return new ResponseEntity(yxStoreCombinationService.save(resources),HttpStatus.CREATED); }else{ yxStoreCombinationService.saveOrUpdate(resources); return new ResponseEntity(HttpStatus.NO_CONTENT); } }
Example 2
Source File: WechatReplyController.java From yshopmall with Apache License 2.0 | 6 votes |
@ApiOperation(value = "新增自动回复") @PostMapping(value = "/yxWechatReply") @PreAuthorize("@el.check('admin','YXWECHATREPLY_ALL','YXWECHATREPLY_CREATE')") public ResponseEntity create(@RequestBody String jsonStr){ JSONObject jsonObject = JSON.parseObject(jsonStr); YxWechatReply yxWechatReply = new YxWechatReply(); YxWechatReply isExist = yxWechatReplyService.isExist(jsonObject.get("key").toString()); yxWechatReply.setKey(jsonObject.get("key").toString()); yxWechatReply.setStatus(Integer.valueOf(jsonObject.get("status").toString())); yxWechatReply.setData(jsonObject.get("data").toString()); yxWechatReply.setType(jsonObject.get("type").toString()); if(ObjectUtil.isNull(isExist)){ yxWechatReplyService.create(yxWechatReply); }else{ yxWechatReply.setId(isExist.getId()); yxWechatReplyService.upDate(yxWechatReply); } return new ResponseEntity(HttpStatus.CREATED); }
Example 3
Source File: PayController.java From supplierShop with MIT License | 6 votes |
@PostMapping(value = "/shop/notify") @ApiOperation(value = "异步通知",notes = "异步通知") public String payNotify(@RequestBody String xmlData){ try { WxPayOrderNotifyResult notifyResult = wxPayService.parseOrderNotifyResult(xmlData); String orderNo = notifyResult.getOutTradeNo(); QueryWrapper<StoreOrder> wrapper = new QueryWrapper<>(); wrapper.eq("deleted",0).eq("pay_status",0).eq("order_sn",orderNo); StoreOrder storeOrder = orderService.getOne(wrapper); if(ObjectUtil.isNull(storeOrder)) { return WxPayNotifyResponse.success("处理成功!"); } orderService.notifyHandle(storeOrder); return WxPayNotifyResponse.success("处理成功!"); } catch (WxPayException e) { log.error(e.getMessage()); return WxPayNotifyResponse.fail(e.getMessage()); } // return WxPayNotifyResponse.success("处理成功!"); }
Example 4
Source File: SmsCodeFilter.java From pre with GNU General Public License v3.0 | 6 votes |
private void validate(HttpServletRequest request) { //短信验证码 String smsCode = obtainSmsCode(request); // 手机号 String mobile = obtainMobile(request); Object redisCode = redisTemplate.opsForValue().get(mobile); if (smsCode == null || smsCode.isEmpty()) { throw new ValidateCodeException("短信验证码不能为空"); } if (ObjectUtil.isNull(redisCode)) { throw new ValidateCodeException("验证码已失效"); } if (!smsCode.toLowerCase().equals(redisCode)) { throw new ValidateCodeException("短信验证码错误"); } }
Example 5
Source File: ValidationUtil.java From sk-admin with Apache License 2.0 | 5 votes |
/** * 验证空 */ public static void isNull(Object obj, String entity, String parameter, Object value) { if (ObjectUtil.isNull(obj)) { String msg = entity + " 不存在: " + parameter + " is " + value; throw new SkException(msg); } }
Example 6
Source File: ZooLockAspect.java From spring-boot-demo with MIT License | 5 votes |
/** * 构造分布式锁的键 * * @param lock 注解 * @param method 注解标记的方法 * @param args 方法上的参数 * @return * @throws NoSuchFieldException * @throws IllegalAccessException */ private String buildLockKey(ZooLock lock, Method method, Object[] args) throws NoSuchFieldException, IllegalAccessException { StringBuilder key = new StringBuilder(KEY_SEPARATOR + KEY_PREFIX + lock.key()); // 迭代全部参数的注解,根据使用LockKeyParam的注解的参数所在的下标,来获取args中对应下标的参数值拼接到前半部分key上 Annotation[][] parameterAnnotations = method.getParameterAnnotations(); for (int i = 0; i < parameterAnnotations.length; i++) { // 循环该参数全部注解 for (Annotation annotation : parameterAnnotations[i]) { // 注解不是 @LockKeyParam if (!annotation.annotationType().isInstance(LockKeyParam.class)) { continue; } // 获取所有fields String[] fields = ((LockKeyParam) annotation).fields(); if (ArrayUtil.isEmpty(fields)) { // 普通数据类型直接拼接 if (ObjectUtil.isNull(args[i])) { throw new RuntimeException("动态参数不能为null"); } key.append(KEY_SEPARATOR).append(args[i]); } else { // @LockKeyParam的fields值不为null,所以当前参数应该是对象类型 for (String field : fields) { Class<?> clazz = args[i].getClass(); Field declaredField = clazz.getDeclaredField(field); declaredField.setAccessible(true); Object value = declaredField.get(clazz); key.append(KEY_SEPARATOR).append(value); } } } } return key.toString(); }
Example 7
Source File: AuthController.java From pre with GNU General Public License v3.0 | 5 votes |
/** * 发送短信验证码 * * @param phone * @return */ @PostMapping("/sendCode/{phone}") public R sendSmsCode(@PathVariable("phone") String phone) { SmsResponse smsResponse = AliYunSmsUtils.sendSms(phone, "prex", "登录"); if (ObjectUtil.isNull(smsResponse)) { return R.error("短信发送失败"); } // 保存到验证码到 redis 有效期两分钟 redisTemplate.opsForValue().set(phone, smsResponse.getSmsCode(), 2, TimeUnit.MINUTES); return R.ok(); }
Example 8
Source File: SubscribeHandler.java From yshopmall with Apache License 2.0 | 5 votes |
@Override public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService weixinService, WxSessionManager sessionManager) throws WxErrorException { String str = "你好,欢迎关注yshop!"; YxWechatReply wechatReply = yxWechatReplyService.isExist("subscribe"); if(!ObjectUtil.isNull(wechatReply)){ str = JSONObject.parseObject(wechatReply.getData()).getString("content"); } try { WxMpXmlOutMessage msg= WxMpXmlOutMessage.TEXT() .content(str) .fromUser(wxMessage.getToUser()) .toUser(wxMessage.getFromUser()) .build(); return msg; } catch (Exception e) { this.logger.error(e.getMessage(), e); } return null; }
Example 9
Source File: DatasourceQueryServiceImpl.java From datax-web with MIT License | 5 votes |
@Override public List<String> getCollectionNames(long id, String dbName) throws IOException { //获取数据源对象 JobDatasource datasource = jobDatasourceService.getById(id); //queryTool组装 if (ObjectUtil.isNull(datasource)) { return Lists.newArrayList(); } return new MongoDBQueryTool(datasource).getCollectionNames(dbName); }
Example 10
Source File: DatasourceQueryServiceImpl.java From datax-web with MIT License | 5 votes |
@Override public List<String> getTableSchema(Long id) { //获取数据源对象 JobDatasource datasource = jobDatasourceService.getById(id); //queryTool组装 if (ObjectUtil.isNull(datasource)) { return Lists.newArrayList(); } BaseQueryTool qTool = QueryToolFactory.getByDbType(datasource); return qTool.getTableSchema(); }
Example 11
Source File: PageUtil.java From spring-boot-demo with MIT License | 5 votes |
/** * 校验分页参数,为NULL,设置分页参数默认值 * * @param condition 查询参数 * @param clazz 类 * @param <T> {@link PageCondition} */ public static <T extends PageCondition> void checkPageCondition(T condition, Class<T> clazz) { if (ObjectUtil.isNull(condition)) { condition = ReflectUtil.newInstance(clazz); } // 校验分页参数 if (ObjectUtil.isNull(condition.getCurrentPage())) { condition.setCurrentPage(Consts.DEFAULT_CURRENT_PAGE); } if (ObjectUtil.isNull(condition.getPageSize())) { condition.setPageSize(Consts.DEFAULT_PAGE_SIZE); } }
Example 12
Source File: GoodsServiceImpl.java From supplierShop with MIT License | 5 votes |
@Override public Map<String,StoreSpecGoodsPrice> goodsSpecPrice(int goodsId) { QueryWrapper<StoreSpecGoodsPrice> wrapper = new QueryWrapper<>(); wrapper.eq("goods_id",goodsId); List<StoreSpecGoodsPrice> specGoodsPriceList = storeSpecGoodsPriceMapper .selectList(wrapper); if(ObjectUtil.isNull(specGoodsPriceList)){ System.out.println("2222"); throw new EntityExistException(specGoodsPriceList.getClass()); } Map<String, StoreSpecGoodsPrice> listMap = specGoodsPriceList.stream().collect( Collectors.toMap(StoreSpecGoodsPrice::getKey,o->o)); return listMap; }
Example 13
Source File: YxStoreOrderServiceImpl.java From yshopmall with Apache License 2.0 | 5 votes |
@Override public String orderType(int id,int pinkId, int combinationId,int seckillId, int bargainId,int shippingType) { String str = "[普通订单]"; if(pinkId > 0 || combinationId > 0){ YxStorePink storePink = storePinkService.getOne(new QueryWrapper<YxStorePink>(). eq("order_id_key",id)); if(ObjectUtil.isNull(storePink)) { str = "[拼团订单]"; }else{ switch (storePink.getStatus()){ case 1: str = "[拼团订单]正在进行中"; break; case 2: str = "[拼团订单]已完成"; break; case 3: str = "[拼团订单]未完成"; break; default: str = "[拼团订单]历史订单"; break; } } }else if(seckillId > 0){ str = "[秒杀订单]"; }else if(bargainId > 0){ str = "[砍价订单]"; } if(shippingType == 2) str = "[核销订单]"; return str; }
Example 14
Source File: IndexController.java From spring-boot-demo with MIT License | 5 votes |
@GetMapping(value = {"", "/"}) public ModelAndView index(HttpServletRequest request) { ModelAndView mv = new ModelAndView(); User user = (User) request.getSession().getAttribute("user"); if (ObjectUtil.isNull(user)) { mv.setViewName("redirect:/user/login"); } else { mv.setViewName("page/index"); mv.addObject(user); } return mv; }
Example 15
Source File: StoreOrderController.java From yshopmall with Apache License 2.0 | 5 votes |
@Log("修改订单") @ApiOperation(value = "修改订单") @PostMapping(value = "/yxStoreOrder/edit") @PreAuthorize("hasAnyRole('admin','YXSTOREORDER_ALL','YXSTOREORDER_EDIT')") public ResponseEntity editOrder(@RequestBody YxStoreOrder resources) { if (ObjectUtil.isNull(resources.getPayPrice())) throw new BadRequestException("请输入支付金额"); if (resources.getPayPrice().doubleValue() < 0) throw new BadRequestException("金额不能低于0"); YxStoreOrderDto storeOrder = generator.convert(yxStoreOrderService.getById(resources.getId()),YxStoreOrderDto.class); //判断金额是否有变动,生成一个额外订单号去支付 int res = NumberUtil.compare(storeOrder.getPayPrice().doubleValue(), resources.getPayPrice().doubleValue()); if (res != 0) { String orderSn = IdUtil.getSnowflake(0, 0).nextIdStr(); resources.setExtendOrderId(orderSn); } yxStoreOrderService.saveOrUpdate(resources); YxStoreOrderStatus storeOrderStatus = new YxStoreOrderStatus(); storeOrderStatus.setOid(resources.getId()); storeOrderStatus.setChangeType("order_edit"); storeOrderStatus.setChangeMessage("修改订单价格为:" + resources.getPayPrice()); storeOrderStatus.setChangeTime(OrderUtil.getSecondTimestampTwo()); yxStoreOrderStatusService.save(storeOrderStatus); return new ResponseEntity(HttpStatus.OK); }
Example 16
Source File: JwtAuthenticationFilter.java From spring-boot-demo with MIT License | 4 votes |
/** * 请求是否不需要进行权限拦截 * * @param request 当前请求 * @return true - 忽略,false - 不忽略 */ private boolean checkIgnores(HttpServletRequest request) { String method = request.getMethod(); HttpMethod httpMethod = HttpMethod.resolve(method); if (ObjectUtil.isNull(httpMethod)) { httpMethod = HttpMethod.GET; } Set<String> ignores = Sets.newHashSet(); switch (httpMethod) { case GET: ignores.addAll(customConfig.getIgnores() .getGet()); break; case PUT: ignores.addAll(customConfig.getIgnores() .getPut()); break; case HEAD: ignores.addAll(customConfig.getIgnores() .getHead()); break; case POST: ignores.addAll(customConfig.getIgnores() .getPost()); break; case PATCH: ignores.addAll(customConfig.getIgnores() .getPatch()); break; case TRACE: ignores.addAll(customConfig.getIgnores() .getTrace()); break; case DELETE: ignores.addAll(customConfig.getIgnores() .getDelete()); break; case OPTIONS: ignores.addAll(customConfig.getIgnores() .getOptions()); break; default: break; } ignores.addAll(customConfig.getIgnores() .getPattern()); if (CollUtil.isNotEmpty(ignores)) { for (String ignore : ignores) { AntPathRequestMatcher matcher = new AntPathRequestMatcher(ignore, method); if (matcher.matches(request)) { return true; } } } return false; }
Example 17
Source File: JwtAuthenticationFilter.java From spring-boot-demo with MIT License | 4 votes |
/** * 请求是否不需要进行权限拦截 * * @param request 当前请求 * @return true - 忽略,false - 不忽略 */ private boolean checkIgnores(HttpServletRequest request) { String method = request.getMethod(); HttpMethod httpMethod = HttpMethod.resolve(method); if (ObjectUtil.isNull(httpMethod)) { httpMethod = HttpMethod.GET; } Set<String> ignores = Sets.newHashSet(); switch (httpMethod) { case GET: ignores.addAll(customConfig.getIgnores() .getGet()); break; case PUT: ignores.addAll(customConfig.getIgnores() .getPut()); break; case HEAD: ignores.addAll(customConfig.getIgnores() .getHead()); break; case POST: ignores.addAll(customConfig.getIgnores() .getPost()); break; case PATCH: ignores.addAll(customConfig.getIgnores() .getPatch()); break; case TRACE: ignores.addAll(customConfig.getIgnores() .getTrace()); break; case DELETE: ignores.addAll(customConfig.getIgnores() .getDelete()); break; case OPTIONS: ignores.addAll(customConfig.getIgnores() .getOptions()); break; default: break; } ignores.addAll(customConfig.getIgnores() .getPattern()); if (CollUtil.isNotEmpty(ignores)) { for (String ignore : ignores) { AntPathRequestMatcher matcher = new AntPathRequestMatcher(ignore, method); if (matcher.matches(request)) { return true; } } } return false; }
Example 18
Source File: AssertUtil.java From magic-starter with GNU Lesser General Public License v3.0 | 2 votes |
/** * 对象是否为空 * * @param object 待校验对象 * @param resultCode 结果状态码 */ public static void isNull(Object object, IResultCode resultCode) { if (ObjectUtil.isNull(object)) { ExceptionUtil.exception(resultCode); } }
Example 19
Source File: AssertUtil.java From magic-starter with GNU Lesser General Public License v3.0 | 2 votes |
/** * 对象是否为空 * * @param object 待校验对象 * @param message 异常消息 */ public static void isNull(Object object, String message) { if (ObjectUtil.isNull(object)) { ExceptionUtil.exception(message); } }
Example 20
Source File: SecurityUtil.java From spring-boot-demo with MIT License | 2 votes |
/** * 获取当前登录用户用户名 * * @return 当前登录用户用户名 */ public static String getCurrentUsername() { UserPrincipal currentUser = getCurrentUser(); return ObjectUtil.isNull(currentUser) ? Consts.ANONYMOUS_NAME : currentUser.getUsername(); }