码迷,mamicode.com
首页 > 其他好文 > 详细

SSH 两个表全套增删改

时间:2016-05-31 23:52:49      阅读:893      评论:0      收藏:0      [点我收藏+]

标签:

0、创建如下oracle的命令

技术分享
 1 create table HOTALINFO
 2 (
 3   HOTALID      NUMBER(10) not null,
 4   HOTALNAME    VARCHAR2(50) not null,
 5   HOTALADDRESS VARCHAR2(100) not null
 6 )
 7 ;
 8 comment on table HOTALINFO
 9   is 酒店信息表;
10 comment on column HOTALINFO.HOTALID
11   is 酒店编号;
12 comment on column HOTALINFO.HOTALNAME
13   is 酒店名称;
14 comment on column HOTALINFO.HOTALADDRESS
15   is 酒店地址;
16 alter table HOTALINFO
17   add constraint PK_HOTALID primary key (HOTALID);
18 
19 
20 create table SPORTSMAN
21 (
22   SPORTID     NUMBER(10) not null,
23   SPORTNAME   VARCHAR2(50) not null,
24   NATIONALITY VARCHAR2(50) not null,
25   HOTALID     NUMBER(10) not null,
26   INTAKETIME  DATE not null,
27   LEAVETIME   DATE not null
28 )
29 ;
30 
31 comment on table SPORTSMAN
32   is 运动员信息表;
33 comment on column SPORTSMAN.SPORTID
34   is 运动员编号;
35 comment on column SPORTSMAN.SPORTNAME
36   is 运动员姓名;
37 comment on column SPORTSMAN.NATIONALITY
38   is 国籍;
39 comment on column SPORTSMAN.HOTALID
40   is 酒店编号;
41 comment on column SPORTSMAN.INTAKETIME
42   is 入住时间;
43 comment on column SPORTSMAN.LEAVETIME
44   is 离开时间;
45   
46 alter table SPORTSMAN
47   add constraint PK_SPORTID primary key (SPORTID);
48 alter table SPORTSMAN
49   add constraint FK_HOTELID foreign key (HOTALID)
50   references HOTALINFO (HOTALID);
51   
52   -- Create sequence 
53 create sequence SEQ_HOTALID
54 minvalue 1
55 maxvalue 999999
56 start with 1
57 increment by 1
58 cache 30;
59 
60 create sequence SEQ_SPORTID
61 minvalue 1
62 maxvalue 99999
63 start with 1
64 increment by 1
65 cache 30;
66 
67 
68 insert into HOTALINFO (HOTALID, HOTALNAME, HOTALADDRESS)
69 values (SEQ_HOTALID.nextval, 帝豪酒店, 南京中央门-30);
70 insert into HOTALINFO (HOTALID, HOTALNAME, HOTALADDRESS)
71 values (SEQ_HOTALID.nextval, 格林豪泰, 南京宣武门-30);
72 insert into HOTALINFO (HOTALID, HOTALNAME, HOTALADDRESS)
73 values (SEQ_HOTALID.nextval, 7天假日, 北京中央门-30);
74 insert into HOTALINFO (HOTALID, HOTALNAME, HOTALADDRESS)
75 values (SEQ_HOTALID.nextval, 99酒店, 南京大厂门-30);
76 commit;
77 
78 
79 insert into SPORTSMAN (SPORTID, SPORTNAME, NATIONALITY, HOTALID, INTAKETIME, LEAVETIME)
80 values (SEQ_SPORTID.nextval, 张三, 英国, 1, to_date(05-04-2014, dd-mm-yyyy), to_date(18-04-2014, dd-mm-yyyy));
81 insert into SPORTSMAN (SPORTID, SPORTNAME, NATIONALITY, HOTALID, INTAKETIME, LEAVETIME)
82 values (SEQ_SPORTID.nextval, 李四, 韩国, 1, to_date(06-04-2014, dd-mm-yyyy), to_date(17-04-2014, dd-mm-yyyy));
83 insert into SPORTSMAN (SPORTID, SPORTNAME, NATIONALITY, HOTALID, INTAKETIME, LEAVETIME)
84 values (SEQ_SPORTID.nextval, 王五, 日本, 1, to_date(07-04-2014, dd-mm-yyyy), to_date(16-04-2014, dd-mm-yyyy));
85 insert into SPORTSMAN (SPORTID, SPORTNAME, NATIONALITY, HOTALID, INTAKETIME, LEAVETIME)
86 values (SEQ_SPORTID.nextval, 马六, 中国, 2, to_date(08-04-2014, dd-mm-yyyy), to_date(15-04-2014, dd-mm-yyyy));
87 insert into SPORTSMAN (SPORTID, SPORTNAME, NATIONALITY, HOTALID, INTAKETIME, LEAVETIME)
88 values (SEQ_SPORTID.nextval, 小猪, 法国, 3, to_date(09-04-2014, dd-mm-yyyy), to_date(14-04-2014, dd-mm-yyyy));
89 insert into SPORTSMAN (SPORTID, SPORTNAME, NATIONALITY, HOTALID, INTAKETIME, LEAVETIME)
90 values (SEQ_SPORTID.nextval, 菜菜, 外国, 4, to_date(10-04-2014, dd-mm-yyyy), to_date(13-04-2014, dd-mm-yyyy));
91 insert into SPORTSMAN (SPORTID, SPORTNAME, NATIONALITY, HOTALID, INTAKETIME, LEAVETIME)
92 values (SEQ_SPORTID.nextval, 放大, 是的, 4, to_date(03-03-2013, dd-mm-yyyy), to_date(06-05-2014, dd-mm-yyyy));
93 insert into SPORTSMAN (SPORTID, SPORTNAME, NATIONALITY, HOTALID, INTAKETIME, LEAVETIME)
94 values (SEQ_SPORTID.nextval, 答复, , 1, to_date(03-03-2013, dd-mm-yyyy), to_date(06-05-2014, dd-mm-yyyy));
95 insert into SPORTSMAN (SPORTID, SPORTNAME, NATIONALITY, HOTALID, INTAKETIME, LEAVETIME)
96 values (SEQ_SPORTID.nextval, 11, 233, 3, to_date(05-04-2014, dd-mm-yyyy), to_date(05-04-2014, dd-mm-yyyy));
97 insert into SPORTSMAN (SPORTID, SPORTNAME, NATIONALITY, HOTALID, INTAKETIME, LEAVETIME)
98 values (SEQ_SPORTID.nextval, 按到, 中国, 4, to_date(03-03-2013, dd-mm-yyyy), to_date(04-04-2014, dd-mm-yyyy));
99 commit;
oracle的脚本

 

1、项目实现如下功能

技术分享

技术分享技术分享

技术分享技术分享

2、创建如下项目结构

技术分享

技术分享

技术分享

3、在entity包下创建HotalInfo.java

技术分享
 1 package entity;
 2 
 3 import java.io.Serializable;
 4 import java.util.HashSet;
 5 import java.util.Set;
 6 
 7 public class HotalInfo implements Serializable{
 8     /**
 9      * 一方:旅馆
10      */
11     private static final long serialVersionUID = -2778660172354090695L;
12     private Integer hotalid;
13     private String hotalname;
14     private String hotaladdress;
15     private Set<Sportsman> sportsmanSet=new HashSet<Sportsman>();
16     public Integer getHotalid() {
17         return hotalid;
18     }
19     public void setHotalid(Integer hotalid) {
20         this.hotalid = hotalid;
21     }
22     public String getHotalname() {
23         return hotalname;
24     }
25     public void setHotalname(String hotalname) {
26         this.hotalname = hotalname;
27     }
28     public String getHotaladdress() {
29         return hotaladdress;
30     }
31     public void setHotaladdress(String hotaladdress) {
32         this.hotaladdress = hotaladdress;
33     }
34     public Set<Sportsman> getSportsmanSet() {
35         return sportsmanSet;
36     }
37     public void setSportsmanSet(Set<Sportsman> sportsmanSet) {
38         this.sportsmanSet = sportsmanSet;
39     }
40     
41 
42     
43     
44 }
HotalInfo.java

4、在entity包下创建HotalInfo.hbm.xml

技术分享
 1 <?xml version="1.0"?>
 2 <!DOCTYPE hibernate-mapping PUBLIC
 3     "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
 4     "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
 5 
 6 <hibernate-mapping>
 7 
 8     <class name="entity.HotalInfo" lazy="false" table="hotalInfo">
 9         <id name="hotalid" type="java.lang.Integer" column="hotalid">
10             <generator class="sequence">
11               <param name="sequence">seq_hotalid</param>
12             </generator>
13         </id>
14         <property name="hotalname" type="java.lang.String" column="hotalname"/>
15         <property name="hotaladdress" type="java.lang.String" column="hotaladdress"/>
16        
17        <!-- 级联并且反转 ,name为实体类的set集合的对象  inverse表示谁去维护主外键关联关系-->
18        <set name="sportsmanSet" table="Sportsman" > 
19          
20           <!-- 外键列 -->
21            <key column="hotalid"></key>
22            
23            <!-- 集合对应的实体类路径 -->
24            <one-to-many class="entity.Sportsman"/>
25        </set>
26         
27     </class>
28 
29 </hibernate-mapping>
HotalInfo.hbm.xml

5、在entity包下创建Sportsman.java

技术分享
 1 package entity;
 2 
 3 import java.io.Serializable;
 4 import java.util.Date;
 5 
 6 public class Sportsman implements Serializable{
 7     /**
 8      * 多方:运动员
 9      */
10     private static final long serialVersionUID = -7208629242686329779L;
11     private Integer sportid;
12     private String sportname;
13     private String nationality;
14     private Date intaketime;
15     private Date leavetime;
16     private HotalInfo hotalinfo;
17     public Integer getSportid() {
18         return sportid;
19     }
20     public void setSportid(Integer sportid) {
21         this.sportid = sportid;
22     }
23     public String getSportname() {
24         return sportname;
25     }
26     public void setSportname(String sportname) {
27         this.sportname = sportname;
28     }
29     public String getNationality() {
30         return nationality;
31     }
32     public void setNationality(String nationality) {
33         this.nationality = nationality;
34     }
35     public Date getIntaketime() {
36         return intaketime;
37     }
38     public void setIntaketime(Date intaketime) {
39         this.intaketime = intaketime;
40     }
41     public Date getLeavetime() {
42         return leavetime;
43     }
44     public void setLeavetime(Date leavetime) {
45         this.leavetime = leavetime;
46     }
47     public HotalInfo getHotalinfo() {
48         return hotalinfo;
49     }
50     public void setHotalinfo(HotalInfo hotalinfo) {
51         this.hotalinfo = hotalinfo;
52     }
53     
54 
55 }
Sportsman.java

6、在entity包下创建Sportsman.hbm.xml

技术分享
 1 <?xml version="1.0"?>
 2 <!DOCTYPE hibernate-mapping PUBLIC
 3     "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
 4     "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
 5 
 6 <hibernate-mapping>
 7 
 8     <class name="entity.Sportsman" table="sportsman">
 9         <id name="sportid" type="java.lang.Integer" column="sportid">
10             <generator class="sequence">
11               <param name="sequence">seq_sportid</param>
12             </generator>
13         </id>
14         
15         <property name="sportname" type="java.lang.String" column="sportname"/>
16  
17         <property name="nationality" type="java.lang.String" column="nationality"/>
18         <property name="intaketime" type="java.util.Date" column="intaketime"/>
19         <property name="leavetime" type="java.util.Date" column="leavetime"/>
20         
21         <!-- name是该类对应的外键类的对象名,class为外键类的全路径,column为数据库表的外键列 -->
22         <many-to-one name="hotalinfo" class="entity.HotalInfo" column="hotalid"></many-to-one>
23     </class>
24 
25 </hibernate-mapping>
Sportsman.hbm.xml

7、在dao包下创建HotalInfoDao.java

技术分享
 1 package dao;
 2 
 3 import java.util.List;
 4 
 5 import entity.HotalInfo;
 6 
 7 
 8 /**
 9  * 数据访问层接口
10  * @author Dell
11  *
12  */
13 public interface HotalInfoDao {
14     /**
15      * 1.查询所有
16      * @return
17      */
18    public List<HotalInfo> query();
19    
20 
21    
22    /**
23     * 2.根据id进行查询
24     * @param id
25     * @return
26     */
27    public HotalInfo queryById(Integer id);
28 
29 }
HotalInfoDao.java

8、在dao包下创建SportsmanDao.java

技术分享
 1 package dao;
 2 
 3 import java.util.List;
 4 
 5 import entity.Sportsman;
 6 
 7 
 8 /**
 9  * 数据访问层接口
10  * @author Dell
11  *
12  */
13 public interface SportsmanDao {
14 
15    
16    /**
17      * 2.分页查询所有
18      * @return
19      */
20   public List<Sportsman> queryPage(Integer pageSize,Integer pageNo);
21    /**
22     * 3.插入一个对象
23     * @param sandard
24     * @return
25     */
26    public int insert(Sportsman obj);
27    
28    /**
29     * 4.根据id删除
30     * @param sandard
31     * @return
32     */
33    public int delete(Sportsman obj);
34    
35    /**
36     * 4.修改某个对象
37     * @param sandard
38     * @return
39     */
40    public int update(Sportsman obj);
41    
42    /**
43     * 5.根据id进行查询
44     * @param id
45     * @return
46     */
47    public Sportsman queryById(Integer id);
48    /**
49     * 6.求出总条数
50     * @return
51     */
52    public Integer totalCount();
53    
54    
55    /**
56     * 7.根据模糊分页查询
57     * @param stdnum
58     * @param zhname
59     * @return 某个区域下的所有监测信息
60     */
61    public List<Sportsman> queryPageLike(Integer pageSize,Integer pageNo,String likeparam);
62    
63    /**
64     * 8.模糊查询总条数
65     * @return
66     */
67    public Integer totalCountLike(String pramname);
68    
69 
70 
71 }
SportsmanDao.java

9、在dao.impl包下创建HotalInfoDaoImpl.java

技术分享
 1 package dao.impl;
 2 
 3 import java.util.List;
 4 
 5 import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
 6 
 7 import dao.HotalInfoDao;
 8 import entity.HotalInfo;
 9 
10 public class HotalInfoDaoImpl extends HibernateDaoSupport implements HotalInfoDao {
11     
12     /**
13      * 查询所有区域信息
14      */
15     public List<HotalInfo> query() {
16         List<HotalInfo> list=(List<HotalInfo>)getHibernateTemplate().find("from HotalInfo");
17         return list;
18     }
19 
20     /**
21      * 根据id查询查询某个区域信息
22      */
23     public HotalInfo queryById(Integer id) {
24         HotalInfo HotalInfo=getHibernateTemplate().get(HotalInfo.class, id);
25         return HotalInfo;
26     }
27    
28     
29     
30 }
HotalInfoDaoImpl.java

10、在dao.impl包下创建SportsmanDaoImpl.java

技术分享
  1 package dao.impl;
  2 
  3 import java.util.List;
  4 
  5 import org.hibernate.Query;
  6 import org.hibernate.Session;
  7 import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
  8 
  9 import dao.SportsmanDao;
 10 import entity.Sportsman;
 11 public class SportsmanDaoImpl extends HibernateDaoSupport implements SportsmanDao {
 12    
 13     /**
 14      * 1.删除
 15      */
 16     public int delete(Sportsman obj) {
 17         getHibernateTemplate().delete(obj);
 18         return 1;
 19     }
 20     /**
 21      * 2.插入
 22      */
 23     public int insert(Sportsman obj) {
 24         getHibernateTemplate().save(obj);
 25         return 1;
 26     }
 27 
 28     /**
 29      * 3.根据id查询
 30      */
 31     public Sportsman queryById(Integer id) {
 32         Sportsman obj=getHibernateTemplate().get(Sportsman.class, id);
 33         return obj;
 34     }
 35     
 36     
 37     /**
 38      * 4.普通分页查询
 39      */
 40     @SuppressWarnings("unchecked")
 41     public List<Sportsman> queryPage(Integer pageSize, Integer pageNo) {
 42         //获取session
 43         Session session=getHibernateTemplate().getSessionFactory().openSession();
 44         
 45         
 46         //执行查询
 47         Query query=session.createQuery("from Sportsman");
 48         
 49         //查询起始行数据集合
 50         query.setFirstResult((pageNo-1)*pageSize);
 51         
 52         //查询最大条数
 53         query.setMaxResults(pageSize);
 54         
 55         //分页查询返回的集合
 56         List<Sportsman> list=(List<Sportsman>)query.list();
 57         
 58         //关闭session
 59         session.close();
 60         
 61         //返回集合
 62         return list;
 63     }
 64      
 65     
 66     /**
 67      * 重点看
 68      * 5.模糊分页查询
 69      * 查询某个区域下的所有监测数据
 70      *  一对多
 71      *  返回区域
 72      */
 73     @SuppressWarnings("unchecked")
 74     public List<Sportsman> queryPageLike(Integer pageSize,Integer pageNo, String likeparam) {
 75         //获取session
 76         Session session=getHibernateTemplate().getSessionFactory().openSession();
 77 
 78             //将String的区域id转换为integer类型的id
 79             Integer id=Integer.parseInt(likeparam);
 80             
 81          String hql="from Sportsman a where a.hotalinfo.hotalid=:id";
 82          
 83         //执行查询
 84         Query query=session.createQuery(hql);
 85         
 86         //为命名参数赋值
 87         query.setParameter("id", id);
 88     
 89         
 90         //查询起始行数据集合
 91         query.setFirstResult((pageNo-1)*pageSize);
 92         
 93         //查询最大条数
 94         query.setMaxResults(pageSize);
 95         
 96         //查询集合
 97         List<Sportsman> list=(List<Sportsman>)query.list();
 98         
 99         //关闭session
100         session.close();
101         
102         
103         
104         //返回集合
105         return list;
106     }
107 
108     
109     /**
110      * 6.求出总记录条数
111      */
112     public Integer totalCount() {
113         //获取session
114         Session session=getHibernateTemplate().getSessionFactory().openSession();
115         
116         String hql="select count(*) from Sportsman";
117         
118         Query query=session.createQuery(hql);
119         String count=query.uniqueResult().toString();
120         Integer totalCount=Integer.parseInt(count);
121         return totalCount;
122     }
123 
124     /**
125      * 7.求模糊总记录条数
126      */
127     public Integer totalCountLike(String pramname) {
128         //获取session
129         Session session=getHibernateTemplate().getSessionFactory().openSession();
130         
131          String hql="select count(*) from Sportsman a where a.hotalinfo.hotalid=:id";
132         
133         //执行查询
134         Query query=session.createQuery(hql);
135         
136         Integer id=Integer.parseInt(pramname);
137         //为命名参数赋值
138         query.setParameter("id", id);
139     
140         /**
141          * 查询唯一结果
142          */
143         String count=query.uniqueResult().toString();
144         
145         Integer totalCount=Integer.parseInt(count);
146     
147         return totalCount;
148     }
149 
150     /**
151      * 8.修改
152      */
153     public int update(Sportsman obj) {
154         getHibernateTemplate().update(obj);
155         return 1;
156     }
157     
158     
159     
160 }
SportsmanDaoImpl.java

11、在service包下创建HotalInfoService.java

技术分享
 1 package service;
 2 
 3 import java.util.List;
 4 
 5 import entity.HotalInfo;
 6 
 7 public interface HotalInfoService {
 8     /**
 9      * 1.查询所有
10      * @return
11      */
12    public List<HotalInfo> query();
13    
14 
15    
16    /**
17     * 2.根据id进行查询
18     * @param id
19     * @return
20     */
21    public HotalInfo queryById(Integer id);
22 }
HotalInfoService.java

12、在service包下创建SportsmanService.java

技术分享
 1 package service;
 2 
 3 import java.util.List;
 4 
 5 import entity.Sportsman;
 6 
 7 public interface SportsmanService {
 8 
 9        /**
10          * 2.分页查询所有
11          * @return
12          */
13       public List<Sportsman> queryPage(Integer pageSize,Integer pageNo);
14        /**
15         * 3.插入一个对象
16         * @param sandard
17         * @return
18         */
19        public int insert(Sportsman obj);
20        
21        /**
22         * 4.根据id删除
23         * @param sandard
24         * @return
25         */
26        public int delete(Sportsman obj);
27        
28        /**
29         * 4.修改某个对象
30         * @param sandard
31         * @return
32         */
33        public int update(Sportsman obj);
34        
35        /**
36         * 5.根据id进行查询
37         * @param id
38         * @return
39         */
40        public Sportsman queryById(Integer id);
41        /**
42         * 6.求出总条数
43         * @return
44         */
45        public Integer totalCount();
46        
47        
48        /**
49         * 7.根据模糊分页查询
50         * 一对多
51         * @param stdnum
52         * @param zhname
53         * @return 
54         */
55        public List<Sportsman> queryPageLike(Integer pageSize,Integer pageNo,String likeparam);
56        
57        /**
58         * 8.模糊查询总条数
59         * @return
60         */
61        public Integer totalCountLike(String pramname);
62        
63 }
SportsmanService.java

13、在service.impl包下创建HotalInfoServiceImpl.java

技术分享
 1 package service.impl;
 2 
 3 import java.util.List;
 4 
 5 import service.HotalInfoService;
 6 import dao.HotalInfoDao;
 7 import entity.HotalInfo;
 8 
 9 public class HotalInfoServiceImpl implements HotalInfoService {
10     private HotalInfoDao disDao;
11     public HotalInfoDao getDisDao() {
12         return disDao;
13     }
14     public void setDisDao(HotalInfoDao disDao) {
15         this.disDao = disDao;
16     }
17 
18     /**
19      * 查询所有区域
20      */
21     public List<HotalInfo> query() {
22         return disDao.query();
23     }
24 
25     /**
26      * 根据id查询某区域
27      */
28     public HotalInfo queryById(Integer id) {
29         return disDao.queryById(id);
30     }
31     
32 }
HotalInfoServiceImpl.java

14、在service.impl包下创建SportsmanServiceImpl.java

技术分享
 1 package service.impl;
 2 
 3 import java.util.List;
 4 
 5 import service.SportsmanService;
 6 import dao.SportsmanDao;
 7 import entity.Sportsman;
 8 
 9 public class SportsmanServiceImpl implements SportsmanService {
10     /**
11      * 实例化空气质量数据访问层接口
12      * 必须要和Sping里的bean的id对应
13      */
14     private SportsmanDao airDao;
15     public SportsmanDao getAirDao() {
16         return airDao;
17     }
18     public void setAirDao(SportsmanDao airDao) {
19         this.airDao = airDao;
20     }
21     
22     /**
23      * 删除
24      */
25     public int delete(Sportsman obj) {
26         return airDao.delete(obj);
27     }
28 
29     /**
30      * 插入
31      */
32     public int insert(Sportsman obj) {
33         
34         return airDao.insert(obj);
35     }
36 
37     /**
38      * 根据id查询单条
39      */
40     public Sportsman queryById(Integer id) {
41         return airDao.queryById(id);
42     }
43  
44     /**
45      * 普通分页查询
46      */
47     public List<Sportsman> queryPage(Integer pageSize, Integer pageNo) {
48         return airDao.queryPage(pageSize, pageNo);
49     }
50 
51     /**条件分页查询
52      * 
53      */
54     public List<Sportsman> queryPageLike(Integer pageSize,Integer pageNo, String likeparam) {
55         return airDao.queryPageLike(pageSize, pageNo, likeparam);
56     }
57 
58     /**
59      * 普通总条数
60      */
61     public Integer totalCount() {
62         return airDao.totalCount();
63     }
64 
65     /**
66      * 条件总条数
67      */
68     public Integer totalCountLike(String pramname) {
69         return airDao.totalCountLike(pramname);
70     }
71 
72     /**
73      * 修改某条数据
74      */
75     public int update(Sportsman obj) {
76         return airDao.update(obj);
77     }
78     
79 }
SportsmanServiceImpl.java

15、在action包下创建SportsmanAction.java

技术分享
  1 package action;
  2 
  3 import java.io.IOException;
  4 import java.text.ParseException;
  5 import java.text.SimpleDateFormat;
  6 import java.util.Date;
  7 import java.util.List;
  8 
  9 import javax.servlet.http.HttpServletRequest;
 10 import javax.servlet.http.HttpSession;
 11 
 12 import org.apache.struts2.ServletActionContext;
 13 
 14 import service.HotalInfoService;
 15 import service.SportsmanService;
 16 
 17 import com.opensymphony.xwork2.ActionSupport;
 18 
 19 import entity.HotalInfo;
 20 import entity.Sportsman;
 21 
 22 public class SportsmanAction extends ActionSupport{
 23     
 24     
 25     /**
 26      * 在业务逻辑层实例化服务层接口对象,
 27      * 改对象名要和sping注入的bean的id一致
 28      */
 29     private HotalInfoService disService;
 30     public HotalInfoService getDisService() {
 31         return disService;
 32     }
 33     public void setDisService(HotalInfoService disService) {
 34         this.disService = disService;
 35     }
 36 
 37     private SportsmanService airService;
 38     public SportsmanService getAirService() {
 39         return airService;
 40     }
 41     public void setAirService(SportsmanService airService) {
 42         this.airService = airService;
 43     }
 44 
 45     /**
 46      * 区域对象
 47      * 
 48      * 用于接收参数
 49      * 比如update.jsp和add.jsp页面name属性的前缀就是该对象
 50      */
 51     private HotalInfo dis;
 52     public HotalInfo getDis() {
 53         return dis;
 54     }
 55     public void setDis(HotalInfo dis) {
 56         this.dis = dis;
 57     }
 58 
 59     /**
 60      * 空气质量对象
 61      */
 62     private Sportsman air;
 63     public Sportsman getAir() {
 64         return air;
 65     }
 66     public void setAir(Sportsman air) {
 67         this.air = air;
 68     }
 69     
 70     /**
 71      * 分页查询
 72      * 在地址栏直接输入:http://localhost:8080/Exam_Standard/page?pageNo=1
 73      * 就是分页查询后显示的首页,该地址表示启动项是action触发而非按钮触发
 74      * @return
 75      */
 76     public String queryPage(){  
 77         //获取request对象
 78         HttpServletRequest request=ServletActionContext.getRequest();
 79         
 80         //获取session对象
 81         HttpSession session=request.getSession();
 82         
 83         //获取地址栏输入的pageNo参数
 84         String no=request.getParameter("pageNo");
 85         
 86         //页面大小
 87         Integer pageSize=2;
 88         Integer pageNo=0;
 89         if(no!=null){
 90             pageNo=Integer.parseInt(no);
 91         }else{
 92             pageNo=1;
 93         }
 94         
 95         /*
 96          * 查询所有区域信息
 97          */
 98         List<HotalInfo> dislist=disService.query();
 99         /*
100          * 将区域信息放入request作用域
101          * 要在填充在区域下拉列表中
102          * 要将区域信息放入session,因为后期还要用
103          */
104         session.setAttribute("dislist", dislist);
105         
106         
107         /*获取分页集合数据(查询空气质量)
108          * 由于已经建立了关联关系,所以当查询空气质量的时候就会把该表对应的区域外键的所有字段查询出来
109          */
110         List<Sportsman> list=airService.queryPage(pageSize, pageNo);
111         
112         
113         //获取总条数
114         Integer totalCount=airService.totalCount();
115         
116         //计算总页数
117         Integer totalPage=totalCount%pageSize==0?totalCount/pageSize:totalCount/pageSize+1;
118         
119         //将空气质量集合放入request请求中
120         request.setAttribute("list", list);
121         
122         //将总页数发送至页面
123         request.setAttribute("totalPage", totalPage);
124         
125         //将当前页发送至页面
126         request.setAttribute("pageNo", pageNo);
127         
128         //发送一个模糊分页查询的标识符到页面,因为前台分页可能是普通分页,也可能是模糊查询分页
129         request.setAttribute("islikePage", "no");
130         
131         return "success";
132     }
133 
134     
135     /**
136      * 模糊条件分页查询
137      * @return
138      */
139     public String likePage(){  
140         //获取request对象
141         HttpServletRequest request=ServletActionContext.getRequest();
142         
143         //获取地址栏输入的pageNo参数
144         String no=request.getParameter("pageNo");
145         
146         //获取输入框输入的条件
147         String likeparam=request.getParameter("paramName");
148         System.out.println("likeparam:"+likeparam);
149         //页面大小
150         Integer pageSize=2;
151         Integer pageNo=0;
152         if(no!=null){
153             pageNo=Integer.parseInt(no);
154         }else{
155             pageNo=1;
156         }
157         
158         //获取条件区域id模糊分页集合数据
159         List<Sportsman> list=airService.queryPageLike(pageSize, pageNo, likeparam);
160         
161         //获取总条数,是对集合数据分页
162         Integer totalCount=airService.totalCountLike(likeparam);
163         
164         System.out.println("totalCount条件分页总条数:"+totalCount);
165         
166         //计算总页数
167         Integer totalPage=totalCount%pageSize==0?totalCount/pageSize:totalCount/pageSize+1;
168         
169         //将集合放入request请求中
170         request.setAttribute("list", list);
171         
172         //将总页数发送至页面
173         request.setAttribute("totalPage", totalPage);
174         
175         //将当前页发送至页面
176         request.setAttribute("pageNo", pageNo);
177         
178         //将获取的文本框的值再传回前台显示
179         request.setAttribute("likeparam", likeparam);
180         
181         //发送一个模糊分页查询的标识符到页面,因为前台分页可能是普通分页,也可能是模糊查询分页
182         request.setAttribute("islikePage", "yes");
183         
184         return "success";
185     }
186 
187     
188     /**
189      * 查询单条
190      * @return
191      */
192     public String findById(){
193         //获取request对象
194         HttpServletRequest request=ServletActionContext.getRequest();
195         
196         //获取地址栏输入的pageNo参数
197         String sid=request.getParameter("id");
198         Integer id=0;
199         if(sid!=null){
200               id=Integer.parseInt(sid);
201              //根据id查询单条数据
202                  Sportsman airqua=airService.queryById(id);
203               request.setAttribute("airqua", airqua);
204         }else{
205             System.out.println("删除时id没有获取到");
206         }
207         
208         return "success";
209         
210     }
211 
212     
213     /**
214      * 修改单条
215      * @return
216      * @throws IOException 
217      */
218      public String updateOne(){
219          
220         Integer result=airService.update(air);
221         
222         return "success";
223     }
224      
225     
226     /**
227      * 删除
228      * 先根据id查询出对象
229      * 删除某个对象
230      * @return
231      */
232     public String delete(){
233         
234         //获取request对象
235         HttpServletRequest request=ServletActionContext.getRequest();
236         
237         //获取地址栏输入的pageNo参数
238         String sid=request.getParameter("id");
239         Integer id=0;
240         if(sid!=null){
241               id=Integer.parseInt(sid);
242              //根据id查询单条数据
243             Sportsman  air=airService.queryById(id);
244               //删除某个对象
245             Integer result=airService.delete(air);
246         }else{
247             System.out.println("删除时id没有获取到");
248         }
249         
250         return "success";
251         
252     }
253 
254     
255     /**
256      * 插入单条
257      * @return
258      * @throws ParseException 
259      * @throws IOException 
260      */
261     public String insertOne() throws ParseException{
262     //    HttpServletRequest request=ServletActionContext.getRequest();
263         
264         
265 //        Date intaketime=new SimpleDateFormat("yyyy-MM-dd").parse(request.getParameter("intaketime"));
266 //        Date leavetime=new SimpleDateFormat("yyyy-MM-dd").parse(request.getParameter("leavetime"));
267 //        air.setIntaketime(intaketime);
268 //        air.setLeavetime(leavetime);
269         
270         //查询某个区域信息
271         HotalInfo dis=disService.queryById(air.getHotalinfo().getHotalid());
272         
273         
274         //为监测信息的区域对象赋值
275         air.setHotalinfo(dis);
276         
277         System.out.println("getSportname:"+air.getSportname());
278         System.out.println("getNationality:"+air.getNationality());
279         System.out.println("getIntaketime:"+air.getIntaketime());
280         System.out.println("getLeavetime:"+air.getLeavetime());
281         System.out.println("getHotalid:"+air.getHotalinfo().getHotalid());
282         System.out.println("getHotalname:"+air.getHotalinfo().getHotalname());
283         System.out.println("getHotaladdress:"+air.getHotalinfo().getHotaladdress());
284         
285         Integer result=airService.insert(air);
286         
287         return "success";
288         
289     }
290     
291     
292 }
SportsmanAction.java

16、在WebRoot下WEB-INF下创建applicationContext.xml

技术分享
  1 <?xml version="1.0" encoding="UTF-8"?>
  2 <beans xmlns="http://www.springframework.org/schema/beans"
  3        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4        xsi:schemaLocation="
  5 http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
  6 
  7 <!-- bean definitions here -->
  8 <!-- 1.定义csp0数据源 -->
  9 <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
 10    <property name="driverClass">
 11      <value>oracle.jdbc.driver.OracleDriver</value>
 12    </property>
 13    <property name="jdbcUrl">
 14      <value>jdbc:oracle:thin:@127.0.0.1:1521:orcl</value>
 15    </property>
 16    <property name="user">
 17      <value>ssh</value>
 18    </property>
 19    <property name="password">
 20      <value>sys</value>
 21    </property>
 22    <property name="minPoolSize">
 23      <value>1</value>
 24    </property>
 25    <property name="maxPoolSize">
 26      <value>100</value>
 27    </property>
 28    <property name="initialPoolSize">
 29      <value>1</value>
 30    </property>
 31    <property name="maxIdleTime">
 32      <value>30</value>
 33    </property>
 34 </bean>
 35 
 36 <!-- 
 37 2.创建session工厂
 38 下面class的值是可以点出来的
 39  -->
 40 <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
 41 
 42    <!-- 
 43       2.1 指定数据源,注意,大小写一定要准确
 44       ref是上面数据员配置的bean的id值,一定要保持一致,name最好和ref的值保持一致
 45     -->
 46    <property name="dataSource" ref="dataSource"></property>
 47   
 48    <!-- 
 49      2.2表映射文件列表,一定要注册
 50      name属性值是可以直接点出来的
 51    -->
 52    <property name="mappingResources">
 53      <list>
 54        <value>entity/Sportsman.hbm.xml</value>
 55        <value>entity/HotalInfo.hbm.xml</value>
 56      </list>
 57    </property>
 58   
 59     <!-- 2.3 hibernate配置 ,下面的name是可以直接点出来的-->
 60    <property name="hibernateProperties">
 61        <props>
 62           <prop key="hibernate.show_sql">true</prop>
 63           <prop key="hibernate.format_sql">true</prop>
 64          
 65           <!-- 下面的值是可以在类里面点出来的 -->    
 66           <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
 67        </props>
 68    </property>
 69 </bean>
 70 
 71 
 72 
 73 <!-- 3.事务管理session工厂 -->
 74 <!-- 下面的class是可以直接点出来的
 75 <bean id="TransactionManager" class="org.springframework.orm.hibernate3.HibernateTemplate">
 76    下面的ref的值是上面session工厂的bean的id,一定要保持一致,name最好和ref的值保持一致 
 77    <property name="sessionFactory" ref="sessionFactory"></property>
 78 </bean>
 79  -->
 80 <!-- 4.Spring的注入 
 81     4.1 把dao引入session 
 82     id的areainfoDao的名称和service.impl.AreainfoServiceImpl中创建的实例对象名称保持一致
 83   -->
 84 <bean id="airDao" class="dao.impl.SportsmanDaoImpl">
 85    <property name="sessionFactory" ref="sessionFactory"></property>
 86 </bean>
 87 <bean id="disDao" class="dao.impl.HotalInfoDaoImpl">
 88     <property name="sessionFactory" ref="sessionFactory"></property>
 89 </bean>
 90 
 91 
 92 
 93 <!-- 4.2 把service倒入dao 
 94     id的areainfoService的名称必须和 action.AreainfoAction中创建对象的实例对象名保持一致-->
 95     
 96 <bean id="airService" class="service.impl.SportsmanServiceImpl">
 97   <property name="airDao" ref="airDao"></property>
 98 </bean>
 99 <bean id="disService" class="service.impl.HotalInfoServiceImpl">
100     <property name="disDao" ref="disDao"></property>
101 </bean>
102 
103 <!-- 4.3 action注入service 必须配置scope="prototype"-->
104 <bean id="airAction" class="action.SportsmanAction" scope="prototype">
105   <property name="airService" ref="airService"></property>
106   <property name="disService" ref="disService"></property>
107 </bean>
108 
109 
110 </beans>
applicationContext.xml

17、在src下创建struts.xml

技术分享
 1 <?xml version="1.0" encoding="UTF-8" ?>
 2 <!DOCTYPE struts PUBLIC
 3     "-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"
 4     "http://struts.apache.org/dtds/struts-2.1.7.dtd">
 5 <struts>
 6     <package name="default" namespace="/" extends="struts-default">  
 7   
 8      
 9         <!-- class的值是spring注入的action的id名字 -->
10         <!-- name为action的名字,mothod为action里方法名 -->
11         
12         
13         <!-- 1.分页查询:项目启动时输入page就可以直接调至查询页面 -->
14         <action name="page" class="airAction" method="queryPage">
15            <result name="success">/index.jsp</result>
16         </action>
17           
18         <!-- 模糊条件分页查询 -->
19         <action name="likePage" class="airAction" method="likePage">
20            <result name="success">/index.jsp</result>
21         </action>
22         
23         <!-- 2.删除 -->
24         <action name="delete" class="airAction" method="delete">
25            <!-- type表示如果删除成功,则将地址重定向的某个action上,由于删除成功后,调至查询页面,所以这里将跳转到查询启动的action ,page -->
26            <result name="success" type="redirectAction">page</result>
27         </action>
28         
29         
30         <!-- 查询单条 -->
31         <action name="findById" class="airAction" method="findById">
32            <result name="success">/update.jsp</result>
33         </action>
34         
35         <!-- 修改单条 -->
36         <action name="update" class="airAction" method="updateOne">
37              <!-- type表示如果修改成功,则将地址重定向的某个action上,由于修改成功后,调至查询页面,所以这里将跳转到查询启动的action ,page -->
38            <result name="success" type="redirectAction">page</result>
39         </action>
40         
41         
42         <!-- 添加单条 -->
43         <action name="insert" class="airAction" method="insertOne">
44              <!-- type表示如果添加成功,则将地址重定向的某个action上,由于添加成功后,调至查询页面,所以这里将跳转到查询启动的action ,page -->
45            <result name="success" type="redirectAction">page</result>
46         </action>
47         
48     </package>
49 
50 
51 </struts>
struts.xml

18、在WebRoot下WEB-INF下创建web.xml

技术分享
 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
 3 
 4     <display-name>Struts Blank</display-name>
 5 <!-- 核心拦截器 -->
 6     <filter>
 7         <filter-name>struts2</filter-name>
 8         <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
 9     </filter>
10 
11     <filter-mapping>
12         <filter-name>struts2</filter-name>
13         <url-pattern>/*</url-pattern>
14     </filter-mapping>
15     <!-- 监听 -->
16 <listener>
17   <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
18 </listener>
19     <welcome-file-list>
20         <welcome-file>index.jsp</welcome-file>
21     </welcome-file-list>
22 
23 </web-app>
web.xml

19、在WebRoot下创建index.jsp

技术分享
  1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
  2 <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
  3 <%
  4     String path = request.getContextPath();
  5     String basePath = request.getScheme() + "://"
  6             + request.getServerName() + ":" + request.getServerPort()
  7             + path + "/";
  8 %>
  9 
 10 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 11 <html>
 12     <head>
 13         <base href="<%=basePath%>">
 14 
 15         <title>My JSP ‘index.jsp‘ starting page</title>
 16         <meta http-equiv="pragma" content="no-cache">
 17         <meta http-equiv="cache-control" content="no-cache">
 18         <meta http-equiv="expires" content="0">
 19         <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
 20         <meta http-equiv="description" content="This is my page">
 21         <style type="text/css"></style>
 22         <script type="text/javascript" src="js/jquery-1.8.3.js"></script>
 23         <script>
 24                 //模糊查询
 25             function funSearch(){
 26                  var numorname=$("#areaname").val();
 27                  window.location="likePage?paramName="+numorname;
 28                  
 29             }
 30     
 31     
 32     
 33     </script>
 34     </head>
 35 
 36     <body>
 37         <center>
 38             <h3>   
 39                 运动员住宿管理系统
 40             </h3>
 41             <table border="1px">
 42                 <tr>
 43                     <td colspan="8" align="right">
 44                     酒店:<select id="areaname" name="areaname">
 45                          <option value="0">不限</option>
 46                          <c:forEach var="d" items="${sessionScope.dislist}">
 47                            <c:choose>
 48                               <c:when test="${requestScope.likeparam eq d.hotalid}">
 49                                    <option value="${d.hotalid }" selected="selected">${d.hotalname}</option>
 50                               </c:when>
 51                               <c:otherwise>
 52                                    <option value="${d.hotalid }">${d.hotalname}</option>
 53                               </c:otherwise>
 54                            </c:choose>
 55                          </c:forEach>
 56                       </select>
 57                       <input type="button" value="查找" onclick="funSearch()"/>
 58                       <a href="add.jsp">添加运动员信息</a>
 59                     </td>
 60                 </tr>
 61                 <tr>
 62                     <td>
 63                         <input type="checkbox" id="all" />
 64                     </td>
 65                     <td>
 66                         序号
 67                     </td>
 68                     <td>
 69                         酒店名称
 70                     </td>
 71                     <td>
 72                         酒店地址
 73                     </td>
 74                     <td>
 75                         运动员姓名
 76                     </td>
 77                     <td>
 78                         入住时间
 79                     </td>
 80                     <td>
 81                            离店时间
 82                     </td>
 83                     <td>
 84                         操作
 85                     </td>
 86                 </tr>
 87                 <c:forEach var="i" items="${requestScope.list}" varStatus="starts">
 88 
 89                     <tr>
 90                         <td>
 91                             <input type="checkbox" name="che" />
 92                         </td>
 93                         <td><!-- starts.index+1 表示索引号 -->
 94                             ${i.sportid}
 95                         </td>
 96                         <td>
 97                             ${i.hotalinfo.hotalname}
 98                         </td>
 99                         <td>
100                             ${i.hotalinfo.hotaladdress}
101                         </td>
102                         <td>
103                             ${i.sportname}
104                         </td>
105                         <td>
106                             ${i.intaketime}
107                         </td>
108                         <td>
109                             ${i.leavetime }
110                         </td>
111                         <td>
112                           <a href=findById?id=${i.sportid}>修改</a>&nbsp;|&nbsp;<a href="delete?id=${i.sportid}">删除</a>
113                         </td>
114                     </tr>
115                 </c:forEach>
116 
117                 <tr>
118                     <td colspan="7" align="right">
119                     
120                     <!-- 普通分页查询 -->
121                     <c:if test="${islikePage eq ‘no‘}">
122                         <c:choose>
123                             <c:when test="${pageNo gt 1}">
124                                 <a href="page?pageNo=1">首页</a>
125                                 <a href="page?pageNo=${pageNo-1}">上一页</a>
126                             </c:when>
127                             <c:otherwise>
128                                 <a href="page?pageNo=1">首页</a>
129                                 <a href="javascript:alert(‘已经是第一页了!‘);">上一页</a>
130                             </c:otherwise>
131                         </c:choose>
132 
133                         <c:choose>
134                             <c:when test="${pageNo lt totalPage}">
135                                 <a href="page?pageNo=${pageNo+1}">下一页</a>
136                                 <a href="page?pageNo=${totalPage}">末页</a>
137                             </c:when>
138                             <c:otherwise>
139                                 <a href="javascript:alert(‘已经是最后一页了!‘);">下一页</a>
140                                 <a href="page?pageNo=${totalPage}">末页</a>
141                             </c:otherwise>
142                         </c:choose>
143                         第${pageNo}页/共${totalPage}页
144                     </c:if>
145                     
146                     <!-- 模糊条件分页查询 -->
147                     <c:if test="${islikePage eq ‘yes‘}">
148                         <c:choose>
149                             <c:when test="${pageNo gt 1}">
150                                 <a href="likePage?pageNo=1&paramName=${likeparam}">首页</a>
151                                 <a href="likePage?pageNo=${pageNo-1}&paramName=${likeparam}">上一页</a>
152                             </c:when>
153                             <c:otherwise>
154                                 <a href="likePage?pageNo=1&paramName=${likeparam}">首页</a>
155                                 <a href="javascript:alert(‘已经是第一页了!‘);">上一页</a>
156                             </c:otherwise>
157                         </c:choose>
158 
159                         <c:choose>
160                             <c:when test="${pageNo lt totalPage}">
161                                 <a href="likePage?pageNo=${pageNo+1}&paramName=${likeparam}">下一页</a>
162                                 <a href="likePage?pageNo=${totalPage}&paramName=${likeparam}">末页</a>
163                             </c:when>
164                             <c:otherwise>
165                                 <a href="javascript:alert(‘已经是最后一页了!‘);">下一页</a>
166                                 <a href="likePage?pageNo=${totalPage}&paramName=${likeparam}">末页</a>
167                             </c:otherwise>
168                         </c:choose>
169                         第${pageNo}页/共${totalPage}页
170                     </c:if>
171                     
172                     </td>
173                 </tr>
174 
175             </table>
176         </center>
177     </body>
178 </html>
index.jsp

20、在WebRoot下创建add.jsp

技术分享
  1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
  2 <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"  %>
  3 <%
  4     String path = request.getContextPath();
  5     String basePath = request.getScheme() + "://"
  6             + request.getServerName() + ":" + request.getServerPort()
  7             + path + "/";
  8 %>
  9 
 10 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 11 <html>
 12     <head>
 13         <base href="<%=basePath%>">
 14 
 15         <title>My JSP ‘update.jsp‘ starting page</title>
 16 
 17         <meta http-equiv="pragma" content="no-cache">
 18         <meta http-equiv="cache-control" content="no-cache">
 19         <meta http-equiv="expires" content="0">
 20         <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
 21         <meta http-equiv="description" content="This is my page">
 22         <!--
 23     <link rel="stylesheet" type="text/css" href="styles.css">
 24     -->
 25 
 26     </head>
 27 
 28     <body>
 29         <center>
 30             <h3> 
 31                 添加运动员信息 
 32             </h3>
 33 
 34             <form action="insert" method="post">
 35                 <table border="1px">
 36                     <tr>
 37                        <td>酒店:</td>
 38                         <td>
 39                             <select id="areaname" name="air.hotalinfo.hotalid">
 40                                  <option value="0">不限</option>
 41                                  <c:forEach var="d" items="${sessionScope.dislist}">
 42                                    <c:choose>
 43                                      <c:when test="${requestScope.likeparam eq d.hotalid}">
 44                                    <option value="${d.hotalid }" selected="selected">${d.hotalname}</option>
 45                               </c:when>
 46                               <c:otherwise>
 47                                    <option value="${d.hotalid }">${d.hotalname}</option>
 48                               </c:otherwise>
 49                                    </c:choose>
 50                                  </c:forEach>
 51                             </select>
 52                         </td>
 53                         
 54                     </tr>
 55                     <tr>
 56                         <td>
 57                             酒店地址:
 58                         </td>
 59                         <td>
 60                             <input type="text" name="air.hotalinfo.hotaladdress" />
 61                         </td>
 62                     </tr>
 63                     <tr>
 64                         <td>
 65                             运动员姓名:
 66                         </td>
 67                         <td>
 68                             <input type="text" name="air.sportname" />
 69                         </td>
 70                     </tr>
 71                     <tr>
 72                         <td>
 73                             国籍:
 74                         </td>
 75                         <td>
 76                             <input type="text" name="air.nationality" />
 77                         </td>
 78                     </tr>
 79                     <tr>
 80                         <td>
 81                             入住时间:
 82                         </td>
 83                         <td>
 84                             <input type="text" name="air.intaketime"/>
 85                         </td>
 86                     </tr>
 87                     <tr>
 88                         <td>
 89                              离店时间:
 90                         </td>
 91                         <td>
 92                             <input type="text" name="air.leavetime"/>
 93                         </td>
 94                     </tr>
 95                     
 96                     <tr>
 97                         <td>
 98                             <input type="submit" value="添加" />
 99                             <input type="reset" value="取消" />
100                         </td>
101                     </tr>
102                 </table>
103             </form>
104         </center>
105     </body>
106 </html>
add.jsp

20、在WebRoot下创建update.jsp

技术分享
  1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
  2 <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"  %>
  3 <%
  4     String path = request.getContextPath();
  5     String basePath = request.getScheme() + "://"
  6             + request.getServerName() + ":" + request.getServerPort()
  7             + path + "/";
  8 %>
  9 
 10 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 11 <html>
 12     <head>
 13         <base href="<%=basePath%>">
 14 
 15         <title>My JSP ‘update.jsp‘ starting page</title>
 16 
 17         <meta http-equiv="pragma" content="no-cache">
 18         <meta http-equiv="cache-control" content="no-cache">
 19         <meta http-equiv="expires" content="0">
 20         <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
 21         <meta http-equiv="description" content="This is my page">
 22         <!--
 23     <link rel="stylesheet" type="text/css" href="styles.css">
 24     -->
 25 
 26     </head>
 27 
 28     <body>
 29         <center>
 30             <h3> 
 31                 运动员信息维护页 
 32             </h3>
 33 
 34             <form action="update" method="post">
 35                 <input type="hidden" name="air.sportid" value="${airqua.sportid}">
 36                 <table border="1px">
 37                     <tr>
 38                        <td>酒店:</td>
 39                         <td>
 40                             <select id="areaname" name="air.hotalinfo.hotalid">
 41                                  <option value="0">不限</option>
 42                                  <c:forEach var="d" items="${sessionScope.dislist}">
 43                                    <c:choose>
 44                                      <c:when test="${airqua.hotalinfo.hotalid eq d.hotalid}">
 45                                    <option value="${d.hotalid }" selected="selected">${d.hotalname}</option>
 46                               </c:when>
 47                               <c:otherwise>
 48                                    <option value="${d.hotalid }">${d.hotalname}</option>
 49                               </c:otherwise>
 50                                    </c:choose>
 51                                  </c:forEach>
 52                             </select>
 53                         </td>
 54                         
 55                     </tr>
 56                 
 57                     <tr>
 58                         <td>
 59                             酒店地址:
 60                         </td>
 61                         <td>
 62                             <input type="text" name="air.hotalinfo.hotaladdress" value="${airqua.hotalinfo.hotaladdress}" />
 63                         </td>
 64                     </tr>
 65                     <tr>
 66                         <td>
 67                             运动员姓名:
 68                         </td>
 69                         <td>
 70                             <input type="text" name="air.sportname" value="${airqua.sportname}" />
 71                         </td>
 72                     </tr>
 73                     <tr>
 74                         <td>
 75                             国籍:
 76                         </td>
 77                         <td>
 78                             <input type="text" name="air.nationality" value="${airqua.nationality}"/>
 79                         </td>
 80                     </tr>
 81                     <tr>
 82                         <td>
 83                             入住时间:
 84                         </td>
 85                         <td>
 86                             <input type="text" name="air.intaketime" value="${airqua.intaketime}" />
 87                         </td>
 88                     </tr>
 89                     <tr>
 90                         <td>
 91                             离店时间:
 92                         </td>
 93                         <td>
 94                             <input type="text" name="air.leavetime" value="${airqua.leavetime}" />
 95                         </td>
 96                     </tr>
 97                     
 98                     <tr>
 99                         <td>
100                             <input type="submit" value="更新" />
101                             <input type="reset" value="取消" />
102                         </td>
103                     </tr>
104                 </table>
105             </form>
106         </center>
107     </body>
108 </html>
update.jsp

 

SSH 两个表全套增删改

标签:

原文地址:http://www.cnblogs.com/holly8/p/5547956.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!