首页 > 代码库 > ongl(原始类型和包装类型)
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="http://www.mamicode.com/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="http://www.mamicode.com/message" default="展示数据" /><br/> 姓名:<s:property value="http://www.mamicode.com/user.name" /><br/> 年龄:<s:property value="http://www.mamicode.com/user.age" /><br/> 国家:<s:property value="http://www.mamicode.com/user.address.country" /> </body>
在搜索栏输入localhost:8080/Struts2_OGNL/showOriginalAndJavaBeanAction访问
ongl(原始类型和包装类型)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。