Recall & Review
beginner
What is the purpose of the @Min annotation in Spring Boot?
The @Min annotation ensures that a numeric value is not less than a specified minimum value. It helps validate input data by enforcing a lower limit.
Click to reveal answer
beginner
How does the @Max annotation work in Spring Boot validation?
The @Max annotation checks that a numeric value does not exceed a specified maximum value. It prevents values greater than the limit from being accepted.
Click to reveal answer
intermediate
Can @Min and @Max be used together on the same field? What does that achieve?
Yes, using @Min and @Max together sets a range for valid numeric input. The value must be between the minimum and maximum limits inclusive.
Click to reveal answer
beginner
What happens if a value violates the @Min or @Max constraint in Spring Boot?
If the value is outside the allowed range, Spring Boot validation fails and returns an error message. This helps prevent invalid data from being processed.
Click to reveal answer
beginner
Show a simple example of using @Min and @Max on a field in a Spring Boot model class.
Example:
<pre>import javax.validation.constraints.Min;
import javax.validation.constraints.Max;
public class Product {
@Min(1)
@Max(100)
private int quantity;
// getters and setters
}</pre>
This means quantity must be between 1 and 100.Click to reveal answer
What does @Min(5) enforce on a numeric field?
✗ Incorrect
@Min(5) means the value cannot be less than 5.
Which annotation ensures a number is not greater than a limit?
✗ Incorrect
@Max sets the maximum allowed value.
If a field has @Min(1) and @Max(10), which value is invalid?
✗ Incorrect
15 is greater than the max limit 10, so it is invalid.
What type of values can @Min and @Max be applied to?
✗ Incorrect
@Min and @Max validate numeric values.
What happens if validation fails for @Min or @Max in Spring Boot?
✗ Incorrect
Validation failure returns an error message to inform the user.
Explain how @Min and @Max annotations help in validating numeric input in Spring Boot.
Think about setting minimum and maximum allowed values.
You got /3 concepts.
Describe a real-life example where you would use @Min and @Max annotations in a Spring Boot application.
Consider a form input that must stay within a range.
You got /3 concepts.