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注解

  • 相关阅读:
    Apache 安装后Error 403的故障排错方法(linux)
    ab接口压力测试工具使用
    php工具、拓展下载地址
    Jboss反序列化漏洞复现(CVE-2017-12149)
    Apache SSI 远程命令执行漏洞复现
    apache httpd多后缀解析漏洞复现
    IIS短文件名漏洞复现
    nginx文件名逻辑漏洞_CVE-2013-4547漏洞复现
    nginx CRLF(换行回车)注入漏洞复现
    nginx目录穿越漏洞复现
  • 原文地址:https://www.cnblogs.com/kangxingyue-210/p/7442319.html
Copyright © 2011-2022 走看看