*IT 統一異常處理:足跡第七十一步:spring異常處理規範

1)業務代碼中不捕獲任何異常

1.1)即 dao、service層的所以異常,都全部拋出到上層。使得業務代碼中沒有 try-catch

2)全都使用統一返回結果集

2.1)使用ResponseEntity結合HttpStatus.OK

import org.springframework.http.ResponseEntity;
import org.springframework.http.HttpStatus;

@PutMapping("update/{id}")
public ResponseEntity update(@PathVariable("id")String id) {
	try{
		xxxService.update(id);
		return new ResponseEntity(HttpStatus.OK);
		} catch (Exception e) {
		return new ResponseEntity("更新異常",-1);
	}
}

附:​​在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章