0
0
Spring Bootframework~5 mins

@Min, @Max for numeric constraints in Spring Boot - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AValue must be exactly 5
BValue must be at most 5
CValue must be at least 5
DValue must be between 0 and 5
Which annotation ensures a number is not greater than a limit?
A@Max
B@Min
C@Size
D@NotNull
If a field has @Min(1) and @Max(10), which value is invalid?
A5
B1
C10
D15
What type of values can @Min and @Max be applied to?
ANumeric types like int, long, double
BOnly Strings
CBoolean values
DAny object
What happens if validation fails for @Min or @Max in Spring Boot?
AThe application crashes
BAn error message is returned
CThe value is automatically corrected
DNothing happens
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.