亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

完全復制老師代碼,利用postman刪除一條數據時,拋出異常 空針,直接忽略還是需要處理?

完全復制老師代碼,利用postman刪除一條數據時,拋出異常 空針,直接忽略還是需要處理?

java.lang.NullpointerException:null???? 請問需要如何處理?

正在回答

5 回答

@DeleteMapping("/luckymoneys/{id}")
public?Result?deleteById(@PathVariable?Integer?id){
????service.delete(id);
???return??ResultUtil.success(null);

}
public?void?delete(Integer?id)?{
????Luckymoney?luckymoney?=?new?Luckymoney();
????luckymoney.setId(id);

????repository.delete(luckymoney);
}
@Pointcut("execution(public?*?com.imooc.luckymoney.controller.LuckMoneyController.*(..))?&&?!execution(public?*?com.imooc.luckymoney.controller.LuckMoneyController.delete*(..))"?)
public?void?log()?{

}

把delete從切入表達式中去除?;蛘咝露x一個切入表達式,讓delete方法使用該切入點↓

@Pointcut("execution(public?*?com.imooc.luckymoney.controller.LuckMoneyController.*(..))?&&?!execution(public?*?com.imooc.luckymoney.controller.LuckMoneyController.delete*(..))"?)
public?void?logByDel(){

}


0 回復 有任何疑惑可以回復我~
@DeleteMapping("/girls/{id}")
public?void?girlDelete(@PathVariable("id")?Integer?id){
????????girlRepository.deleteById(id);
????throw?new?GirlException(ResultEnum.SUCCESS);
}

無返回值的加個

throw?new?GirlException(ResultEnum.SUCCESS);

就餓可以了

1 回復 有任何疑惑可以回復我~
應該是deleteGirl方法沒有返回值,所以(@AfterReturning(returning?=?"object",pointcut?=?"log()"))doAftereReturning方法中參數Object為null,然后toString報的空指針吧


1 回復 有任何疑惑可以回復我~

我的也會出現這種情況,能成功刪除數據,但是會報空指針錯誤!

0 回復 有任何疑惑可以回復我~

數據庫沒數據吧

0 回復 有任何疑惑可以回復我~
#1

soicano 提問者

你好,數據庫有數據的!無論用 Get還是Delete過去請求,進行deletebyid對當前實施刪除后!報異常!請問如何處理?哪怕刪除第一條或者最后一條任意一位置都拋出空針錯誤,當然數據是刪除的,返回的時候執行@after 拋出異常
2018-05-16 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

完全復制老師代碼,利用postman刪除一條數據時,拋出異常 空針,直接忽略還是需要處理?

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號