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

  • 相关阅读:
    NOIP 模拟 序列操作
    LUOGU 1525 关押罪犯
    HDU2473 Junk-Mail Filter
    BZOJ 2096 Pilots
    luogu 3939 数颜色
    NOIP模拟 赌博游戏
    Unity3D
    HTML5
    Cocos2d-x——支持多触点
    Cocos2d-x——Cocos2d-x 屏幕适配总结
  • 原文地址:https://www.cnblogs.com/hwj2wj/p/2824749.html
Copyright © 2011-2022 走看看