• ongl(原始类型和包装类型)


    原始类型和包装类型

    //首先创建两个实体类 user 和 address user中包含address

    package cn.jbit.bean;
    public class User { //用户类
        private String name; //姓名
        private int age;     //年龄
        private Address address;//住址
        public Address getAddress() {
            return address;
        }
        public void setAddress(Address address) {
            this.address = address;
        }
        public String getName() {
            return name;
        }
        public void setName(String name) {
            this.name = name;
        }
        public int getAge() {
            return age;
        }
        public void setAge(int age) {
            this.age = age;
        }
    
    }
    package cn.jbit.bean;
    
    public class Address { // 家庭地址
    
        private String country; // 国家
        private String city; // 城市
        private String street; // 街道
        public String getCountry() {
            return country;
        }
        public void setCountry(String country) {
            this.country = country;
        }
        public String getCity() {
            return city;
        }
        public void setCity(String city) {
            this.city = city;
        }
        public String getStreet() {
            return street;
        }
        public void setStreet(String street) {
            this.street = street;
        }
    
    }
    

      2.创建出一个action先创建出两个成员变量 然后在核心方法中实例化成员变量。

    package cn.jbit.action;
    
    import com.opensymphony.xwork2.ActionSupport;
    import cn.jbit.bean.*;
    
    public class ShowOriginalAndJavaBeanAction extends ActionSupport {
        private User user;
        private String message;
        public String execute(){
            setUser(new User());
            getUser().setName("jbit");
            getUser().setAge(23);
            Address address=new Address();
            address.setCountry("中国");
            address.setCity("北京");
            address.setStreet("长安街");
            getUser().setAddress(address);
            setMessage("展示原始类型和JavaBean");
            return SUCCESS;
        }
        public User getUser() {
            return user;
        }
        public void setUser(User user) {
            this.user = user;
        }
        public String getMessage() {
            return message;
        }
        public void setMessage(String message) {
            this.message = message;
        }
    }
    

      核心配置:struts.xml

    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE struts PUBLIC 
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">
    <struts>
    <!-- <constant name="struts.custom.i18n.resources" value="message"/>	-->
    <package name="default" extends="struts-default">	
    <action name="showOriginalAndJavaBeanAction" class="cn.jbit.action.ShowOriginalAndJavaBeanAction">
    <result>result.jsp</result>
    </action>
    </package>
    </struts>
    

      index.jsp

    <body>
           信息:<s:property value="message" default="展示数据" /><br/>
           姓名:<s:property value="user.name" /><br/>
           年龄:<s:property value="user.age"  /><br/>
          国家:<s:property value="user.address.country" />
      </body>
    

      在搜索栏输入localhost:8080/Struts2_OGNL/showOriginalAndJavaBeanAction访问

  • 相关阅读:
    eventkeyboardmouse
    代理 IP
    网关 192.168.2.1 114.114.114.114 dns查询
    http ssl
    SSDP 抓包
    抓包登录信息提交
    危险的input 微博的过去
    firstChild.nodeValue
    浏览器控制台
    haproxy 中的http请求和https请求
  • 原文地址:https://www.cnblogs.com/yangronglin/p/5942702.html
Copyright © 2020-2023  润新知