Я пишу некоторые пользовательские методы исключения с помощью пользовательского класса ответов. Это мой класс ответов < /p>
package com.mahadi.InventoryManagementSystem.dto;
import java.time.LocalDateTime;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.mahadi.InventoryManagementSystem.enums.UserRole;
import lombok.Builder;
import lombok.Data;
@Data
@Builder
@JsonInclude(content = Include.NON_NULL)
public class Response {
// generic
private int status;
private String message;
// for login
private String token;
private String expirationTime;
private UserRole role;
// for pagination
private Integer totalPages;
private Long totalElement;
// data output optional
private UserDTO user;
private List userList;
< /code>
Это мой глобальный класс обработчика исключений < /p>
package com.mahadi.InventoryManagementSystem.exceptions;
import org.springframework.http.HttpStatus;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import com.mahadi.InventoryManagementSystem.dto.Response;
@ControllerAdvice
public class GlobalExceptionHandler {
@ExceptionHandler(Exception.class)
public ResponseEntity handleAllExceptions(Exception exception) {
Response response = Response.builder()
.status(HttpStatus.INTERNAL_SERVER_ERROR.value()) // or other status code
.message(exception.getMessage()) // exception message
.build();
return new ResponseEntity(response, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
< /code>
Теперь посмотрите на скриншот. Здесь метод застройщика не отвечает, но я добавил аннотацию @Builder в классе ответа. я не смог ее исправить. Мне нужно твое предложение. Я использую JDK 17 с Spring Boot 3.0.0
Подробнее здесь: https://stackoverflow.com/questions/794 ... der-method