1、工具类
package com.duodian.youhui.admin.utils;
import com.duodian.youhui.admin.Exceptions.AppException;
import com.duodian.youhui.entity.db.taobao.TaobaoWechat;
import java.lang.reflect.Field;
public class JudgeNullUtils {
public static boolean isNull(Object object,String ... fieldName){
try {
for (int i = 0; i < fieldName.length; i++) {
Field field = null;
field = object.getClass().getDeclaredField(fieldName[i]);
field.setAccessible(true);
if(field.get(object)==null){
throw new AppException(fieldName[i]+"不能为空");
}
}
return true ;
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return false ;
}
}
2、catch捕获
@ApiOperation(value = "添加淘宝营销总代理",
notes = "添加淘宝营销总代理",
consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE,
response = ResponseBean.class
)
@ResponseBody
@GetMapping("addEsWechat")
public ResponseBean addEsWechat(TaobaoEsWechat taobaoWechat ){
try {
JudgeNullUtils.isNull(taobaoWechat,"code","status");
return ResponseBean.buildSuccess(taobaoEsWechatService.addTaobaoEsWechat(taobaoWechat));
} catch (AppException e) {
ExceptionLogUtils.log(e, this.getClass());
return ResponseBean.buildFailure(e.getCode(),e.getMessage());
} catch (Exception e) {
ExceptionLogUtils.log(e, this.getClass());
return ResponseBean.buildFailure(e.getMessage());
}
}