zoukankan      html  css  js  c++  java
  • struts2简单类型参数转换器(拦截器自动转换)

    这边测试类型int,string,date,list(set),map,下面贴代码

    struts.xml文件代码

            <!-- 类型转换 -->
            <action name="ConvertAction_*" class="convert.CovertAction" method="{1}">
                <result name="success" type="dispatcher">/convert.jsp</result>
            </action>

    定义action类

    public class CovertAction extends ActionSupport{
        
        private int age;
        private Date date;
        private List<String> interests;
        private String name;
        private Map<String, String> map;
        
        public Map<String, String> getMap() {
            return map;
        }
        public void setMap(Map<String, String> map) {
            this.map = map;
        }
        public int getAge() {
            return age;
        }
        public Date getDate() {
            return date;
        }
        public List<String> getInterests() {
            return interests;
        }
        public String getName() {
            return name;
        }
        public String hello(){
               
               return SUCCESS;
           }
        public void setAge(int age) {
            this.age = age;
        }
        public void setDate(Date date) {
            this.date = date;
        }
        public void setInterests(List<String> interests) {
            this.interests = interests;
        }
        
       public void setName(String name) {
        this.name = name;
    }
        
        
    }

    前端测试页面

        age:<s:property value="age"/><br/>
        name:<s:property value="name"/><br/>
        date:<s:property value="date"/><br/>
        <s:date name="date" format="yyyy-MM-dd"/><br/>
        interests:<s:property value="interests"/><br/>
        map:<s:property value="map"/>
        <s:debug></s:debug>

    测试url

    http://localhost:8081/struts05/hello/ConvertAction_hello.action?name=xxxx&age=11&date=1999-01-01&interests=math&interests=english&map['a']=aaa&map['b']=bbb

    result:

  • 相关阅读:
    MySQL面试题-基础
    IDEA 创建Spring项目后org.springframework.boot报错
    IDEA上传项目到SVN
    解决:idea中右键项目找不到subversion
    关于fromdata的上传文件问题
    PHP清除数组中为0的元素
    PHP删除数组中重复的元素
    PHP代码篇(六)--如何根据邀请人id查询满足条件的会员上级
    PHP对URL进行字符串编码
    PHP时间戳相互转换
  • 原文地址:https://www.cnblogs.com/Danial7777777/p/9153501.html
Copyright © 2011-2022 走看看