John has developed a web application. But when he was testing his application he got the ugly result as an output. He wants to return a meaningful result on exception raised. He wants to use @ResponseStatus annotation on custom exception class handling class to return the meaningful result. which one of the following code snippets satisfied his need? import org.springframework.HttpStatus; import org.springframework.annotation.ResponseStatus;A@ResponseStatus(value = HttpStatus. NOT_FOUND, reason = "No such Keyword") public class KeywordNotFoundException extends RuntimeExceptionpublic KeywordNotFoundException(String key){super(key+" not available");
时间: 2024-03-21 15:41:44 浏览: 210
AutoJs源码-龙小证自动抢单Com-A.ugly.min
Yes, the following code snippet satisfies John's need:
```
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
@ResponseStatus(value = HttpStatus.NOT_FOUND, reason = "No such Keyword")
public class KeywordNotFoundException extends RuntimeException {
public KeywordNotFoundException(String key) {
super(key + " not available");
}
}
```
This code snippet defines a custom exception class `KeywordNotFoundException` that extends `RuntimeException`. The `@ResponseStatus` annotation is used to set the HTTP status code to `404 NOT_FOUND` and the reason to "No such Keyword" when this exception is thrown. This will return a meaningful result when an exception is raised in John's web application.
阅读全文