mvc:annotation-driver作用
RequestMappingHandlerMapping
RequestMappingHandlerAapter方法回调
ExceptionHandlerResolver
@RequestMapping
@ExceptionHandler
数据格式化
@NumberFormat可对类似数字类型的属性进行标注
二个互斥的属性
-style:NumberFormat.Style
(Style.NUMBER,Style.CURRENCY,Style.PERCENT)
-pattern:类型为string,自定义 pattern="#,##"
步骤:
1)
<form>
name:<input type="text" name="name"/>
age:<input type="text" name="age"/>
salary:<input type="text" name="salary"/>
<input type="submit" value="submit"/>
</form>
2)写POJO-User
@NumberFormat(pattern="#,###.##")
private Double salary;
注:加入mvc:annotation-driver
3)写handler
4)在配置文件中加入
<mvc:annotation-diver conversionService="ConversionService"></mvc:annotation-diver >
<bean id="ConversionService"
class=**"FormattingConversionServiceFactoryBean">**
<property name="converters">
<set >
<bean class=" StringToUserConverter "></bean>
</set>
</bean>
注:必须让我们的ConversionService采用"FormattingConversionService
默认spring加载的就是FormattingConversionService,如果添加了自定义的类型转换器,必须手动填写为FormattingConversionService
日期格式化
@DateTimeFormat
–pattern属性:yyy-MM-dd hh:mm:ss
–iOS属性:ISO.ONE
ISO.DATE
ISO.TIME
ISO.DATE-TIME
–style属性:字符串
1)在页面中加入
Birth:<input type="text" name="birth"/>
2)写POJO-User中加入
@DateFormat(pattern="yyy-MM-dd")
private Date birthday;
注:mvc:annotation-driver必须加入
必须让我们的ConversionService采用"FormattingConversionService
默认spring加载的就是FormattingConversionService,如果添加了自定义的类型转换器,必须手动填写为FormattingConversionService