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:

  • 相关阅读:
    linux安装kibana
    linux安装6.5.3版本elastic search
    linux非root用户安装nginx
    linux非root用户安装ncurses-devel依赖
    linux无网络情况下安装rpm包
    linux非root用户安装rabbitmq
    linux非root用户安装4.0.14版本redis
    (初)Knockout 监控属性(Observables)
    ECMAScript6
    SonarLint 代码质量管理
  • 原文地址:https://www.cnblogs.com/Danial7777777/p/9153501.html
Copyright © 2011-2022 走看看