Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

validation with double value in Spring

I want to check score which have value: 0.00 <= value<= 10.00
I used:
-Model(Score):

 @Range(min = (long) 0.0, max = (long) 10.0)
 private double score;

-messages.properties:

Range.score.score=Please input 0<= score <=10

-servlet-context.xml:

   <beans:bean id="messageSource"
        class="org.springframework.context.support.ResourceBundleMessageSource">
        <beans:property name="basename" value="messages" />
    </beans:bean>

But the value = 10.01 has passed the check.
Please help me.

like image 547
Ducthien Avatar asked Feb 17 '16 15:02

Ducthien


1 Answers

I resolve my proplem with:

 @DecimalMax("10.0") @DecimalMin("0.0") 
 private double score;

Thank you lots @ Kayaman ,@hyness

like image 191
Ducthien Avatar answered Nov 09 '22 12:11

Ducthien