getOrder(type)和 getOrder()的区别
时间: 2024-06-18 09:03:40 浏览: 5
getOrder(type)和getOrder()的区别在于,getOrder(type)需要传入一个参数type来指定需要获取哪种类型的订单,而getOrder()则是获取全部类型的订单。例如,如果你想获取所有的待支付订单,就可以调用getOrder("unpaid")来获取,而如果你想获取所有类型的订单,就可以调用getOrder()来获取。可以理解为getOrder(type)是getOrder()的一个子集。
相关问题
if (bindingResult.hasErrors()) { for (ObjectError error : bindingResult.getAllErrors()) { return new PayResult<ZhenghangParamDTO>(PayResultConstant.PARAM_VALID_FAILED.getCode(), error.getDefaultMessage(), null); } } if (StringUtils.isBlank(orgCode)){ return new PayResult<ZhenghangParamDTO>(PayResultConstant.PARAM_VALID_FAILED.getCode(), "公司编码不能为空", null); } if (epayBankParamDTO.getCo_list() == null || epayBankParamDTO.getCo_list().isEmpty()){ return new PayResult<ZhenghangParamDTO>(PayResultConstant.PARAM_VALID_FAILED.getCode(), "关联订单信息不能为空", null); } if (!isIntAndGreaterThanZero(epayBankParamDTO.getBill_acct())){ return new PayResult(PayResultConstant.PARAM_VALID_FAILED.getCode(),"交易金额必须大于0,必须为整数", null); } if (StringUtils.isBlank(epayBankParamDTO.getCanInputName())){ epayBankParamDTO.setCanInputName("1"); } if (StringUtils.isBlank(epayBankParamDTO.getOrder_type())){ epayBankParamDTO.setOrder_type("901"); } if (StringUtils.isBlank(epayBankParamDTO.getCurr_type())){ epayBankParamDTO.setCurr_type("156"); }
这段代码可以进行如下优化:
```java
if (bindingResult.hasErrors()) {
ObjectError error = bindingResult.getAllErrors().get(0);
return new PayResult<>(PayResultConstant.PARAM_VALID_FAILED.getCode(), error.getDefaultMessage(), null);
}
if (StringUtils.isBlank(orgCode)) {
return new PayResult<>(PayResultConstant.PARAM_VALID_FAILED.getCode(), "公司编码不能为空", null);
}
if (epayBankParamDTO.getCo_list() == null || epayBankParamDTO.getCo_list().isEmpty()) {
return new PayResult<>(PayResultConstant.PARAM_VALID_FAILED.getCode(), "关联订单信息不能为空", null);
}
if (!isIntAndGreaterThanZero(epayBankParamDTO.getBill_acct())) {
return new PayResult<>(PayResultConstant.PARAM_VALID_FAILED.getCode(), "交易金额必须大于0,必须为整数", null);
}
epayBankParamDTO.setCanInputName(StringUtils.defaultIfBlank(epayBankParamDTO.getCanInputName(), "1"));
epayBankParamDTO.setOrder_type(StringUtils.defaultIfBlank(epayBankParamDTO.getOrder_type(), "901"));
epayBankParamDTO.setCurr_type(StringUtils.defaultIfBlank(epayBankParamDTO.getCurr_type(), "156"));
```
这个优化做了以下几个改进:
1. 在第一个 `if` 语句块里,我们只需要获取第一个错误信息,而不需要遍历所有的错误信息,这样可以减少不必要的操作。
2. 对于后面三个 `if` 语句块,我们可以使用 `StringUtils.defaultIfBlank()` 方法来简化代码,这个方法会在字符串为空时返回一个默认值,这样可以避免使用 `if` 语句来判断是否为空。
java.lang.NullPointerException public static List<OrderAbnormalRecordResultBase> convertOrderListIntoResultList(List<OrderBasicInfoDB> list) { List<OrderAbnormalRecordResultBase> ret = new ArrayList<OrderAbnormalRecordResultBase>(); if (list !=null && list.size()>0){ for (OrderBasicInfoDB record: list){ OrderAbnormalRecordResultDispatchAcceptTimeOut t = new OrderAbnormalRecordResultDispatchAcceptTimeOut(); t.setAbnormalRecordType(OrderAbnormalRecordListParam.ABNORMAL_RECORD_TYPE_DISPATCHED_ORDER_ACCEPT_TIME_OUT); t.setId(record.getId()); t.setOrder_no(record.getOrder_no()); t.setOrder_type(record.getOrder_type()); t.setPpl_id(record.getPpl_detail_info().getId()); t.setPpl_name(record.getPpl_name()!=null?record.getPpl_name(): record.getPpl_detail_info().getPpl_name()); t.setContact_phone(record.getContact_phone()); t.setProduct_name(record.getProduct_name()); t.setProduct_id(record.getProduct_id()==null?0: record.getProduct_id()); t.setCreate_time(DateUtil.convertTimeByFormat(record.getCreate_time(), OrderBasicInfoDB.DATE_TIME_FORMAT)); t.setService_personnel_id(record.getService_personnel_id().getId()); t.setService_personnel_name(record.getService_personnel_name()); t.setStaff_tel(record.getService_personnel_id().getPpl_tel()); t.setAmount(record.getAmount()); t.setService_plan_time(DateUtil.convertTimeByFormat(record.getService_plan_time(), OrderBasicInfoDB.DATE_TIME_FORMAT)); t.setDispatch_time(DateUtil.convertTimeByFormat(record.getDispatch_time(), OrderBasicInfoDB.DATE_TIME_FORMAT)); t.setOrder_final_status(record.getOrder_final_status()); ret.add(t); } } return ret; }
在这段代码中,出现`java.lang.NullPointerException`的原因可能是以下几种情况之一:
1. `list`参数为空。在使用`list`之前,应该先判断其是否为空,可以添加如下代码进行判断:
```java
if (list == null) {
return ret; // 或者抛出异常,具体根据需求来决定
}
```
2. `record`对象中的某个属性为`null`,而在设置属性值时未进行判空处理。可以在设置属性值之前,先进行判断是否为`null`,例如:
```java
t.setPpl_name(record.getPpl_name() != null ? record.getPpl_name() : record.getPpl_detail_info().getPpl_name());
```
类似地,对于其他可能为`null`的属性,都需要进行类似的判空处理。
根据具体的异常信息和代码逻辑,可以进一步分析并排查导致`NullPointerException`异常的具体原因,并进行相应的修复。
相关推荐
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)