//AbstractAddress.java package org.kyle.address.hibernate.beans; /** */ /** * AbstractAddress entity provides the base persistence definition of the * Address entity. * * @author MyEclipse Persistence Tools */ public abstract class AbstractAddress implements java.io.Serializable ... { // Fields private Integer id; private Integer userId; private String name; private String sex; private String mobile; private String email; private String qq; private String company; private String address; private String postcode; // Constructors /** *//** default constructor */ public AbstractAddress() ...{ } /** *//** minimal constructor */ public AbstractAddress(Integer id, Integer userId, String name) ...{ this.id = id; this.userId = userId; this.name = name; } /** *//** full constructor */ public AbstractAddress(String Integer, Integer userId, String name, String sex, String mobile, String email, String qq, String company, String address, String postcode) ...{ this.id = id; this.userId = userId; this.name = name; this.sex = sex; this.mobile = mobile; this.email = email; this.qq = qq; this.company = company; this.address = address; this.postcode = postcode; } // Property accessors public Integer getId() ...{ return this.id; } public void setId(Integer id) ...{ this.id = id; } public Integer getUserId() ...{ return this.userId; } public void setUserId(Integer userId) ...{ this.userId = userId; } public String getName() ...{ return this.name; } public void setName(String name) ...{ this.name = name; } public String getSex() ...{ return this.sex; } public void setSex(String sex) ...{ this.sex = sex; } public String getMobile() ...{ return this.mobile; } public void setMobile(String mobile) ...{ this.mobile = mobile; } public String getEmail() ...{ return this.email; } public void setEmail(String email) ...{ this.email = email; } public String getQq() ...{ return this.qq; } public void setQq(String qq) ...{ this.qq = qq; } public String getCompany() ...{ return this.company; } public void setCompany(String company) ...{ this.company = company; } public String getAddress() ...{ return this.address; } public void setAddress(String address) ...{ this.address = address; } public String getPostcode() ...{ return this.postcode; } public void setPostcode(String postcode) ...{ this.postcode = postcode; }} //Addres.java package org.kyle.address.hibernate.beans; /** */ /** * Address entity. * * @author MyEclipse Persistence Tools */ public class Address extends AbstractAddress implements java.io.Serializable ... { // Constructors /** *//** default constructor */ public Address() ...{ } /** *//** minimal constructor */ public Address(Integer id, Integer userId, String name) ...{ super(id, userId, name); } /** *//** full constructor */ public Address(String id, Integer userId, String name, String sex, String mobile, String email, String qq, String company, String address, String postcode) ...{ super(id, userId, name, sex, mobile, email, qq, company, address, postcode); }} //struts-config.xml <? xml version="1.0" encoding="UTF-8" ?> <! DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd" > < struts-config > < data-sources /> < form-beans > < form-bean name ="address" type ="org.apache.struts.action.DynaActionForm" > <!-- /IAddressBook/src/org/kyle/address/hibernate/beans/Address.java --> < form-property name ="address" type ="org.kyle.address.hibernate.beans.Address" /> </ form-bean > </ form-beans > < global-exceptions /> < global-forwards /> < action-mappings > <!-- /IAddressBook/src/org/kyle/address/struts/actions/AddressAction.java --> < action path ="/address" name ="address" scope ="request" type ="org.kyle.address.struts.actions.AddressAction" parameter ="method" > </ action > </ action-mappings > < message-resources parameter ="ApplicationResources" /> </ struts-config > //AddressAction.java /**/ /* * Generated by MyEclipse Struts * Template path: templates/java/JavaClass.vtl */ package org.kyle.address.struts.actions; import java.io.IOException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.apache.struts.action.DynaActionForm; import org.apache.struts.actions.DispatchAction; import org.kyle.Util.spring.GetSpringAppContext; import org.kyle.address.dao.IAddressDAO; import org.kyle.address.dao.impl.AddressDAO; import org.kyle.address.hibernate.beans.AbstractAddress; import org.kyle.address.hibernate.beans.Address; /** */ /** * MyEclipse Struts Creation date: 05-17-2008 * * XDoclet definition: * * @struts.action path="/address" name="addressForm" parameter="method" * scope="request" validate="true" */ public class AddressAction extends DispatchAction ... { /**//* * Generated Methods */ /** *//** * Method execute * * @param mapping * @param form * @param request * @param response * @return ActionForward */ public IAddressDAO addressDAO; //Test url: http://localhost:8080/IAddressBook/address.do?method=add&address.userId=1231&address.name=bb public ActionForward add(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) ...{ DynaActionForm iAddressForm = (DynaActionForm) form; // Address address = (Address) iAddressForm.get("address");// 获得Address对象实例// addressDAO = (IAddressDAO) GetSpringAppContext.getObj(); // 注如DAO业务对象// addressDAO.insert(address); // 执行插入 try ...{ response.getWriter().println("content:" + address.getName()); } catch (IOException e) ...{ e.printStackTrace(); } return null; } public void write(HttpServletResponse response, String content) ...{ try ...{ response.getWriter().println("content:" + content); } catch (IOException e) ...{ e.printStackTrace(); } } /**//* * Address address = new Address(); addressDAO = (IAddressDAO) * GetSpringAppContext.getContext().getBean( "addressDAO"); * * address.setUserId(1); address.setName("kyle23"); address.setSex("2"); * address.setQq("123456789"); address.setMobile("13573178648"); * address.setCompany("intel"); address.setEmail("xkyle@live.cn"); * address.setPostcode("4646454"); address.setAddress("ShangHai"); * * addressDAO.insert(address); */}