Java 弹簧,数字验证,默认值,警告消息
我有bean定义,例如Java 弹簧,数字验证,默认值,警告消息,java,spring,constraints,default-value,Java,Spring,Constraints,Default Value,我有bean定义,例如 <bean id="DsdDetectorLogic" class="my class" init-method="init" lazy-init="true" > <property name="threshold" value="#{ properties.threshold }" /> <property name="lag" value="#{ properties.lag }" /> ... </
<bean id="DsdDetectorLogic" class="my class" init-method="init" lazy-init="true" >
<property name="threshold" value="#{ properties.threshold }" />
<property name="lag" value="#{ properties.lag }" />
...
</bean>
...
我需要在特定参数(滞后)上添加约束,如果该参数超过最大值3或最小值1,我需要它获得默认值1。此外,我需要收到一些警告消息,该参数因此收到了一个默认值
我熟悉使用javax.validation.constraints.Min/Max注释代码中字段的解决方案
是否可以使用一些spring功能来编辑xml文件,或者唯一的解决方案是在调用setter时从java对象类进行编辑?我将部分回答我的问题,因为我发现如何检查约束并通过xml发送默认值,警告消息仍然是一个谜 我将使用SPeL:
<bean id="DsdDetectorLogic" class="my class" init-method="init" lazy-init="true" >
<property name="threshold" value="#{ properties.threshold }" />
<property name="lag" value="#{ (1 > new Integer(properties.lag ) or
new Integer(properties.lag ) > 3) ? 1 :
properties.lag }" />
...
</bean>
...
我看了看,没有看到你问的任何问题。但是,第3.3节提到了设置构造函数值。如果这是您的自定义类,您可能可以通过这种方式实现类似的功能。@Jesse J:我找到了一种方法来部分解决我的问题,您是否可以帮助找到如何显示警告消息?(我的答复附于附件)