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

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

異常沒被捕獲呀。。。

我按課程代碼寫的異常沒被捕獲,什么情況? package handler; import com.imooc.domain.Result; import com.imooc.utils.ResultUtil; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ResponseBody; /** * Created by MBENBEN on 2017/6/18. */ @ControllerAdvice public class ExceptionHandle { ? ?@ExceptionHandler(value = Exception.class) ? ?@ResponseBody ? ?public Result handle(Exception e){ ? ? ? ? ?return ResultUtil.error(100,e.getMessage()); ? ?} } service里 public void getAge(Integer id) throws Exception{ ? ? ? ? Girl girl= girlRepository.findOne(id); ? ? ? ?Integer age=girl.getAge(); ? ? ? ?if(age<10){ throw="" new="" else="" age="">10 && age<16){ ? ? ? ? ? ?//你可能還在上初中 ? ? ? ? ? ?throw new Exception("你可能還在上初中"); ? ? ? ?} ? ? ? ?//如果大于16歲 ? ?} controller里 @GetMapping(value = "girls/getAge/{id}") ? ?public void getAge(@PathVariable("id") Integer id) throws Exception{ ? ? ? ?girlService.getAge(id); ? ?}

正在回答

4 回答

感謝感謝哈哈哈哈

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

謝謝老鐵

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

感謝了,老鐵

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

后來發現問題了,代碼都是正確的,注意handle包必須和controller包和service包在同一級包下才行??!

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

舉報

0/150
提交
取消

異常沒被捕獲呀。。。

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

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

幫助反饋 APP下載

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

公眾號

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