Skip to content

Commit 4cedb9f

Browse files
committed
springboot-exceptionHandler代码优化
1 parent 7e93926 commit 4cedb9f

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

springboot-exceptionHandler/src/main/java/com/pancm/exception/GlobalExceptionHandler.java

-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ public ResultBody exceptionHandler(HttpServletRequest req, NullPointerException
6262
@ExceptionHandler(value =Exception.class)
6363
@ResponseBody
6464
public ResultBody exceptionHandler(HttpServletRequest req, Exception e){
65-
System.out.println("未知异常!原因是:"+e);
6665
logger.error("未知异常!原因是:",e);
6766
return ResultBody.error(CommonEnum.INTERNAL_SERVER_ERROR);
6867
}

springboot-exceptionHandler/src/main/java/com/pancm/web/UserRestController.java

+10-6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.pancm.pojo.User;
66
import org.springframework.web.bind.annotation.*;
77

8+
import java.util.ArrayList;
89
import java.util.List;
910

1011

@@ -44,18 +45,21 @@ public boolean update(@RequestBody User user) {
4445
@DeleteMapping("/user")
4546
public boolean delete(@RequestBody User user) {
4647
System.out.println("开始删除...");
47-
if(user.getId()==null){
48-
throw new BizException(CommonEnum.BODY_NOT_MATCH);
49-
}
48+
//这里故意造成一个异常,并且不进行处理
49+
Integer.parseInt("abc123");
5050
return true;
5151
}
5252

5353
@GetMapping("/user")
5454
public List<User> findByUser(User user) {
5555
System.out.println("开始查询...");
56-
//这里故意造成一个异常,并且不进行处理
57-
Integer.parseInt("abc123");
58-
return null;
56+
List<User> userList =new ArrayList<>();
57+
User user2=new User();
58+
user2.setId(1L);
59+
user2.setName("xuwujing");
60+
user2.setAge(18);
61+
userList.add(user2);
62+
return userList;
5963
}
6064

6165
}

0 commit comments

Comments
 (0)