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:

  • 相关阅读:
    近期计划安排
    线段树+离散化+染色
    矩阵快速幂(共轭函数两种递推式)
    树状数组求区间最值和单点更新
    矩阵快速幂(共轭函数)
    树状数组之区间更新与查询
    Python List min()方法
    Python List max()方法
    Python List len()方法
    Python List cmp()方法
  • 原文地址:https://www.cnblogs.com/Danial7777777/p/9153501.html
Copyright © 2011-2022 走看看