zoukankan      html  css  js  c++  java
  • java_Struts2为Action自定义转发器

    只是自己的理解,

    转换器类例子:

    public class DateConverter extends DefaultTypeConverter{

       //重写convertValue方法

      public  Object convertValue(Map context, Object value, Class toType) {

        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");

        try{

          if(toType==Date.class){

             String[]  params = (String[])value;

             return sdf.parse(params[0])

          }else if(toType==String.class){

             Date date = (Date)value;

             return sdf.format(date);

          }

        }catch(Exception e){   }

        return null;

      }     

    }

    注册转换器:

    全局:为整个应用使用

    在src目录下配置属性文件名格式为xwork-conversion.properties

     属性文件:要转换的类型=转换器的完整名称(包含了包名)

    例如:java.util.Date=com.yjdgis.converter. DateConverter

    局部:为制定的Action使用

    在Action说在的包目录下配置属性文件 ,属性文件的名字为:ActionClassName-convertion.properties

    属性文件:要转的Action内的属性名称=转换器的完整名称(包含了包名)

    例如:userBirthday=com.yjdgis.converter. DateConverter

  • 相关阅读:
    Hello World
    查找字符串 fiand
    stdou,write与print()
    python 中 按位 与 & ,| ,^ ,~,
    3*3元素主对角元素之和
    Python random() 函数
    文本颜色设计
    if __name__=="__main__
    join函数
    ProGAN论文的翻译+学习体会
  • 原文地址:https://www.cnblogs.com/hwj2wj/p/2824749.html
Copyright © 2011-2022 走看看