zoukankan      html  css  js  c++  java
  • springMVC相关—格式化标签

    格式化主要讲的是让数据以一种特定格式输入,得到特定样式的结果(也可归属于数据类型转换,多为String类型转换为其他类型)。

    此处以@NumberFormat 及 @DateTimeFormat 注解为例说明:

    一、针对问题:

    在输入日期时可能会写成诸如1990-11-23该格式类型,该格式为字符串类型,后台为date类型无法识别,需进行格式化操作。(@DateTimeFormat)

    在输入如工资时,可能为1,000的格式,此处为字符串,也需格式化,让后台识别。(@NumberFormat)

    二、基础使用(使用方法):

      1.在SpringMVC配置文件中配置<mvc:annotation-driven/>

    1 <mvc:annotation-driven conversion-service="Service"></mvc:annotation-driven>
    2     
    3     <bean id="Service" class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
    4         <property name="converters">
    5             <set>
    6                 <ref bean="myConverter"/>
    7             </set>
    8         </property>
    9     </bean>

           2.在目标POJO对象的属性上加上@NumberFormat 或者 @DateTimeFormat 注解!
             @DateTimeFormat
                –    pattern 属性:类型为字符串。指定解析/格式化字段数据的模式, 如:”yyyy-MM-dd hh:mm:ss”
             @NumberFormat
                –pattern:类型为 String,自定义样式, 如patter="#,###";

    1   @DateTimeFormat(pattern="yyyy-MM-dd")
    2     private Date birth;
    3 
    4     
    5     @NumberFormat(pattern="#,###,###")
    6     private Integer salary;

    三、简单介绍@NumberFormat 及 @DateTimeFormat注解

  • 相关阅读:
    关于margintop/bottom在nonReplaced inline元素上不起作用的解释
    css position
    css :three column +top box
    little box: two box
    css layout :center
    Absolute, Relative, Fixed Positioning: How Do They Differ?
    little box:three column
    利用position:absolute重叠元素
    C#生成(操作)PDF
    asp.net发布网站时三个选项的问题
  • 原文地址:https://www.cnblogs.com/kangxingyue-210/p/7442319.html
Copyright © 2011-2022 走看看